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?
- A. 2
- B. 1
- C. 0
- 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
- Problem: Kruskal's algorithm on the edges 0-1 (3), 1-2 (1), 0-2 (2), 2-3 (5), 1-3 (4), 3-4 (2), 2-4 (6) processes the edges in increasing…
- Problem: A tree has 7 nodes labelled 1–7 with edges 1-2, 1-3, 3-4, 3-5, 5-6, 5-7. Node 1 is the root. What is the depth of the deepest…
- Problem: Strings "axbycz" and "abc" are given. Count the subsequences of "axbycz" that equal "abc" (indices must be increasing, and…
- Problem: Starting with the list [1, 2, 3, 4, 5, 6], repeatedly remove every second element (keeping the first) until one element remains…
- Problem: In the array [5, 1, 4, 2, 8, 0, 2], count the pairs (i, j) with i < j and a[i] > 2·a[j] (so a[i] is more than double a[j]).
- Problem: The string "aabcbbca" is processed by a sliding window that keeps at most one distinct letter 'a' inside (other letters are…