注意到 SG\operatorname{SG}SG 值相同的树可以等价替换。 考虑长度为 nnn 的链,SG\operatorname{SG}SG 值为 nnn。 对于一个根节点挂链的情况,直接异或起来 SG\operatorname{SG}SG 值加一即可。