Walking Around
InterviewTime limit1sMemory limit2048 MB
Given a weighted tree, find the minimum and maximum XOR of edge weights over all paths between two distinct vertices.
- Level
Medium4 of 10
- Topics
- Tree, Bit manipulation, Trie
- Solved
- No attempts yet
Problem
You are given a weighted tree with vertices, numbered from to . The edges are numbered from to , where edge connects two vertices and and has a non-negative integer weight .
A path in the tree is a sequence of distinct vertices for some , such that every pair of adjacent vertices for is connected by an edge of the tree. The score of the path is the bitwise XOR of the weights of all edges on the path, that is , where is the weight of the edge connecting and .

Find the minimum and the maximum score among all paths in the tree.
Input
The first line contains an integer (), the number of vertices. Each of the next lines contains three integers , , and (; ), describing edge .
Output
Print the minimum and the maximum score separated by a space, on a single line.