2278: 【信息学奥赛一本通】The xor-longest Path

Memory Limit:128 MB Time Limit:1.000 S
Judge Style:Text Compare Creator:
Submit:16 Solved:16

Description

原题来自:POJ 3764

给定一棵 n 个点的带权树,求树上最长的异或和路径。

Input

第一行一个整数 n,接下来 n−1 行每行三个整数 u,v,w,表示 u,v 之间有一条长度为 w 的边。

Output

输出一行一个整数,表示答案。

Sample Input Copy

4
1 2 3
2 3 4
2 4 6

Sample Output Copy

7

HINT

样例解释

最长的异或和路径是 1→2→3 ,它的长度是 3⨁4=7。

注意:结点下标从 1 开始到 N。

注:x⨁y 表示 x 与 y 按位异或。