CF1615D X(or)-mas Tree
Description
'Twas the night before Christmas, and Santa's frantically setting up his new Christmas tree! There are $ n $ nodes in the tree, connected by $ n-1 $ edges. On each edge of the tree, there's a set of Christmas lights, which can be represented by an integer in binary representation.
He has $ m $ elves come over and admire his tree. Each elf is assigned two nodes, $ a $ and $ b $ , and that elf looks at all lights on the simple path between the two nodes. After this, the elf's favorite number becomes the [bitwise XOR](https://en.wikipedia.org/wiki/Bitwise_operation#XOR) of the values of the lights on the edges in that path.
However, the North Pole has been recovering from a nasty bout of flu. Because of this, Santa forgot some of the configurations of lights he had put on the tree, and he has already left the North Pole! Fortunately, the elves came to the rescue, and each one told Santa what pair of nodes he was assigned $ (a_i, b_i) $ , as well as the parity of the number of set bits in his favorite number. In other words, he remembers whether the number of $ 1 $ 's when his favorite number is written in binary is odd or even.
Help Santa determine if it's possible that the memories are consistent, and if it is, remember what his tree looked like, and maybe you'll go down in history!
Input Format
N/A
Output Format
N/A
Explanation/Hint
The first test case is the image in the statement.
One possible answer is assigning the value of the edge $ (1, 2) $ to $ 5 $ , and the value of the edge $ (2, 5) $ to $ 3 $ . This is correct because:
- The first elf goes from node $ 2 $ to node $ 3 $ . This elf's favorite number is $ 4 $ , so he remembers the value $ 1 $ (as $ 4 $ has an odd number of $ 1 $ bits in its binary representation).
- The second elf goes from node $ 2 $ to node $ 5 $ . This elf's favorite number is $ 3 $ , so he remembers the value $ 0 $ (as $ 3 $ has an even number of $ 1 $ bits in its binary representation).
- The third elf goes from node $ 5 $ to node $ 6 $ . This elf's favorite number is $ 7 $ , so he remembers the value $ 1 $ (as $ 7 $ has an odd number of $ 1 $ bits in its binary representation).
- The fourth elf goes from node $ 6 $ to node $ 1 $ . This elf's favorite number is $ 1 $ , so he remembers the value $ 1 $ (as $ 1 $ has an odd number of $ 1 $ bits in its binary representation).
- The fifth elf goes from node $ 4 $ to node $ 5 $ . This elf's favorite number is $ 4 $ , so he remembers the number $ 1 $ (as $ 4 $ has an odd number of $ 1 $ bits in its binary representation).
Note that there are other possible answers.