#include<iostream>
#include<cstdio>
#include<set>
#include<map>
#include<vector>
#include<cstring>
#include<string>
#include<cstdlib>
#include<algorithm>
#include<queue>
#include<iomanip>
#include<stack>
#include<cmath>

 
using namespace std;
 
 
#ifndef POJ
    #define Cpp11
#endif
 
#ifdef Cpp11
    #define _for(i,a,b) for(auto i = (a);i<(b);++i)
    #define _rep(i,a,b) for(auto i = (a);i<=(b);++i)
    #define _dep(i,a,b) for(auto i = (a);i>=(b);--i)
    #define mt(a,b,c) make_tuple(a,b,c) 
    #include<ctime>
    #include<random>
    #include<chrono>
    #include<limits>
    #include<complex>
    #include<unordered_set>
    #include<unordered_map>
    #include<cassert>
    #include<functional>
    #include<bitset>
    #define IO ios::sync_with_stdio(false);cout.tie(nullptr);cin.tie(nullptr);
#endif
 
#ifndef Cpp11
    #define _for(i,a,b) for(int i = (a);i<(b);++i)
    #define _rep(i,a,b) for(int i = (a);i<=(b);++i)
    #define _dep(i,a,b) for(int i = (a);i>=(b);--i)
    #define IO ios::sync_with_stdio(false);cout.tie(NULL);cin.tie(NULL);
#endif
 
 
using namespace std;


 
#define fr first
#define sc second
#define all(x) (x).begin(),(x).end()
#define pb push_back
#define pob pop_back
#define pf push_front
#define pof pop_front
#define sci(x) scanf("%d",&(x))
#define scl(x) scanf("%lld",&(x))
#define debugline fprintf(stderr,"-----------------------\n");
#define szint(x) ((int)(x).size())

 
#ifdef I128IO
typedef __int128 SPLL;
char buff[200];
template<typename T>
void read(T& o)
{
    o = 0;
    scanf("%s",buff);
    //printf("%s\n",buff);
    T f = 1;
    int i = 0;
 
    if(buff[0]=='-')i++,f = -1;
    for(;buff[i];++i)
    {
        o*=10,o+=buff[i]-'0';
    }
    o*=f;
}
 
template<typename T>
void write(T o)
{
    int len = 0;
    buff[0] = '0';
    if(o==0)
    {
        putchar('0');
        return;
    }
    int f = 1;
    if(o<0) f = -1;
    o*=f;
    for(;o;o/=10) buff[len++] = o%10+'0';
    if(f==-1) buff[len++] = '-';
    reverse(buff,buff+len);
    buff[len++] ='\0';
    printf("%s",buff);
}
#endif
 
#ifdef FIO
char buff[100];
template<typename T>
void read(T& o)
{
    o = 0;
    scanf("%s",buff);
    //printf("%s\n",buff);
    T f = 1;
    int i = 0;
    if(buff[0]=='-')i++,f = -1;
    for(;buff[i];++i)
    {
        o*=10,o+=buff[i]-'0';
    }
    o*=f;
}
template<typename T>
void write(T o)
{
    int len = 0;
    buff[0] = '0';
    if(o==0)
    {
        putchar('0');
        return;
    }
    int f = 1;
    if(o<0) f = -1;
    o*=f;
    for(;o;o/=10) buff[len++] = o%10+'0';
    if(f==-1) buff[len++] = '-';
    reverse(buff,buff+len);
    buff[len++] ='\0';
    printf("%s",buff);
}
#endif

#define OIreader


#ifdef OIreader
inline int read(){
    char ch; bool sign=0; int res=0;
    while(!isdigit(ch=getchar()))if(ch=='-')sign=1;
    while(isdigit(ch))res=res*10+(ch^48),ch=getchar();
    if(sign)return -res; else return res;
}
#endif

#ifdef _Random_
    mt19937 __MT(chrono::system_clock::now().time_since_epoch().count());
#endif
 
#ifndef BigNumber
    typedef unsigned long long uLL;
    typedef long long LL;
    typedef long long ll;
    typedef pair<LL,LL> pLL;
    typedef vector<LL> vL;
    typedef vector<vL> vLL;
#endif


// Sorry,I must be yellow!

typedef vector<int> vi;
typedef vector<vi> vii;
typedef vector<vii> viii;
typedef pair<int,int> pii;


const int maxn = 200+10;
const int inf = 1e9;
const int maxm = 5000000+10;
const int base = 2000000+10;
const int apsz = 26;
const LL mod = 998244353;//for triple NTT 469762049,998244353,1004535809


int n,m;
int g[maxn][maxn],co[maxn];

inline int dfs(int u,int c)
{
    co[u] = c;
    _rep(i,1,n)
    {
        if(i==u||g[u][i]>=inf)continue;
        if(!co[i])
        {
            if(!dfs(i,3-c))return 0;
        }
        else if(co[i]==c) return 0;
    }
    return 1;
}


inline int init()
{
    _rep(i,1,n)
    {
        if(!co[i]) 
        {
            if(!dfs(i,1))return 0;
        }
    }
    vi d(n+1,0),cnt(n+1,0),inq(n+1,0);
    queue<int> q;
    _rep(i,1,n) q.push(i);

    for(;!q.empty();)
    {
        int u = q.front();q.pop();
        inq[u] = 0;
        _rep(v,1,n)
        {
            if(g[u][v]>=inf)continue;
            if(d[v]>d[u]+g[u][v])
            {
                d[v] = d[u]+g[u][v];
                if(!inq[v])
                {
                    q.push(v);
                    inq[v] = 1;
                    if(++cnt[v]>=n)return 0;
                }
            }
        }
    }
    return 1;
}
int dp[maxn][maxn];

inline int solve()
{
    _rep(i,1,n)_rep(j,1,n) dp[i][j] = g[i][j];
    if(!init())return 0;
    _rep(o,1,n)
    {
        _rep(u,1,n)
        {
            _rep(v,1,n)
            {
                dp[u][v] = min(dp[u][v],dp[u][o]+dp[o][v]);
            }
        }
    }
    int u(1),v(1);
    _rep(i,1,n)
    {
        _rep(j,1,n)
        {
            if(dp[i][j]<inf)
            {
                if(dp[i][j]>dp[u][v]) u = i,v = j;
            }
        }
    }
    printf("YES\n%d\n",dp[u][v]);
    _rep(i,1,n)
    {
        printf("%d ",5000+dp[u][i]);
    }
    return 1;
}



int main(void)
{
    sci(n),sci(m);
    _rep(i,1,n)_rep(j,i+1,n)g[i][j] =  g[j][i] = inf;
    _rep(i,1,m)
    {
        int u,v,b;
        scanf("%d%d%d",&u,&v,&b);
        if(g[v][u]==-1)continue;
        if(b) 
        {
            if(g[u][v]==-1)
            {
                return puts("-1"),0;
            }
            g[u][v] = 1,g[v][u] = -1;

        }
        else g[u][v] = g[v][u] = 1;
    }
    solve()?puts(""):puts("NO");
    return 0;
}