atcoder#AGC052B. [AGC052B] Tree Edges XOR
[AGC052B] Tree Edges XOR
Score : points
Problem Statement
You are given a tree with vertices, where is odd. The vertices are numbered from through and edges from through . The edge connects vertices and and its initial weight is .
You can perform the following operation any number of times:
- Choose an edge of the tree, and suppose that its weight now is . For every edge, which is incident to exactly one of and , we XOR the weight of that edge with (if it was , replace it with ).
Your goal is to reach the state where each edge has weight . Determine if you can get to the goal by performing the operation above any number of times.
Constraints
- is odd.
- All values in input are integers.
- The input represents a valid tree.
Input
Input is given from Standard Input in the following format:
Output
If you can get the goal weight assignment from the initial state, output YES
. Otherwise, output NO
.
Note that the checker is case-insensitive: you can print letters in both uppercase and lowercase.
3
1 2 1 1
2 3 8 9
YES
If you perform the operation on the edge , the weight of the edge becomes .
5
1 2 0 3
1 3 1 0
1 4 2 1
1 5 0 0
NO