#P4551. 最长异或路径

最长异或路径

Description

Given a weighted tree with nn nodes, indexed from 11 to nn. Find the maximum value among the XOR of all paths in the tree.

An XOR path is the XOR of all edge weights along the unique path between two nodes in the tree.

Constraints 1n105;0<u,vn;0w<2311 \le n \le 10^5; 0 < u, v \le n; 0 \le w < 2^{31}.

Input Format

The first line contains an integer nn, the number of nodes.

The next n1n-1 lines each contain u,v,wu, v, w, meaning there is an edge between node uu and node vv with weight ww.

Output Format

One line with a single integer, the answer.

4
1 2 3
2 3 4
2 4 6
7

Hint

When the two nodes are 11 and 33, the value is 7=347=3\oplus 4, which is the maximum.

Translated by ChatGPT 5