Mashtali vs AtCoder solution codeforces
After many unsuccessful tries, Mashtali decided to copy modify an AtCoder problem. So here is his copied new problem:
There is a tree withvertices and some non-empty set of the vertices are pinned to the ground.
Two players play a game against each other on the tree. They alternately perform the following action:
- Remove an edge from the tree, then remove every connected component that has no pinned vertex.The player who cannot move loses(every edge has been deleted already).
You are given the tree, but not the set of the pinned vertices. Your task is to determine, for each, the winner of the game, if only the vertices are pinned and both players play optimally.
The first line of input contains an integer— the number of vertices ( ).
The-th of the following lines contains two integers ( , ) — the endpoints of the -th edge. It’s guaranteed that these edges form a tree.
Print a string of length. The -th character should be ‘1’ if the first player wins the -th scenario, and ‘2’ otherwise.
Copy Mashtali vs AtCoder solution codeforces
5 1 2 2 3 2 4 4 5
5 1 2 2 3 1 4 4 5
output Mashtali vs AtCoder solution codeforces
6 1 2 2 4 5 1 6 3 3 2
7 1 2 3 7 4 6 2 3 2 4 1 5
Note Mashtali vs AtCoder solution codeforces
Below you can see the tree in the first sample :
Ifor , the first player can cut the edge , after that only the edges and remain. After the second players move, there will be a single edge left for the first player to cut. So first player wins.