Data Structures & AlgorithmsVery hardICPC regional · Codeforces Div2 D

Problem: Vertices 0–5 form a directed graph with arcs 0→1, 1→2, 2→3, 3→1, 3→4, 4→5, 5→4. Let S be the set of vertices reachable from 0. How many vertices are in S and are NOT on any directed cycle?

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

Correct answer: B. 1

First find the reachable set from 0, then test each vertex for lying on a cycle by checking whether it can reach itself. The vertices 1 through 3 and 4, 5 are on cycles, leaving only 0 in the reachable set outside them.

More Coding Interview Problems questions

Exams that ask this topic