#include <bits/stdc++.h>
using namespace std;

int dist[205][205];
vector<pair<int, int>> adj[205];
int n, m;
int color[205];

void dfs(int u) {
    for (auto i: adj[u]) {
        if (!color[i.first]) {
            color[i.first] = 3 - color[u];
            dfs(i.first);
        }
    }
}

bool checkBipartite() {
    for (int i = 1; i <= n; i++) {
        if (!color[i]) {
            color[i] = 1;
            dfs(i);
        }
    }
    
    for (int i = 1; i <= n; i++) {
        for (auto j: adj[i]) {
            if (color[i] + color[j.first] != 3) return false;
        }
    }
    
    return true;
}


int main() {
    ios::sync_with_stdio(0);
    cin.tie(NULL);
    
    cin >> n >> m;
    for (int i = 1; i <= m; i++) {
        int u, v, b;
        cin >> u >> v >> b;
        
        if (b == 0) {
            // -1 <= au - av <= 1
            adj[u].push_back({v, 1});
            adj[v].push_back({u, 1});
        }
        else {
            // av = au + 1
            adj[u].push_back({v, 1});
            adj[v].push_back({u, -1});
        }
    }
    
    if (!checkBipartite()) {
        cout << "NO";
        return 0;
    }
    
    const int INF = 1e9;
    
    for (int i = 1; i <= n; i++) {
        for (int j = 1; j <= n; j++) {
            if (i != j) dist[i][j] = INF;
        }
        for (auto j: adj[i]) {
            dist[i][j.first] = min(dist[i][j.first], j.second);
        }
    }
    
    for (int k = 1; k <= n; k++) {
        for (int i = 1; i <= n; i++) {
            for (int j = 1; j <= n; j++) {
                dist[i][j] = min(dist[i][j], dist[i][k] + dist[k][j]);
            }
        }
    }
    
    for (int i = 1; i <= n; i++) {
        if (dist[i][i] < 0) {
            cout << "NO";
            return 0;
        }
    }
    
    int maxDist = -1;
    int u = -1, v = -1;
    
    for (int i = 1; i <= n; i++) {
        for (int j = 1; j <= n; j++) {
            // cout << i << " " << j << " " << dist[i][j] << endl; 
            if (dist[i][j] > maxDist) {
                u = i, v = j;
                maxDist = dist[i][j];
            }
        }
    }
    
    cout << "YES\n";
    cout << dist[u][v] << "\n";
    for (int i = 1; i <= n; i++) {
        cout << dist[u][i] << " ";
    }
    
        
    return 0;
}