# c8kbf and Tree CodeChef Solution

### We Are Discuss About CODECHEF SOLUTION

c8kbf and Tree CodeChef Solution

## c8kbf and Tree CodeChef Solution ## Problem

Chef c8kbf has an unrooted, weighted tree with  nodes, where vertices  and  are connected by an edge with weight .

The value of the simple path from  to  is defined as the bitwise XOR of the weights of the edges it consists of.
Recall that a simple path is a path that does not have repeating vertices.

Help Chef c8kbf find any four vertices �,�,�,�, such that:

• �<� and �<�;
• The value of the simple path from  to  is equal to that of the path from  to ;
• The pairs (�,�) and (�,�) are different. In other words, �≠� or �≠�.
Note that the four vertices do not have to be all distinct. For example, it is allowed for  and  to be the same if  and  are different.

If no four vertices satisfy such a property, report so. If there are multiple answers, output any one of them.

### Input Format

• The first line of input will contain a single integer , denoting the number of test cases.
• Each test case consists of multiple lines of input. For each test case,
• The first line contains an integer , the number of vertices.
• The next �−1 lines contain three space-separated integers ����, and ��, denoting an edge between �� and �� with weight ��. It is guaranteed that these edges will form a tree.

### Output Format

For each test case, output four space-separated integers , and  on a new line, representing the four vertices. If there are multiple answers, output any one of them.

If no four vertices satisfy the property, output −1 on a new line instead.

### Constraints

• 1≤�≤10
• 3≤�≤105
• 1≤��,��≤�
• ��≠�� for each 1≤�≤�−1.
• 0≤��≤220
• It is guaranteed that the given edges will form a tree.
• The sum of  over all test cases won’t exceed 3⋅105.

### Sample 1:

Input

Output

3
4
1 2 1
2 3 2
2 4 3
4
1 2 2
2 3 4
2 4 8
3
1 2 5
2 3 0
1 4 2 3
-1
1 2 1 3

### Explanation:

Test case 1: The value of the path between vertices 1 and 4 is 1⊕3=2. The path between vertices 3 and 2 only has one edge, so the value is also 2. Note that 2 3 1 4 or 2 4 1 3 would be other acceptable answers.

Test case 2: No four vertices satisfy the property.

Test case 3: Note that �=� for the output of this case, which is allowed. ## SOLUTION

Yhaa You have done it but next? if YOU Want to Get Others Please Visit Here ScishowEngineer   Then Follow US HERE and Join Telegram.