
ZOJ Problem Set  2342
The kingdom of Farland has N cities connected by M roads. Some roads are paved with stones, others are just country roads. Since paving the road is quite expensive, the roads to be paved were chosen in such a way that for any two cities there is exactly one way to get from one city to another passing only the stoned roads. The kingdom has a very strong bureaucracy so each road has its own ordinal number ranging from 1 to M: the stoned roads have numbers from 1 to N  1 and other roads have numbers from N to M. Each road requires some money for support, ith road requires ci coins per year to keep it intact. Recently the king has decided to save some money and keep financing only some roads. Since he wants his people to be able to get from any city to any other, he decided to keep supporting some roads in such a way, that there is still a path between any two cities. It might seem to you that keeping the stoned roads would be the good idea, however the king did not think so. Since he did not like to travel, he did not know the difference between traveling by a stoned road and travelling by a muddy road. Thus he ordered you to bring him the costs of maintaining the roads so that he could order his wizard to choose the roads to keep in such a way that the total cost of maintaining them would be minimal. Being the minister of communications of Farland, you want to help your people to keep the stoned roads. To do this you want to fake the costs of maintaining the roads in your report to the king. That is, you want to provide for each road the fake cost of its maintaining di in such a way, that stoned roads form the set of roads the king would keep. However, to lower the chance of being caught, you want the sum c_{1}d_{1} + c_{2}d_{2} + ... + c_{m}d_{m} to be as small as possible. You know that the king��s wizard is not a complete fool, so if there is the way to choose the minimal set of roads to be the set of the stoned roads, he would do it, so ties are allowed. This problem contains multiple test cases! The first line of a multiple input is an integer N, then a blank line followed by N input blocks. Each input block is in the format indicated in the problem description. There is a blank line between input blocks. The output format consists of N output blocks. There is a blank line between output blocks. Input The first line of the input file contains N and M (2 <= N <= 60, N  1 <= M <= 400). Next M lines contain three integer numbers a_{i}, b_{i} and c_{i} each  the numbers of the cities the road connects (1 <= a_{i} <= N, 1 <= b_{i} <= N, a_{i} != b_{i}) and the cost of maintaining it (1 <= c_{i} <= 10 000). Output Output M lines  for each road output di that should be reported to be its maintainance cost so that the king would choose first N  1 roads to be the roads to keep and the sum c_{1}d_{1} + c_{2}d_{2} + ... + c_{m}d_{m} is minimal possible. Sample Input
1 Sample Output
4 Author: Andrew Stankevich Source: Andrew Stankevich's Contest #2 