Data Structures & AlgorithmsVery hardGATE CS · Codeforces Div 2 B
A directed acyclic graph has the vertices C, D, H, I, U, X and the arcs U→I, U→H, U→C, D→I, D→C, X→I, X→C, H→C. 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 U?
- A. 4
- B. 3
- C. 1
- D. 2
Correct answer: D. 2
Evaluate the Grundy values from the sinks backwards; the value of U is 2. Using the number of out-arcs in place of the Grundy values gives 2, and the longest path from U 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
- A grid has 6 rows and 8 columns (rows listed top to bottom; '.' is an open cell, '#' a wall): ..#..... .#.....# ...##... ....###. #.###…
- Two unmarked jugs hold 5 litres and 9 litres. Allowed operations: fill a jug completely, empty a jug completely, or pour one jug into the…
- A directed graph with no directed cycles has arcs u→v (weight) : X→E (-1), X→A (-3), X→J (8), E→G (-1), A→G (7), A→J (0), G→J (-3)…
- A directed acyclic graph has the vertices F, N, R, S, T, U, V, X and the directed edges R→V, U→S, S→X, F→X, N→V, R→S, U→F, F→N, R→F, R→T…
- An undirected graph has the vertices B, E, G, I, J, K, O, P and the edges I–J, I–O, J–E, J–G, J–P, E–K, E–B, G–P, G–B, G–O, K–P, K–B. What…
- An undirected connected graph on the vertices E, I, L, Y, Z has the edges Y–I, Y–Z, E–Y, L–Z, E–Z, E–I. How many spanning trees does it…