Graph Theory37 sections · 1633 units
Open in Course

Problem - Message Route

(CSES shortest path)

You have N computers (11 to N) and M connections. Find the shortest path from computer 11 to computer N, or report if impossible.

Print the number of computers in the path and the path itself.

This is a standard shortest path problem. Think about which technique applies here. The graph is unweighted (all connections cost 11), so you should consider which traversal finds shortest paths in unweighted graphs. You also need to reconstruct the actual path, not just compute the distance.