Data Structures & AlgorithmsHardCodeforces Div 2 B · GATE CS

Directed graph on vertices 0 to 8; every edge costs 0 or 1: 3→8 (1), 7→3 (1), 2→0 (1), 4→2 (0), 6→2 (0), 6→4 (1), 5→6 (1), 0→2 (1), 4→6 (1), 1→4 (1), 2→5 (0), 5→0 (0), 4→8 (1), 7→2 (0), 8→6 (1), 8→5 (0), 1→5 (1), 7→0 (1), 6→0 (0), 2→4 (0), 0→5 (1), 7→4 (1), 3→1 (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. 2
  2. B. 0
  3. C. 4
  4. D. 3

Correct answer: A. 2

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

More Trees, Graphs, Recursion and Dynamic Programming questions

Exams that ask this topic