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?
- A. 2
- B. 1
- C. 0
- 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
- Problem: An undirected graph on 6 vertices has edges 0-1, 1-2, 2-3, 3-0, 3-4, 4-5. Find the number of vertices whose removal leaves a…
- Problem: The rooted tree (root 0) has children 0: [1, 2], 1: [3, 4], 2: [5], 4: [6, 7], 5: [8]. Nodes are numbered in DFS pre-order with…
- Problem: A binary tree is given by a parent array where node i has parent p[i] (p[0] = −1 is the root): p = [−1, 0, 0, 1, 1, 2, 2, 5]. How…
- Problem: What is the minimum number of swaps of two neighbouring characters needed to turn "abcdef" into "fedcba"?
- Problem: Find the number of distinct strings obtained by reading the grid of letters ab cd moving right or down from the top-left, where…
- Problem: The string "ababa" has how many distinct substrings of length 2 and 3 combined?