Regional development

아직 제출이 없습니다시간 제한4초메모리 제한256 MB

문제

The King has received several complaints that certain regions of his kingdom are economically neglected. The citizens have not seen a single merchant travelling on certain roads between villages in a very long time. To fix this problem and return wealth and prosperity to his kingdom, the King has appointed his royal mathematician to come up with a viable plan of merchant’s routes.

The plan will consist of a positive number of merchants travelling along each road in one of the directions. The number of merchants entering a village along the roads should be equal to the number of merchants exiting it. To ensure a somewhat even distribution of merchants throughout the kingdom, the King has requested that the number of merchants travelling along each road should be at least one and less than MM.

The royal mathematician has been summoned by the King to present his findings. His future is uncertain as he has not been able to solve the problem. However, he did make some progress. He found a plan with a valid number of merchants travelling along each road. The only problem is that the incoming and outgoing merchants in the villages do not add up (at least not exactly). Their difference might not be zero for every village, but it is equal to zero modulo MM. He is willing to share his findings with you, if you can write a program that finds a valid plan or reports that it doesn’t exist.

입력

The first line contains NN, the number of villages, RR, the number of roads and the number MM.

The following RR lines describe the roads with numbers A_iA\_i, B_iB\_i and C_iC\_i that indicate a road between villages A_iA\_i and B_iB\_i with C_iC\_i merchants travelling from A_iA\_i to B_iB\_i. Cities are numbered from 11 to NN. There is at most one road between each pair of villages and no road connects a village with itself. The difference between incoming and outgoing merchants in each village is equal to 00 modulo MM.

출력

Print the number of merchants travelling along each road. Print them in the same order as they were given in the input and on separate lines. If the merchants travel in the opposite direction with respect to the order of cities that defined a road in the input, indicate this with a negative value (e.g. if there are XX merchants travelling from B_iB\_i to A_iA\_i, indicate this with X-X in the ii-th line of output).

If there are multiple solutions, you can output any of them. If no solution exists, print the word "IMPOSSIBLE" in a single line (without the quotes).

제한

  • 1N10001 ≤ N ≤ 1000
  • 0R10,0000 ≤ R ≤ 10\\,000
  • 2M10002 ≤ M ≤ 1000
  • 1A_i,B_iN1 ≤ A\_i , B\_i ≤ N
  • 0<C_i<M0 < C\_i < M