Data Structures & AlgorithmsHardGATE CS · ICPC regional

A directed acyclic graph has the vertices M, Q, U, V, X, Y, Z and the arcs M→Y, M→Q, M→V, U→Y, U→Z, U→V, Y→Q, Y→Z, Y→V, Q→Z, Q→X, Z→X, X→V. 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 M?

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

Correct answer: D. 3

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

More Trees, Graphs, Recursion and Dynamic Programming questions

Exams that ask this topic