You are given a connected simple undirected graph with vertices and edges. Edge joins vertices and . Each vertex has a given value .
Assign a positive integer weight to each edge so that the sum of weights of the edges incident to vertex equals for every .
Find the minimum possible maximum edge weight, or determine that no valid assignment exists.
For each test case, output the minimum possible maximum edge weight, or -1 if no consistent assignment exists.
The vertex sums force edge weights in input order.
Edge weights give a maximum of . A maximum of cannot give any vertex sum of .
Each vertex has two incident edges, so its sum must be at least .
The edge weights satisfy all vertex sums. The edge incident to vertex must have weight .
The edge incident to vertex must have weight . Assign weight to each of the other four edges.