#P3359. 改造异或树

改造异或树

Description

You are given a tree with nn nodes, and each edge has a weight. Now we delete all n1n - 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 n1n - 1 lines each contain three integers ai,bi,zia_i, b_i, z_i, with 1ai,bin1 \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 n1n - 1 integers separated by single spaces, which form a permutation of 1n11 \sim n - 1, representing the deletion order of the n1n - 1 edges.

Output Format

Output nn lines, each containing one integer. The kk-th line (where k=0,1,,n1k = 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, n1000n \le 1000.

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

For all testdata, n105n \le 10^5, 0zi1090 \le z_i \le 10^9.

Translated by ChatGPT 5