Since July, the holiday spirit has been in the air, and as the Grinch you are, you've already set up your Christmas tree. Your Christmas tree can be represented as a tree (in programming terms) with $$$N$$$ nodes and $$$N-1$$$ edges, where there is a unique path between any pair of nodes in the tree.
We define the distance between two nodes in the tree as the number of edges in the unique path between them. Let's call the distance between $$$u$$$ and $$$v$$$ as $$$d(u,v)$$$.
While waiting for midnight on December 25th (only six months to go), you decide to play a game with your friend on the Christmas tree.
The game starts with a token on node $$$u$$$ of the tree. Players alternate turns, with you playing first, then your friend, and so on. On each turn, if the token is on node $$$v$$$ of the tree, the player whose turn it is must move the token to any node $$$w$$$ such that $$$d(v, w) \gt M$$$, where $$$M$$$ is the maximum distance any player has previously moved the token. The player who is unable to make a move loses the game.
For each node $$$u$$$ determine if, starting with the token on node $$$u$$$, you will win the or not, it's known that the players always plays optimally.
The first line of input consists of an integer $$$1 \leq N \leq 10^6$$$ representing the number of nodes in the tree. The next $$$N-1$$$ lines each contain two integers $$$u$$$ and $$$v$$$, representing the edges of the tree.
Print a single line containing a string of $$$0$$$s and $$$1$$$s, where $$$s_i = 1$$$ if and only if starting with the token on node $$$i$$$, you will win the game.
41 21 31 4
0111