Problem: A society can be represented by a connected, undirected graph of n vertices and m edges. The vertices represent people, and an edge (i,j) represents a friendship between people i and j.

In society, the i-th person has an income a_i. A person i is envious of person j if a_j=a_i+1. That is if person j has exactly 1 more unit of income than person i.

The society is called capitalist if for every pair of friends one is envious of the other. For some friendships, you know which friend is envious of the other. For the remaining friendships, you do not know the direction of envy.

The income inequality of society is defined as max_{1 ≤ i ≤ n} a_i - min_{1 ≤ i ≤ n} a_i.

You only know the friendships and not the incomes. If it is impossible for this society to be capitalist with the given knowledge, you should report about it. Otherwise, you should find an assignment of incomes in which the society is capitalist, and the income inequality is maximized.

Input

The first line contains two integers n, m (1≤ n≤ 200, n-1≤ m≤ 2000) — the number of people and friendships, respectively.

The following m lines describe the friendships. Each friendship is described by three integers i, j, b (1≤ i, j≤ n, i≠ j, 0≤ b≤ 1). This denotes that people i and j are friends. If b=1, we require that person i is envious of person j. If b=0, one friend should be envious of the other in either direction.

There is at most one friendship between each pair of people. It is guaranteed that if we consider the friendships as undirected edges, the graph is connected.

Output

Print "YES" if it is possible that the society is capitalist, or "NO" otherwise. You can print characters in any case (upper or lower).

If the answer is "YES", you should print two additional lines. In the first line, print the maximum possible income inequality. On the next line you should print n integers a_1,…, a_n (0≤ a_i≤ 10^6), where a_i denotes the income of the i-th person.

We can prove that if there exists a solution, there exists one where 0≤ a_i≤ 10^6 for all i.

If there exist multiple solutions, print any.

Examples

Input


6 6
1 2 0
3 2 0
2 5 0
6 5 1
6 3 0
2 4 1


Output


YES
3
3 2 1 3 1 0 


Input


4 4
1 2 1
2 3 0
3 4 1
4 1 1


Output


NO


Input


1 0


Output


YES
0
0 

Note

In the first test, we can show that an income inequality greater than 3 is impossible for the given society. In the given answer with income inequality equal to 3:

  * Person 2 is envious of person 1. 
  * Person 3 is envious of person 2. 
  * Person 5 is envious of person 2. 
  * Person 6 is envious of person 5 (the required direction is satisfied). 
  * Person 6 is envious of person 3. 
  * Person 2 is envious of person 4 (the required direction is satisfied). 



In the second test, we can show that there is no way to assign incomes to satisfy all requirements.

Solution (in CPP):

Solution:
// Codeforces Boilerplate
#include <bits/stdc++.h>

using namespace std;

typedef long long ll;

#define FOR(i,a,b) for(int i = a; i < b; i++)
#define ROF(i,a,b) for(int i = b-1; i >= a; i--)

// overloaded << operator for printing vectors. Idea from Neal Wu
template<typename T> ostream& operator<< (ostream& os, vector<T> v) {
    os << '['; string sep; for (const T& el : v) os << sep << el, sep = ", "; return os << ']';
} 
// cool recursive template for debug printing. also Neal Wu
void dbg_out () {cerr << endl;}
template<typename Head, typename... Tail> void dbg_out (Head H, Tail... T) {
    cerr << ' ' << H; dbg_out(T...);
}

#ifdef JACOB_DEBUG
#define dbg(desc, ...) cerr << '(' << desc << "):"; dbg_out(__VA_ARGS__);
#else
#define dbg(...)
#endif

struct Edge {
    Edge(int i, int j, int w) :start(i), end(j), weight(w) {}
    int start; int end; int weight;
};

// numbers r small in this problem
const int INF = 100000;

void run () {
    int n,m; cin >> n >> m;
    vector<Edge> edgelist;
    vector<vector<int> > adjlist (n+1);
    vector<vector<int> > adjmat(n+1, vector<int>(n+1, INF));
    FOR(i,0,m) {
        int start, end, weight;
        cin >> start >> end >> weight;
        int ijwt = 1, jiwt = 1;
        if (weight == 1) {
            jiwt = -jiwt;            
        }
        edgelist.push_back(Edge(start,end,ijwt));
        edgelist.push_back(Edge(end,start,jiwt));
        adjlist[start].push_back(end);
        adjlist[end].push_back(start);
        adjmat[start][end] = ijwt;
        adjmat[end][start] = jiwt;
    }

    FOR(i,1,n+1) adjmat[i][i]=0;

    // bfs to detect odd cycles
    bool has_odd_cycle = false;
    {
        // connected so doesn't matter where we start
        queue<int> bfs; bfs.push(1);
        vector<int> bfs_dist(n+1,-1);
        bfs_dist[1] = 0;
        while (!bfs.empty()) {
            int curr = bfs.front(); bfs.pop();
            dbg("c,a",curr,adjlist[curr]);
            for (int ch : adjlist[curr]) {
                if (bfs_dist[ch] != -1) {
                    if (bfs_dist[ch] == bfs_dist[curr]) has_odd_cycle = true;
                } else {
                    bfs_dist[ch] = bfs_dist[curr] + 1;
                    bfs.push(ch);
                }
            }
        }
    }
    // bellman-ford to detect negative cycles
    bool has_neg_cycle = false;
    {
        int last_i_with_improvement = -1;
        
        vector<int> bf_dist(n+1, INF);
        bf_dist[1] = 0;
        FOR(i,0,n) {
            for (Edge e: edgelist) {
                dbg("i,e",i,e.start,e.end,e.weight);
                if (bf_dist[e.end] > bf_dist[e.start] + e.weight) {

                    last_i_with_improvement = i;
                    bf_dist[e.end] = bf_dist[e.start] + e.weight;
                }
                dbg("bfd",bf_dist);
            }
        }
        has_neg_cycle = (last_i_with_improvement == (n-1));
        dbg("bf_dist", has_neg_cycle, bf_dist);
    }

    // floyd-warshall to calculate distances
    if (!(has_odd_cycle||has_neg_cycle)) {
        vector<vector<int> > fw_dist(adjmat);
        FOR(i,1,n+1) {
            // allow i to be intermediate between j and k
            FOR(j,1,n+1) {
                FOR(k,1,n+1) {
                    fw_dist[j][k] = min(fw_dist[j][k], fw_dist[j][i] + fw_dist[i][k]);
                }
            }
        }
        int best_i = 1, best_dist = 0;
        FOR(i,1,n+1) {
            FOR(j,1,n+1) {
                if (fw_dist[i][j] < INF && fw_dist[i][j] > best_dist) {
                    best_i = i; best_dist = fw_dist[i][j];
                }
            }
        }
        cout << "YES\n";
        cout << best_dist << '\n';
        FOR(i,1,n+1) cout << fw_dist[best_i][i] << ' ';
        cout <<'\n';
    } else {
        cout << "NO\n";
    }
}

int main () {
    ios_base::sync_with_stdio(false); cin.tie(NULL);
    run();
}