There is a tree with vertices numbered . The tree is rooted at vertex .
There is a building of height at vertex . Every height is a nonnegative integer and satisfies the following conditions.
An exploration robot moves from vertex to vertex along the simple path between them. When it traverses an edge and the height increases by , it consumes unit of battery. When the height decreases by , it gains unit of battery. The battery level must never become negative during the movement.
Define as the minimum initial battery level that allows the robot to move from to . If the robot starts with exactly units of battery, let be the first vertex at which its battery level is . The starting vertex is included when determining this first vertex. Let be the remaining battery level when the robot reaches during the same movement.
There are records of past explorations. Each record gives the values of , , and for a pair of vertices .
Find one assignment of heights that is consistent with every record. If no such assignment exists, determine that it is impossible.
The input is given from Standard Input in the following format:
For each test case, print one line.
If a valid height assignment exists, print integers in the following format:
Each case is given in the following format:
is the -th edge of the tree.
The -th exploration record means , , and .
The printed heights must satisfy every condition and every exploration record. If there are multiple solutions, print any of them.
If no valid height assignment exists, print -1.
| 3 | 19 |
|
| 4 | 24 | The edges are exactly . |
| 5 | 38 | No additional constraints. |