Tahsin and Tree

Limits: 1s, 256 MB

Tahsin loves graph theory very much. He is specialy fond of trees. For his upcoming birthday his friends decided to gift him a tree, lets call it birthday tree. Birthday tree consists of n node numbered 1 to n, having a light in every node. Initialy some of the light is turned on and some are turned off. Root of the tree is 1.


This is a companion discussion topic for the original entry at https://toph.co/p/tahsin-and-tree