Data Structures & AlgorithmsVery hardGATE CS · Codeforces Div 2 B
A directed acyclic graph has the vertices C, J, P, U, X and the arcs P→C, P→X, U→C, J→C, C→X. 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 P?
- A. 2
- B. 3
- C. 4
- D. 1
Correct answer: A. 2
Evaluate the Grundy values from the sinks backwards; the value of P is 2. Using the number of out-arcs in place of the Grundy values gives 2, and the longest path from P 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 3 rows and 4 columns with these values (top to bottom): 1832 3673 2187 A path moves between side-adjacent cells (up, down, left…
- A tree on the vertices J, L, M, N, T has the arcs T→J, J→N, L→T, M→T (each undirected edge is directed as shown). You may reverse the…
- A grid has 5 rows and 8 columns (rows listed top to bottom; '.' is an open cell, '#' a wall): ..#..... ....#..# ...#...# #.#..... ......#…
- An undirected graph on 5 vertices has the edges T–X, X–L, X–B, L–B, L–N, B–N. How many simple paths (no repeated vertex) go from T to N?…
- An undirected graph has the vertices D, E, H, J, M, P and the edges P–E, P–H, P–J, E–H, E–D, M–J, M–D. In how many ways can each vertex be…
- An undirected graph has the vertices A, B, F, I, J, P and the edges I–A, I–J, I–B, A–P, A–F, J–P, J–F, P–B. In how many ways can each…