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?

  1. A. 2
  2. B. 4
  3. C. 3
  4. 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.

More Trees, Graphs, Recursion and Dynamic Programming questions

Exams that ask this topic