You are given a connected simple undirected graph with vertices and edges. Edge joins vertices and . Each vertex has an unknown integer weight with .
The value of a path is the minimum vertex weight on it, including its endpoints. For distinct vertices and , let be the maximum value of a path between them. Set .
For each vertex , you are given . Find a compatible assignment of vertex weights, or determine that none exists.
For each test case, output the vertex weights, or -1 instead if no compatible assignment exists. If several assignments are possible, output any of them.
Vertex weights give totals .
No assignment of positive integer vertex weights gives totals .
Vertex weights are compatible. The path from to through has value .
Assigning weight to every vertex makes each of the four terms in each total equal to .