Data Structures & AlgorithmsHardGATE CS · Codeforces Div 2 B

Unweighted directed graph on vertices 0 to 5 with edges: 0→1, 0→2, 2→4, 1→0, 1→3, 2→5, 3→5, 3→1, 4→1, 5→4, 0→3, 4→0, 0→4. How many shortest paths (fewest edges) lead from 0 to 5? Two paths are different if their vertex sequences differ.

  1. A. 5
  2. B. 4
  3. C. 1
  4. D. 2

Correct answer: D. 2

BFS finds distance 2 and 2 shortest paths, counted level by level. Counting every simple path (5) or ignoring directions (4) are the traps; 1 vertices sit at that distance.

More Trees, Graphs, Recursion and Dynamic Programming questions

Exams that ask this topic