#P1815F. OH NO1 (-2-3-4)
OH NO1 (-2-3-4)
No submission language available for this problem.
Description
You are given an undirected graph with vertices and edges. The graph may contains multi-edges, but do not contain self loops.
The graph satisfy the following property: the given edges can be divided into groups of , such that each group is a triangle.
A triangle are three edges , and , for some three distinct vertices ().
Initially, each vertex has a non-negative integer weight . For every edge in the graph, you should perform the following operation exactly once:
- Choose an integer between and . Then increase both and by .
After performing all operations, the following requirement should be satisfied: if and are connected by an edge, then .
It can be proven this is always possible under the constraints of the task. Output a way to do so, by outputting the choice of for each edge. It is easy to see that the order of operations do not matter. If there are multiple valid answers, output any.
The first line contains a single integer () — the number of test cases. The description of test cases follows.
The first line of each test case contains two integers and (, ) — denoting the graph have vertices and edges.
The second line of each test case contains integers () — the initial weights of each vertex.
Then lines follows. The -th line contains three integers , , () — denotes that three edges , and .
Note that the graph may contain multi-edges: a pair may appear in multiple triangles.
It is guaranteed that the sum of over all test cases do not exceed and the sum of over all test cases do not exceed .
For each test case, output lines of integers each.
The -th line should contains three integers (), denoting the choice of value for edges , and respectively.
Input
The first line contains a single integer () — the number of test cases. The description of test cases follows.
The first line of each test case contains two integers and (, ) — denoting the graph have vertices and edges.
The second line of each test case contains integers () — the initial weights of each vertex.
Then lines follows. The -th line contains three integers , , () — denotes that three edges , and .
Note that the graph may contain multi-edges: a pair may appear in multiple triangles.
It is guaranteed that the sum of over all test cases do not exceed and the sum of over all test cases do not exceed .
Output
For each test case, output lines of integers each.
The -th line should contains three integers (), denoting the choice of value for edges , and respectively.
Note
In the first test case, the initial weights are . We have added values as follows:
- Added to vertices and
- Added to vertices and
- Added to vertices and
The final weights are . The output is valid because , , , and that all chosen values are between and .
In the second test case, the initial weights are . The weights after the operations are . The output is valid because , , , and that , , , and that all chosen values are between and .
In the third test case, the initial weights are . The weights after the operations are , so all final weights are distinct, which means no two adjacent vertices have the same weight.