Solution: AT_agc017_d [AGC017D] Game on Tree
你可以浏览这个题解的中文版本。
The operation in the problem can be interpreted as selecting a subtree (not the whole tree) to delete it. Thus we can translate it into a DAG game, let
It's reasonable to guess that
-
-
- Delete the subtree rooted at $y$, the SG Number is $0$. - Delete another subtree, obviously it is within the subtree rooted at $y$. Using mathematical induction, $0, 1, \dots, \operatorname{SG}(y) - 1$ will appear in the SG Numbers of the remaining part of the subtree. Thus, $\operatorname{SG}(x)=\operatorname{mex}(1, 2, \dots, \operatorname{SG}(y))=\operatorname{SG}(y)+1$. -
By a simple DFS, we can get the SG Number of the whole tree.