Graph
时间限制:C/C++/Rust/Pascal 1秒,其他语言2秒
空间限制:C/C++/Rust/Pascal 256 M,其他语言512 M
64bit IO Format: %lld

题目描述

Mr. W got a new graph with N vertices and N - 1 edges. It's a connected graph without cycles. Each edge should have an ugly value. To make the graph more beautiful, Mr. W hope you can help him modify it. You can delete or add one edge with an ugly value at a time and you can do it as many times as you want. But the following conditions should be satisfied at any time:
1. The graph is connected.
2. For each cycles in the graph, the XOR sum of all ugly values in the cycle is 0.
Mr. W wants to know the minimum sum of ugly values of all edges in the graph.

输入描述:

The first line contains one integer.
Next N - 1 lines each contains three integers , denoting an edge between vertex U and V with ugly value W.

输出描述:

One integer, the minimum sum of ugly values of all edges in the graph.
示例1

输入

复制
6
0 1 1
1 2 4
1 3 3
0 4 5
0 5 2

输出

复制
7