#Q58. 「一本通 2.3 练习 5」The XOR-longest Path

「一本通 2.3 练习 5」The XOR-longest Path

Description

Original problem from: POJ 3764

Given a weighted tree with nn nodes, find the longest XOR path on the tree.

Input Format

The first line contains an integer nn. The next n1n-1 lines each contain three integers u,v,wu, v, w, indicating an edge between uu and vv with length ww.

Output Format

Output a single integer representing the answer.

Sample 1

The longest XOR path is 1231\to 2\to 3, with a length of 34=73 \bigoplus 4=7.

Note: Node indices range from 11 to NN.

Note: xyx \bigoplus y denotes the bitwise XOR of xx and yy.

4
1 2 3
2 3 4
2 4 6

7

Constraints & Hints

For 100%100\% of the data, 1n105,1u,vn,0w<2311\le n\le 10^5,1\le u, v \le n,0 \le w < 2^{31}