#include<bits/stdc++.h>
using namespace std;
const int maxn = 200 + 10;
const int maxm = 3000 + 10;
const int INF = 0x3f3f3f3f;
int u[maxm],v[maxm];
int dp[maxn][maxn];
int n,m;

int main(){
    scanf("%d%d",&n,&m);
    memset(dp,INF,sizeof(dp));
    for(int i = 1 ; i <= n ; i++ )
        dp[i][i] = 0;
    for(int i = 1 ; i <= m ; i++ ){
        int b;
        scanf("%d%d%d",&u[i],&v[i],&b);
        dp[u[i]][v[i]] = 1;
        dp[v[i]][u[i]] = (b ? -1 : 1);
    }
    for(int k = 1 ; k <= n ; k++ ){
        for(int i = 1 ; i <= n ; i++ ){
            for(int j = 1 ; j <= n ; j++ ){
                if(dp[i][k] != INF && dp[k][j] != INF && dp[i][j] > dp[i][k] + dp[k][j]){
                    dp[i][j] = dp[i][k] + dp[k][j];
                    // if(dp[i][j] <= -2 * n){
                    //     printf("NO\n");
                    //     return 0;
                    // }
                }
            }
        }
    }
    pair<int,int> bes = make_pair(-1,1);
    for(int i = 1 ; i <= n ; i++ ){
        if(dp[i][i] < 0){
            printf("NO\n");
            return 0;
        }
        for(int j = 1 ; j <= n ; j++ ){
            bes = max(bes,make_pair(dp[i][j],i));
        }
    }
    int s = bes.second;
    for(int i = 1 ; i <= m ; i++ ){
        if(dp[s][u[i]] == dp[s][v[i]]){
            printf("NO\n");
            return 0;
        }
    }
    printf("YES\n%d\n", bes.first);
    for(int i = 1 ; i <= n ; i++ )
        printf("%d%c", dp[s][i],i == n ? '\n' : ' ');
    return 0;
}