Data Structures & AlgorithmsHardCodeforces Div 2 B · GATE CS

Directed graph on vertices 0 to 8; every edge costs 0 or 1: 6→8 (1), 4→8 (1), 6→1 (0), 6→5 (0), 0→3 (1), 5→1 (0), 1→4 (1), 2→7 (1), 8→2 (0), 6→3 (1), 5→2 (0), 4→2 (0), 3→2 (1), 7→2 (1), 1→7 (0), 1→0 (0), 8→7 (0), 8→4 (1), 3→7 (0), 0→7 (1), 4→0 (1), 7→1 (0), 5→7 (0). What is the minimum total cost of a path from 0 to 8, where a path's cost is the sum of its edge costs?

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

Correct answer: A. 3

A 0-1 BFS (or Dijkstra) gives cost 3. Counting hops gives 4, and forbidding the 0-cost edges gives unreachable; both are traps.

More Trees, Graphs, Recursion and Dynamic Programming questions

Exams that ask this topic