Data Structures & AlgorithmsVery hardGATE CS · Codeforces Div 2 B

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

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

Correct answer: A. 2

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

More Trees, Graphs, Recursion and Dynamic Programming questions

Exams that ask this topic