Translation credit to Kaz Nakao
In the country of IOI, there was a railway mogul JOI that owned all of the railroads.
However, JOI has passed away and the railways he owns are to be distributed as a split inheritance.
In IOI, there are
The cities are numbered
A railroad
There may be several lines between the same two cities.
The railroads will be divided among the
Each child is given a number from
Each child will receive some number of railroads out of the total
First, child 1 will choose a set of railroads to inherit from the set of M railroads.
Next, child 2 will choose anohter set of railroads to inherit from the remaining number of railroads.
Following the above pattern, the
However, there are a couple of rules about how the children will choose their railroads.
- A child won't choose a railroad that has already been chosen. For example, if the first child chooses railroad
$i$ , the second child wouldn't be able to choose railroad$i$ anymore. - A child won't choose railroads that form a "cycle". A "cycle" is formed when you can start at a city and can get back to it using each edge in a distinct set of edges once.
- As all the children are as greedy as their father, they will always choose the set of railroads that yield the optimal profit. It is guaranteed that there is only one inheritance arrangement that meets the above rules.
If a railroad is not chosen by any child, it becoms publicly owned.
Given the railroads and the children, determine which child will choose which railroads.
The first line contains 3 space-separated integers
The following
The output should consist of
Line
If no child owns the railway, output 0 instead.
3 5 2
1 2 3
1 2 1
2 3 4
2 3 6
1 3 2
1
0
2
1
2
The first child chooses railroads 1 and 4. These two railroads yield a total profit of 3 + 6 = 9 yen, which is the optimal profit. Note that he cannot choose railroads 3 and 4, because these two would form a cycle.
The second child chooses railroads 3 and 5 among the resulting railroads (2, 3, and 5). These two railroads yield a total profit of 4 + 2 = 6 yen, which is the most profit they can get.
Railroad 2 is not chosen, and thus becomes publicly owned.
3 6 5
1 2 1
1 2 2
2 3 3
2 3 4
3 1 5
3 1 6
4
3
2
1
2
1