Graph Theory37 sections · 1633 units
Open in Course

CSES 1667 Message Route - Problem Statement

CSES Problem Set

Problem: Message Route (CSES). There are NN computers numbered 11 to NN and MM bidirectional connections. Find the shortest path from computer 11 to computer NN. If a path exists, print its length and the nodes along the path. If no path exists, print IMPOSSIBLE.

This is a textbook BFS problem. Run BFS from node 11. If you reach node NN, reconstruct the path using a parent array. If BFS finishes without reaching NN, the answer is IMPOSSIBLE. The challenge here is path reconstruction, not finding the distance.