Two papers I

2.6

21 votes
Dynamic Programming, Algorithms, Trees, Math
Problem

Y found two papers and a pencil in his room (It's svaluable for a prisoner). a weighted tree is drawn on the first paper and intialy 0 is written on the second paper.

He will do following operation for all nonempty matchings of the tree drawn on the first paper:

  • First Y will bitwise xor the matching's all edges weights, let's call this value y.
  • Second consider x is written on the second paper, Y will erase it and write xy (bitwise xor of x and y) on the second paper.

What is the number written on the second paper after Y has done all operations?

Input

First line contains only n, number of tree's vertices.

Each of following n1 lines contains vi,ui and wi separated space describing tree's ith edge's vertices(vi,ui) and its weight (wi).

1n2×105

1vi,uin0wi109

It is guaranteed that the edges form a tree.

Output

The only line of output contains an integer, the number written on the second paper after Y has done all operations.

Time Limit: 4
Memory Limit: 256
Source Limit:
Explanation

There is two nonempty matching which xor of their edge's weights are 1 and 6 so answer is 16=7.

Editor Image

?