Data Structures & AlgorithmsVery hardCodeforces Div 2 C · GATE CS
A directed acyclic graph has the vertices B, I, M, Q, R and the arcs B→Q, B→R, I→Q, I→R, I→M, Q→M. 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 B?
- A. 1
- B. 4
- C. 2
- D. 3
Correct answer: C. 2
Evaluate the Grundy values from the sinks backwards; the value of B is 2. Using the number of out-arcs in place of the Grundy values gives 2, and the longest path from B 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
- Starting from the integer 15, one operation either adds 1, subtracts 1, or doubles the current value. Values may be any non-negative…
- A tree has vertices with weights in brackets: A[5], Z[10], I[13], N[7], L[8], M[15], D[8], R[12], C[9]. The edges are A–Z, Z–I, I–N, A–L…
- An undirected graph has the vertices B, I, L, N, Q, Y, Z and the edges N–L, N–Y, N–Q, N–I, N–Z, L–Y, L–Q, B–I, B–Z. What is its chromatic…
- An undirected graph has the vertices A, C, J, Q, S, Z and the edges S–C, S–J, S–A, Q–Z, C–J, A–Z. What is the size of a maximum matching…
- Floyd–Warshall runs on vertices 1 to 4 with these arcs u→v (weight): 1→2 (5), 1→4 (2), 2→1 (2), 2→3 (3), 2→4 (6), 3→1 (1), 3→4 (10), 4→2…
- A connected undirected graph has the vertices A, I, P, T, V, Y and the edges P–V, P–T, P–A, V–I, V–Y, I–A. Parallel edges are allowed when…