CF901D Weighting a Tree
Description
You are given a connected undirected graph with $ n $ vertices and $ m $ edges. The vertices are enumerated from $ 1 $ to $ n $ .
You are given $ n $ integers $ c_{1},c_{2},...,c_{n} $ , each of them is between $ -n $ and $ n $ , inclusive. It is also guaranteed that the parity of $ c_{v} $ equals the parity of degree of vertex $ v $ . The degree of a vertex is the number of edges connected to it.
You are to write a weight between $ -2·n^{2} $ and $ 2·n^{2} $ (inclusive) on each edge in such a way, that for each vertex $ v $ the sum of weights on edges connected to this vertex is equal to $ c_{v} $ , or determine that this is impossible.
Input Format
The first line contains two integers $ n $ and $ m $ ( $ 2
Output Format
If there is no solution, print "NO".
Otherwise print "YES" and then $ m $ lines, the $ i $ -th of them is the weight of the $ i $ -th edge $ w_{i} $ ( $ -2·n^{2}