Data Structures & AlgorithmsHardGATE CS · Codeforces Div 2 B

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

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

Correct answer: C. 2

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

More Trees, Graphs, Recursion and Dynamic Programming questions

Exams that ask this topic