Data Structures & AlgorithmsVery hardICPC regional · Codeforces Div2 D

Problem: A directed graph on vertices 0–4 has arcs 0→1, 1→2, 2→0, 2→3, 3→4. How many distinct simple directed cycles does it contain?

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

Correct answer: B. 1

Enumerate cycles by starting from each smallest vertex, so every simple cycle is found exactly once. Counting strongly connected components instead answers a different question.

More Coding Interview Problems questions

Exams that ask this topic