#P8047. [COCI 2015/2016 #4] GALAKSIJA
[COCI 2015/2016 #4] GALAKSIJA
Problem Description
A long time ago, in a galaxy far, far away, there were planets and edges connecting all planets. In other words, the planets and edges formed a tree. Also, each edge had a weight.
A planet pair is boring if and only if the following conditions hold:
- .
- Planets and can reach each other.
- The xor sum of the weights of all edges on the path between and equals .
Now, due to an uncontrollable force, all edges in the galaxy will be destroyed in a fixed order. Please output the number of boring planet pairs at the beginning and after each time an edge is destroyed.
Input Format
The first line contains an integer , the number of planets.
Then follow lines, each containing three integers , meaning that the -th edge connects nodes and , and its weight is .
Then a line contains integers; the -th integer indicates the index of the edge destroyed in the -th destruction.
Output Format
Output lines, each containing one integer. The -th integer denotes the number of boring planet pairs after destroying edges in order.
2
1 2 0
1
1
0
3
1 2 4
2 3 4
1 2
1
0
0
4
1 2 0
2 3 0
2 4 0
3 1 2
6
3
1
0
Hint
[Sample 1 Explanation]
Initially, only the planet pair is boring. After destroying the only edge, there are no boring planet pairs anymore.
[Sample 2 Explanation]
Initially, only the planet pair is boring. After destroying edge , since planets and can no longer reach each other, there are no boring planet pairs afterward.
[Sample 3 Explanation]
Initially, all planet pairs are boring, because for every pair of planets, the xor sum of the weights of all edges on the path between them is .
[Constraints]
For all testdata, , , .
There are test points in total. The constraints for each test point are as follows:
| Test Point | Special Property A | |
|---|---|---|
Special Property A: The weight of every edge is . In other words, , .
[Source]
This problem comes from COCI 2015-2016 CONTEST 4 T5 GALAKSIJA. With the original testdata configuration, the full score is points.
Translated and organized by Eason_AC.
Translated by ChatGPT 5