Data Structures & AlgorithmsVery hardCodeforces Div 2 C · GATE CS

A directed acyclic graph has the vertices A, B, D, G, H, I, L and the arcs H→G, H→D, H→B, H→I, H→L, A→G, A→D, A→B, A→I, A→L, G→D, G→B, G→I, D→B, D→L, I→L. 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 H?

  1. A. 4
  2. B. 2
  3. C. 5
  4. D. 3

Correct answer: D. 3

Evaluate the Grundy values from the sinks backwards; the value of H is 3. Using the number of out-arcs in place of the Grundy values gives 4, and the longest path from H is 3.

More Trees, Graphs, Recursion and Dynamic Programming questions

Exams that ask this topic