#P1498F. Christmas Game
Christmas Game
Description
Alice and Bob are going to celebrate Christmas by playing a game with a tree of presents. The tree has nodes (numbered to , with some node as its root). There are presents are hanging from the -th node.
Before beginning the game, a special integer is chosen. The game proceeds as follows:
- Alice begins the game, with moves alternating each turn;
- in any move, the current player may choose some node (for example, ) which has depth at least . Then, the player picks some positive number of presents hanging from that node, let's call it ;
- the player then places these presents on the -th ancestor (let's call it ) of the -th node (the -th ancestor of vertex is a vertex such that is a descendant of , and the difference between the depth of and the depth of is exactly ). Now, the number of presents of the -th node is decreased by , and, correspondingly, is increased by ;
- Alice and Bob both play optimally. The player unable to make a move loses the game.
For each possible root of the tree, find who among Alice or Bob wins the game.
Note: The depth of a node in a tree with root is defined as the number of edges on the simple path from node to node . The depth of root itself is zero.
The first line contains two space-separated integers and .
The next lines each contain two integers and , denoting an undirected edge between the two nodes and . These edges form a tree of nodes.
The next line contains space-separated integers denoting the array .
Output integers, where the -th integer is if Alice wins the game when the tree is rooted at node , or otherwise.
Input
The first line contains two space-separated integers and .
The next lines each contain two integers and , denoting an undirected edge between the two nodes and . These edges form a tree of nodes.
The next line contains space-separated integers denoting the array .
Output
Output integers, where the -th integer is if Alice wins the game when the tree is rooted at node , or otherwise.
Note
Let us calculate the answer for sample input with root node as 1 and as 2.
Root node 1
Alice always wins in this case. One possible gameplay between Alice and Bob is:
- Alice moves one present from node 4 to node 3.
- Bob moves four presents from node 5 to node 2.
- Alice moves four presents from node 2 to node 1.
- Bob moves three presents from node 2 to node 1.
- Alice moves three presents from node 3 to node 1.
- Bob moves three presents from node 4 to node 3.
- Alice moves three presents from node 3 to node 1.
Bob is now unable to make a move and hence loses.
Root node 2
Bob always wins in this case. One such gameplay is:
- Alice moves four presents from node 4 to node 3.
- Bob moves four presents from node 5 to node 2.
- Alice moves six presents from node 3 to node 1.
- Bob moves six presents from node 1 to node 2.
Alice is now unable to make a move and hence loses.