Data Structures & AlgorithmsHardGATE CS · ICPC regional
A directed acyclic graph has the vertices M, Q, U, V, X, Y, Z and the arcs M→Y, M→Q, M→V, U→Y, U→Z, U→V, Y→Q, Y→Z, Y→V, Q→Z, Q→X, Z→X, X→V. 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 M?
- A. 4
- B. 5
- C. 1
- D. 3
Correct answer: D. 3
Evaluate the Grundy values from the sinks backwards; the value of M is 3. Using the number of out-arcs in place of the Grundy values gives 1, and the longest path from M is 5.
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 and right side Q1, Q2, Q3, Q4, Q5, with edges P3–Q2, P2–Q4, P1–Q5, P3–Q4, P2–Q1, P3–Q5. What is…
- A flow network has source S and sink T, with directed arcs and capacities in brackets: S→A (9), D→T (3), A→D (1), A→T (4), B→D (4), B→T…
- A directed acyclic graph has the vertices D, G, K, L, Q, S, V, Y and the directed edges D→K, D→Q, D→L, D→V, Q→L, G→L, D→Y, Y→Q, K→Y, K→V…
- A tree has vertices F, G, J, K, L, M, N, U, X and weighted edges (weights in brackets): N–F (4), N–U (3), U–M (7), N–X (7), U–J (7), U–K…
- Bellman–Ford is run from source I on the directed graph whose arcs (weights in brackets) are listed in the order they are relaxed: O→I…
- A counter starts at 1. Each step, you may add 1, add 2, or double the counter. Each step must stay at or below 12. Two sequences of steps…