Potential
시간 제한3초메모리 제한1024 MB
가중 방향 그래프가 주어질 때 모든 간선의 새 가중치 w + Phi_u - Phi_v가 같은 상수가 되도록 정수 퍼텐셜 Phi를 정한다.
문제
You are given a weighted directed graph. Let each vertex have potential . Let be the weight of the edge . Then, define the new weight as .
Find such integer potentials that the weights for all edges will be equal.
입력
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 : start vertex, end vertex and weight of an edge (, ). It is guaranteed that there are no self-loops and no multiple edges in the graph.
That the sum of all and all is guaranteed to not exceed .
출력
For each test case, on the first line, print "YES" if an integer solution exists, or "NO" otherwise.
If the answer is positive, on next line, print integers: the potentials of the vertices. The potentials must not exceed by absolute value. It is guaranteed that, if a solution exists, there also exists a solution satisfying the above requirement.
If there is more than one solution, output any one of them.