Data Structures & AlgorithmsVery hardCodeforces Div 2 C · GATE CS
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, G→I, D→B, D→L, I→L. 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. 4
- B. 2
- C. 5
- D. 3
Correct answer: D. 3
Evaluate the Grundy values from the sinks backwards; the value of H is 3. Using the number of out-arcs in place of the Grundy values gives 4, and the longest path from H is 3.
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
- 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…
- A directed graph with no directed cycles has arcs u→v (weight) : U→J (2), U→K (4), J→S (0), J→K (4), S→K (-1), P→K (3). Weights may be…
- A four-wheel combination lock shows four digits 0–9 on wheels that wrap around (9 goes to 0 and 0 goes to 9). One move turns one wheel by…
- A directed graph has the vertices A, E, F, M, N, R and the arcs R→F, R→M, A→M, M→R, M→A, E→F, E→N. How many strongly connected components…
- Floyd–Warshall runs on vertices 1 to 4 with these arcs u→v (weight): 1→2 (1), 1→3 (11), 1→4 (12), 2→1 (12), 2→3 (2), 2→4 (8), 3→1 (7), 3→2…
- Two unmarked jugs hold 6 litres and 8 litres. Allowed operations: fill a jug completely, empty a jug completely, or pour one jug into the…