Editorial for Bubble Cup V9 C Paint it really, really black
Submitting an official solution before solving the problem yourself is a bannable offence.
Root the tree at node
Now it is easy to see that all that we need to do is to make DFS-like tour of the tree and upon returning from a node to a corresponding parent we check the color of the child node. If it is black, continue normally, otherwise visit it again and again return to the parent and then continue normally. The only exception is the root node as it has no parent. After finishing the tour and ending up in node
It is recommended to do the implementation with a stack. Complexity is
Comments