Potential

시간 제한3초메모리 제한1024 MB

요약
가중 방향 그래프가 주어질 때 모든 간선의 새 가중치 w + Phi_u - Phi_v가 같은 상수가 되도록 정수 퍼텐셜 Phi를 정한다.
난이도

어려움10점 중 8점

유형
그래프, DFS, 수학, 구현
정답자
아직 제출이 없습니다

문제

You are given a weighted directed graph. Let each vertex ii have potential Φ_i\Phi\_i. Let w_uvw\_{uv} be the weight of the edge (u,v)(u, v). Then, define the new weight as w′_uv=w_uv+Φ_u−Φ_vw'\_{uv} = w\_{uv} + \Phi\_u - \Phi\_v.

Find such integer potentials Φ_i\Phi\_i that the weights w′w' for all edges will be equal.

입력

The first line of input contains an integer tt, the number of test cases.

Each test case starts with a line containing two integers nn and mm: the number of vertices and edges in the graph (1≤n≤300,0001 \le n \le 300\\,000, 0≤m≤300,0000 \le m \le 300\\,000). Each of the next mm lines contains three integers x_ix\_i, y_iy\_i and w_iw\_i: start vertex, end vertex and weight of an edge (1≤x_i,y_i≤n1 \le x\_i, y\_i \le n, −109≤w_i≤109-10^9 \le w\_i \le 10^9). It is guaranteed that there are no self-loops and no multiple edges in the graph.

That the sum of all nn and all mm is guaranteed to not exceed 600,000600\\,000.

출력

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 nn integers: the potentials of the vertices. The potentials must not exceed 101810^{18} 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.

예제1

  1. 예제 1

    입력
    2
    5 4
    1 2 -1
    2 3 2
    3 4 1
    4 5 179
    5 5
    1 2 1
    2 3 1
    3 4 1
    4 5 0
    5 1 2
    
    예상 출력
    YES
    0 -1 1 2 181
    YES
    0 0 0 0 -1