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?

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

More Trees, Graphs, Recursion and Dynamic Programming questions

Exams that ask this topic