GUPTA MECHANICAL

IN THIS WEBSITE I CAN TELL ALL ABOUT TECH. TIPS AND TRICKS APP REVIEWS AND UNBOXINGS ALSO TECH. NEWS .............

Friday 6 May 2022

Hemose on the Tree Codeforces Solution | Codeforces Problem Solution 2022

E. Hemose on the Tree
time limit per test
2 seconds
memory limit per test
256 megabytes
input
standard input
output
standard output

After the last regional contest, Hemose and his teammates finally qualified to the ICPC World Finals, so for this great achievement and his love of trees, he gave you this problem as the name of his team "Hemose 3al shagra" (Hemose on the tree).

You are given a tree of n vertices where n is a power of 2. You have to give each node and edge an integer value in the range [1,2n1] (inclusive), where all the values are distinct.

Solution Click Below:-  CLICK HERE

After giving each node and edge a value, you should select some root for the tree such that the maximum cost of any simple path starting from the root and ending at any other node or edge is minimized.

The cost of the path between two nodes u and v or any node u and edge e is defined as the bitwise XOR of all the node's and edge's values between them, including the endpoints (note that in a tree there is only one simple path between two nodes or between a node and an edge).

Prof. Slim Codeforces Solution | Codeforces Problem Solution 2022

Dorms War Codeforces Solution | Codeforces Problem Solution 2022

Where is the Pizza? Codeforces Solution | Codeforces Problem Solution 2022

Very Suspicious Codeforces Solution | Codeforces Problem Solution 2022

Hemose on the Tree Codeforces Solution | Codeforces Problem Solution 2022

Jee, You See? Codeforces Solution | Codeforces Problem Solution 2022


Input

The first line contains a single integer t (1t5104) — the number of test cases. Then t test cases follow.

The first line of each test case contains a single integer p (1p17), where n (the number of vertices in the tree) is equal to 2p.

Each of the next n1 lines contains two integers u and v (1u,vn) meaning that there is an edge between the vertices u and v in the tree.

It is guaranteed that the given graph is a tree.

It is guaranteed that the sum of n over all test cases doesn't exceed 3105.

Output

For each test case on the first line print the chosen root.

On the second line, print n integers separated by spaces, where the i-th integer represents the chosen value for the i-th node.

On the third line, print n1 integers separated by spaces, where the i-th integer represents the chosen value for the i-th edge. The edges are numerated in the order of their appearance in the input data.

If there are multiple solutions, you may output any.

Join Now for Solution:- 

No comments:

Post a Comment