Potential
Time limit3sMemory limit1024 MB
Find integer vertex potentials that make every edge's reweighted value w + Φu - Φv equal, or report that no such potentials exist.
Problem
You are given a weighted directed graph. Each vertex has a potential . Let be the weight of the edge . The new weight is defined as .
Find integer potentials such that the new weights of all edges are equal.
Input
The first line of input contains an integer , the number of test cases.
Each test case starts with a line containing two integers and , the number of vertices and edges in the graph (, ). Each of the next lines contains three integers , and , the start vertex, end vertex, and weight of an edge (, ). The graph has no self-loops and no multiple edges.
The sum of all and the sum of all do not exceed .
Output
For each test case, print "YES" on the first line if an integer solution exists, or "NO" otherwise.
If a solution exists, print integers on the next line: the potentials of the vertices. The absolute value of each potential must not exceed . If a solution exists, one satisfying this bound is guaranteed to exist.
If there is more than one solution, print any one of them.