Add edges
Use language Plain text
for this task. This is Output only
task.
Given a tree with vertices and edges. It is necessary to add exactly new edges to this tree. Adding multiple edges or loops is prohibited. If the degree of a certain vertex was before adding edges, then after adding edges, its degree should not exceed . It should be noted that the degree of a vertex is the number of edges connecting it to other vertices.
In addition, integers are given. After adding edges, it is necessary to assign each edge one of the elements of the array so that each element of the array corresponds to exactly one edge. The value assigned to the edge will denote its weight.
It is necessary to add new edges and assign numbers to the edges in such a way that the sum of the shortest distances between each pair of vertices is maximized. That is, it is necessary to maximize the function , where is the minimum distance between vertices, for all and (). The minimum distance between vertices is considered to be the sum of the weights of all edges on the simple path between them.
Please note that in this problem, you need to submit not the code, but the actual answers. You also have access to all the tests, which can be downloaded from Eolymp.
Input
There are tests.
The first line of each test contains three integers , , and (, , ) - the number of vertices in the tree, the number of edges to be added, and the maximum number of edges that can be added to one vertex.
The second line contains integers ().
The next lines contain two integers each, and () - the numbers of vertices connected by an edge. It is guaranteed that the initially given graph is a tree.
It is guaranteed that it is always possible to add edges in such a way that all the requirements described in the task are met.
Output
For each test, output the following:
If you have an answer for this test, output , otherwise output .
If you have an answer, then in each of the next lines, output three integers - the numbers of vertices connected by an edge in the final graph, and its weight.
Examples
Scoring
Let be a certain variable in the test, and be the sum of distances in your graph. If , you will receive points for the test. Otherwise, you will receive as many points for the test as:
If is the sum of points for all tests, then for the attempt you will receive , rounded to the nearest integer.