Under construction

Still being built. Things may change

Potential

Time limit3sMemory limit1024 MB

Summary
Find integer vertex potentials that make every edge's reweighted value w + Φu - Φv equal, or report that no such potentials exist.
Level

Medium6 of 10

Topics
Graph, BFS, Math
Solved
No attempts yet

Problem

You are given a weighted directed graph. Each vertex ii has a potential Φi\Phi_i. Let wuvw_{uv} be the weight of the edge (u,v)(u, v). The new weight is defined as wuv′=wuv+Φu−Φvw'_{uv} = w_{uv} + \Phi_u - \Phi_v.

Find integer potentials Φi\Phi_i such that the new weights w′w' of all edges are equal.

Input

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 xix_i, yiy_i and wiw_i, the start vertex, end vertex, and weight of an edge (1≤xi,yi≤n1 \le x_i, y_i \le n, −109≤wi≤109-10^9 \le w_i \le 10^9). The graph has no self-loops and no multiple edges.

The sum of all nn and the sum of all mm do not exceed 600 000600\,000.

Output

For each test case, print "YES" on the first line if an integer solution exists, or "NO" otherwise.

If a solution exists, print nn integers on the next line: the potentials of the vertices. The absolute value of each potential must not exceed 101810^{18}. If a solution exists, one satisfying this bound is guaranteed to exist.

If there is more than one solution, print any one of them.

Examples1

  1. Example 1

    Input
    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
    
    Expected output
    YES
    0 -1 1 2 181
    YES
    0 0 0 0 -1