Data Structures & AlgorithmsVery hardICPC regional · Codeforces Div2 D
Problem: Count the walks of length 3 on the path graph P4 (vertices 1–4, edges 1-2, 2-3, 3-4) that start and end at the same vertex. Walks may revisit vertices.
- A. 0
- B. 1
- C. 2
- D. 3
Correct answer: A. 0
Odd-length closed walks in a bipartite graph are impossible, since each step switches the colour class. The count is therefore zero, and any nonzero result would indicate an error in the walk counting.
More Coding Interview Problems questions
- Problem: The array [2, 7, 4, 1, 8, 1] is examined by a sweep: for each index i, the value a[i] is compared with the minimum of the…
- Problem: Starting with the stack [1] (top is the rightmost element), the operations are: push 2, push 3, pop, push 4, push 5, pop, pop…
- Problem: A bank processes queued withdrawals of 40, 25, 60, 15, 30 from a balance of 100. Each withdrawal is processed only if the current…
- Problem: The Z-array of "aaabaab" is computed (z[0] is the full length by convention). What is the sum of z[1] through z[6]?
- Problem: The string "aaaa" has how many distinct palindromic substrings (counting each distinct string once, of any length ≥ 1)?
- Problem: In the tree with edges 1-2, 1-3, 2-4, 2-5, 3-6, 3-7, what is the number of leaves (nodes with degree 1)?