Data Structures & AlgorithmsVery hardGATE CS · Codeforces Div 2 B

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

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

Correct answer: B. 2

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

More Trees, Graphs, Recursion and Dynamic Programming questions

Exams that ask this topic