Data Structures & AlgorithmsHardGATE CS · Codeforces Div 2 B

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

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

Correct answer: B. 3

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

More Trees, Graphs, Recursion and Dynamic Programming questions

Exams that ask this topic