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?
- A. 5
- B. 6
- C. 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
- Problem: In a directed graph with arcs 0→1, 1→2, 2→0, 2→3, 3→4, 4→3, the strongly connected components are formed. What is the size of the…
- Problem: The tree with edges 1-2, 1-3, 2-4, 2-5, 3-6, 6-7, 6-8 is rooted at node 1. How many nodes have exactly two neighbours (degree 2)…
- Problem: How many occurrences of the substring "ana" are in "bananarama" (overlapping occurrences count)?
- Problem: How many distinct strings formed by permuting the letters of "aab" are palindromes?
- Problem: Find the length of the shortest substring of "bbaac" that contains both letters 'a' and 'b' at least once.
- Problem: What is the length of the longest substring of "aabbcbbcc" in which every character occurs at least twice?