Data Structures & AlgorithmsVery hardCodeforces Div 2 D · ICPC regional

A directed acyclic graph has the vertices F, H, M, P, U, W and the arcs H→M, H→W, U→F, F→M, F→P, F→W, M→P, M→W. 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. 3
  2. B. 4
  3. C. 2
  4. D. 1

Correct answer: C. 2

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

More Trees, Graphs, Recursion and Dynamic Programming questions

Exams that ask this topic