#P3359. 改造异或树

改造异或树

Problem Description

You are given a tree with nn nodes, and each edge has a weight. Now we delete all n−1n - 1 edges one by one in a given order. After deleting each edge, query how many paths currently have the XOR sum of edge weights equal to 00.

Input Format

The first line contains an integer nn.

The next n−1n - 1 lines each contain three integers ai,bi,zia_i, b_i, z_i, with 1≤ai,bi≤n1 \le a_i, b_i \le n, indicating that there is an edge with weight ziz_i between nodes numbered aia_i and bib_i.

The next line contains n−1n - 1 integers separated by single spaces, which form a permutation of 1∼n−11 \sim n - 1, representing the deletion order of the n−1n - 1 edges.

Output Format

Output nn lines, each containing one integer. The kk-th line (where k=0,1,…,n−1k = 0, 1, \dots, n - 1) is the number of paths whose XOR sum of edge weights is 00 after deleting the first kk edges in the given order.

4
1 2 0
2 3 0
2 4 0
3 1 2
6
3
1
0

Hint

For 20%20\% of the testdata, n≤1000n \le 1000.

For another 30%30\% of the testdata, all zi=0z_i = 0.

For all testdata, n≤105n \le 10^5, 0≤zi≤1090 \le z_i \le 10^9.

Translated by ChatGPT 5