// Author : RioTian
// Time : 20/12/21
#include <bits/stdc++.h>
using namespace std;
#define all(s) (s.being(), s.end())
#define rep(i, s, n) for (int i = s; i <= n; ++i)
typedef long long ll;
int n, m, g[200][200];
int a[2000], b[2000], c;

int main(void) {
    memset(g, 0x3f, sizeof(g));
    scanf("%d%d", &n, &m);
    for (int i = 0; i < m; i++) {
        scanf("%d%d%d", &a[i], &b[i], &c);
        g[a[i] - 1][b[i] - 1] = 1;
        if (c == 1)
            g[b[i] - 1][a[i] - 1] = -1;
        else
            g[b[i] - 1][a[i] - 1] = 1;
    }
    for (int i = 0; i < n; i++)
        g[i][i] = 0;
    for (int i = 0; i < n; i++)
        for (int j = 0; j < n; j++)
            for (int k = 0; k < n; k++)
                g[j][k] = min(g[j][k], g[j][i] + g[i][k]);
    int pos = -1, ans = -1;
    for (int i = 0; i < n; i++) {
        if (g[i][i] < 0) {
            printf("NO\n");
            return 0;
        }
        int mx = -n, mn = n;
        for (int j = 0; j < n; j++) {
            mx = max(mx, g[i][j]);
            mn = min(mn, g[i][j]);
        }
        for (int j = 0; j < m; j++)
            if (g[i][a[j] - 1] == g[i][b[j] - 1])
                mx = -n;
        if (ans < mx - mn) {
            ans = mx - mn;
            pos = i;
        }
    }
    if (ans == -1)
        printf("NO\n");
    else {
        printf("YES\n%d\n", ans);
        for (int i = 0; i < n; i++)
            printf("%d%c", g[pos][i] + n, i == n - 1 ? '\n' : ' ');
    }
    return 0;
}