Data Structures & AlgorithmsVery hardICPC regional · Codeforces Div2 D

Problem: An undirected graph has edges 0-1, 1-2, 2-3, 3-4, 4-0, 1-5, 5-6, 6-2. What is the length of the shortest cycle that passes through vertex 0?

  1. A. 5
  2. B. 6
  3. C. 4
  4. D. 7

Correct answer: A. 5

A cycle through vertex 0 uses two of its edges, so remove one edge at 0 and find the shortest return path to 0 for each choice. The four-cycle 0-1-2-3-4 is the shortest one through 0 here.

More Coding Interview Problems questions

Exams that ask this topic