##### ###### ##### ### # # ### # # ###### ## ## ## ## ## ## ## # # # # # ## ##### #### ##### # # # # # # # #### ## # ## ## ## ## # # # # # ## ## # ###### ## ### # ### # ######
##### ###### ##### ### # # ### # # ###### ## ## ## ## ## ## ## # # # # # ## ##### #### ##### # # # # # # # #### ## # ## ## ## ## # # # # # ## ## # ###### ## ### # ### # ######
##### ###### ##### ### # # ### # # ###### ## ## ## ## ## ## ## # # # # # ## ##### #### ##### # # # # # # # #### ## # ## ## ## ## # # # # # ## ## # ###### ## ### # ### # ######
5
1 2 1 1 1 1 1 1
2 1 1 1 2
3 2 1 1 2 2 2 3
4 2 1 1 2 3 3 4
5 6 1 3 5 2 2 4 4 5 5 1 1 1 2 3 3 1 4 5
The graph has only one vertex, so it is already connected. Both operations add self-loops.
Yes 1 1
Yes 2
Yes 2 3
No
Yes 1 4 4 1 2 5
You are given a graph with vertices. Initially, the graph has no edges.
You are also given operations. In the -th operation, three integers , , and are given, where .
For each operation, you must choose an integer such that , and then add an undirected edge between and .
The graph may contain self-loops and multiple edges.
Determine whether it is possible to choose all values so that the final graph is connected. If it is possible, output one valid choice.
For each test case, if it is impossible to make the graph connected, output
Otherwise, output two lines in the following format:
where for every , and the graph formed by the edges is connected.
If there are multiple valid answers, you may output any of them.
Choosing adds the edge between vertices and , so the graph becomes connected.
Choosing and adds the edges and , so all three vertices are connected.
The first operation can only use vertices from to , and the second operation can only use vertices from to . Therefore no edge can connect the two parts and .
One valid choice is . The added edges include , , , and , which connect all five vertices.