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

typedef long long ll;

typedef pair<int, int> pii;
typedef pair<ll, ll> pll;

#define fr first
#define sc second

const int N = 205, M=2005;
int u[M], v[M];
//vector<pii> e[N];
int dis[N][N];


int main(){
    ios_base::sync_with_stdio(0);
    cin.tie(0); cout.tie(0);
    #ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
    #endif

	int n, m; cin>>n>>m;
    for(int i=0; i<n; i++){
        for(int j=0; j<n; j++){
            if(i==j) continue;
            dis[i][j]=2e4;
        }
    }

    for(int i=0; i<m; i++){
        cin>>u[i]>>v[i];
        u[i]--, v[i]--;
        int op; cin>>op;
        dis[u[i]][v[i]]=1;
        dis[v[i]][u[i]]=(op==1? -1 : 1);
        /*if(op==0){
            e[u].push_back(make_pair(v, 1));
            e[v].push_back(make_pair(u, 1));
            dis[u][v]=dis[v][u]=1;
        }
        else if(op==1){
            e[u].push_back(make_pair(v, 1));
            e[v].push_back(make_pair(u, -1));
            dis[u][v]=1;
            dis[v][u]=-1;
        }*/
    }
    for(int k=0; k<n; k++) {
        for(int i=0; i<n; i++) {
            for(int j=0; j<n; j++) {
                if(dis[i][k] != 2e4 && dis[k][j] != 2e4 && dis[i][k] + dis[k][j] < dis[i][j]) {
                    dis[i][j] = dis[i][k] + dis[k][j];
                }
            }
        }
    }

    pii sol={-1, 1};
    for(int i=0; i<n; i++){
        if(dis[i][i]<0){
            cout<<"NO\n";
            return 0;
        }
        for(int j=0; j<n; j++)
            sol=max(sol, make_pair(dis[i][j], i));
    }

    int st=sol.sc;
    for(int i=0; i<m; i++){
        if(dis[st][u[i]]==dis[st][v[i]]){
            cout<<"NO\n";
            return 0;
        }
    }
    cout<<"YES\n";
    cout<<sol.fr<<'\n';
    for(int i=0; i<n; i++){
        cout<<dis[st][i]<<" \n"[i==n-1];
    }

    return 0;
}
