Data Structures & AlgorithmsVery hardGATE CS · Codeforces Div 2 B

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

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

Correct answer: D. 2

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

More Trees, Graphs, Recursion and Dynamic Programming questions

Exams that ask this topic