Mr. JOI, the millionare who owns all of the IOI kingdom's railways, has passed away. According to his will, the railways are to be divided among his children.
There are N cities in the IOI kingdom, numbered from 1 to N. There are M railways connecting the cities, numbered from 1 to M. Railway i connects cities Ai and city Bi in both directions, and produces a profit of Ci yen in one year. Ci, ..., CM are all pairwise distinct because some railways are used more by passengers and railways also have different operating costs. There might be more than one railway connecting two cities.
Mr. JOI's will gave the following instructions on the distribution of his railway:
Every child is greedy just like their father and will pick railways such that the total annual profit of his or her inheritance is as large as possible. The total annual profit of a set of railways is the sum of the annual profit for each railway in the set. For each child, the choice of railways that maximizes his or her total annual profit is unique. For each railway, determine who it is distributed to.
Given information about the IOI kingdom's railways and the number of children Mr. JOI had, write a program to find the eventual ownership of each railway.
Read from standard input.
Print to standard output.
All input data satisfies following constraints:
Subtask 1 (15 points): K ≤ 10.
Subtask 2 (85 points): No additional constraints.
3 5 2
1 2 3
1 2 1
2 3 4
2 3 6
1 3 2
1
0
2
1
2
Child 1 chooses railways 1, 4 from railways 1, 2, 3, 4, 5, obtaining a total annual profit of 3 + 6 = 9 yen. This is the maximum.
Child 2 chooses railways 3, 5 from railways 2, 3, 5, obtaining a total annual profit of 4 + 2 = 6 yen. This is the maximum.
The remaining railway 2 is donated to the IOI kingdom.
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
The number of railways inherited by each child can differ. There can also exist a child that does not inherit any railways.
Subtask | Score |
---|---|
1 | 15 |
2 | 85 |
3 | 0 |