Data Structures & AlgorithmsHardICPC regional · Product Company SDE

Problem: A directed graph on 6 vertices (0–5) has arcs 0→1, 1→2, 0→3, 3→2, 2→4. How many ordered pairs (u, v) with u ≠ v have v unreachable from u?

  1. A. 25
  2. B. 21
  3. C. 9
  4. D. 10

Correct answer: B. 21

Reachable pairs: 0→{1,2,3,4}, 1→{2,4}, 3→{2,4}, 2→{4}: 9 of the 30 ordered pairs, so 21 are unreachable. Counting only non-arcs gives 25, 9 is the reachable count, and treating arcs as undirected gives 10.

More Coding Interview Problems questions

Exams that ask this topic