Data Structures & AlgorithmsVery hardCodeforces Div 2 D · ICPC regional
A directed acyclic graph has the vertices F, H, M, P, U, W and the arcs H→M, H→W, U→F, F→M, F→P, F→W, M→P, M→W. Two players alternately move a single token along an arc. A player who cannot move loses. The Grundy (nim) value of a vertex is the mex (smallest non-negative integer not present) of the Grundy values of its out-neighbours, with 0 for a sink. What is the Grundy value of H?
- A. 3
- B. 4
- C. 2
- D. 1
Correct answer: C. 2
Evaluate the Grundy values from the sinks backwards; the value of H is 2. Using the number of out-arcs in place of the Grundy values gives 1, and the longest path from H is 2.
Practise more Trees, Graphs, Recursion and Dynamic Programming questionsTrees, Graphs, Recursion and Dynamic Programming: notes and key points
More Trees, Graphs, Recursion and Dynamic Programming questions
- An undirected graph has the vertices A, D, U, W, Y and the edges U–Y, A–D, A–Y, D–Y, W–Y, U–D, A–W, A–U. How many simple cycles does it…
- Floyd–Warshall runs on vertices 1 to 5 with these arcs u→v (weight): 1→2 (6), 1→3 (5), 1→5 (6), 2→3 (5), 2→4 (11), 3→1 (11), 3→2 (3), 3→4…
- An undirected graph on 6 vertices has the edges E–Z, E–K, E–W, Z–K, Z–F, Z–H, Z–W, K–F, K–W. How many simple paths (no repeated vertex) go…
- A directed graph with no directed cycles has arcs u→v (weight) : T→C (8), T→G (-3), T→L (5), C→G (1), C→X (-1), C→L (5), G→X (-3), X→L…
- A directed acyclic graph has the vertices A, B, D, G, H, I, L and the arcs H→G, H→D, H→B, H→I, H→L, A→G, A→D, A→B, A→I, A→L, G→D, G→B…
- A grid has 4 rows and 3 columns with these values (top to bottom): 855 818 192 153 A path moves between side-adjacent cells (up, down…