Data Structures & AlgorithmsHardCodeforces Div 2 D · ICPC regional
A directed acyclic graph has the vertices A, E, F, J, L, N and the arcs F→N, F→E, F→J, F→A, L→E, N→E, E→A, J→A. 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 F?
- A. 2
- B. 4
- C. 3
- D. 1
Correct answer: A. 2
Evaluate the Grundy values from the sinks backwards; the value of F is 2. Using the number of out-arcs in place of the Grundy values gives 2, and the longest path from F 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 bipartite graph has left side P1, P2, P3, P4 and right side Q1, Q2, Q3, Q4, Q5, with edges P1–Q1, P4–Q1, P1–Q2, P1–Q5, P4–Q5, P2–Q5…
- A tree has vertices with weights in brackets: Y[6], L[12], B[1], X[10], W[6], I[3], N[4], V[14], J[7]. The edges are Y–L, Y–B, L–X, L–W…
- A directed graph has the vertices D, F, M, O, S and the arcs M→D, M→O, D→O, D→F, O→S, F→O, S→M. Count the directed Hamiltonian paths…
- On an 7×7 chessboard, rows and columns are numbered 0 to 6, and squares are written (row, column). A knight moves in the usual L-shape…
- A directed acyclic graph has the vertices A, F, J, K, P, R, S and the edges P→A, P→F, A→F, J→F, J→S, J→R, S→F. A topological order lists…
- A counter starts at 1. Each step, you may add 1, add 2, or double the counter. Each step must stay at or below 23. Two sequences of steps…