Data Structures & AlgorithmsVery hardGATE CS · Codeforces Div 2 B

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

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

Correct answer: C. 3

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

More Trees, Graphs, Recursion and Dynamic Programming questions

Exams that ask this topic