atcoder#APC001F. XOR Tree
XOR Tree
Score : points
Problem Statement
You are given a tree with vertices. The vertices are numbered through , and the edges are numbered through . Edge connects Vertex and , and has a value . You can perform the following operation any number of times:
- Choose a simple path and a non-negative integer , then for each edge that belongs to the path, change by executing (⊕ denotes XOR).
Your objective is to have for all edges . Find the minimum number of operations required to achieve it.
Constraints
- The given graph is a tree.
- All input values are integers.
Input
Input is given from Standard Input in the following format:
Output
Find the minimum number of operations required to achieve the objective.
5
0 1 1
0 2 3
0 3 6
3 4 4
3
The objective can be achieved in three operations, as follows:
- First, choose the path connecting Vertex , and .
- Then, choose the path connecting Vertex , and .
- Lastly, choose the path connecting Vertex , and .
2
1 0 0
0