xortree2

Time limit: 1.5s Memory limit: 64MB Input: Output:

Task

You are given a tree with NN nodes. Each edge has a weight wiw_i. The difference of two nodes uu and vv is the binary XOR of the weights on the simple path that connects them. More formally, if the simple path between uu and vv consists of the edges e1,e2,,ele_1, e_2, \dots, e_l, then their difference is defined as we1we2welw_{e_1} \oplus w_{e_2} \oplus \dots \oplus w_{e_l}.

Let II be the set of interesting nodes (II is initially empty). You have to perform QQ operations on this set: in one operation, a node is either added or removed from II. After each operation, you have to print the maximum difference between two distinct interesting nodes (if I1|I| \leq 1, you must print 00).

Input

The first line contains two integers, NN (1N50 0001 \le N \le 50\ 000) and QQ (1Q50 0001 \le Q \le 50\ 000). The ii-th of the following N1N-1 lines contains three integers uiu_i, viv_i (1ui,viN1 \le u_i, v_i \le N for each i=1N1i=1\ldots N-1.) and wiw_i (0wi1090 \le w_i \le 10^9 for each i=1N1i=1\ldots N-1), corresponding to an edge of weight wiw_i between nodes uiu_i and viv_i.

Each of the next QQ lines contains a single integer pip_i (1piN1 \le p_i \le N for each i=1Qi=1\ldots Q). If pi∉Ip_i \not \in I, then node pip_i gets added to II, otherwise it gets deleted from II.

For tests worth 1111: N,Q100N, Q \leq 100.

For tests worth 1313: wi{0,1}w_i \in \{0, 1\} for each i=1N1i = 1 \ldots N-1.

For tests worth 1717: N,Q1000N, Q \leq 1000.

For tests worth 5959: No additional limitations.

Output

You need to print QQ lines. The ii-th line must contain a single integer, the maximum difference between two interesting nodes after the ii-th operation.

stdin

3 4
1 2 1
1 3 2
1
2
3
2

stdout

0
1
3
2

stdin

5 5
1 2 3
1 3 1
3 4 4
3 5 1
3
1
4
3
2

stdout

0
1
5
5
6

Notes

In the first sample case, the set of interesting nodes and the interesting pair with the maximum difference after each operation:

No. of operation Set of interesting nodes Pair with maximum difference
1 {1}\{1\} No pairs
2 {1,2}\{1, 2\} (1,2)(1, 2)
3 {1,2,3}\{1, 2, 3\} (2,3)(2, 3)
4 {1,3}\{1, 3\} (1,3)(1, 3)

In the second sample case, the set of interesting nodes and the interesting pair with the maximum difference after each operation:

No. of operation Set of interesting nodes Pair with maximum difference
1 {1}\{1\} No pairs
2 {1,3}\{1, 3\} (1,3)(1, 3)
3 {1,3,4}\{1, 3, 4\} (1,4)(1, 4)
4 {1,4}\{1, 4\} (1,4)(1, 4)
5 {1,2,4}\{1, 2, 4\} (2,4)(2, 4)

Log in or sign up to be able to send submissions!