Data Structures & AlgorithmsVery hardCodeforces Div 2 B · GATE CS

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

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

Correct answer: C. 2

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

More Trees, Graphs, Recursion and Dynamic Programming questions

Exams that ask this topic