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

#define FAST ios_base::sync_with_stdio(false); cin.tie(0);
#define pb push_back
#define eb emplace_back
#define ins insert
#define f first
#define s second
#define cbr cerr<<"hi\n"
#define mmst(x, v) memset((x), v, sizeof ((x)))
#define siz(x) ll(x.size())
#define all(x) (x).begin(), (x).end()
#define lbd(x,y) (lower_bound(all(x),y)-x.begin())
#define ubd(x,y) (upper_bound(all(x),y)-x.begin())
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());    //can be used by calling rng() or shuffle(A, A+n, rng)
inline long long rand(long long x, long long y) { return rng() % (y+1-x) + x; } //inclusivesss
string inline to_string(char c) {string s(1,c);return s;} template<typename T> inline T gcd(T a,T b){ return a==0?llabs(b):gcd(b%a,a); }

using ll=long long; 
using ld=long double;
#define FOR(i,s,e) for(ll i=s;i<=ll(e);++i)
#define DEC(i,s,e) for(ll i=s;i>=ll(e);--i)
using pi=pair<ll,ll>; using spi=pair<ll,pi>; using dpi=pair<pi,pi>; 

long long LLINF = 1e18;
int INF = 1e9+1e6;
#define MAXN (206)
ll n, m;
vector<pi> v[MAXN];
bitset<MAXN> vis;
pi A[MAXN], tmp;
int main() {
	FAST
	cin>>n>>m;
	FOR(i,1,m){
		ll a,b,c;
		cin>>a>>b>>c;
		if(c==1){
			v[a].eb(b,0);
			v[b].eb(a,1);
		}else{
			v[a].eb(b,2);
			v[b].eb(a,2);
		}
	}
	vector<ll> ans={-1};
	FOR(s,1,n) {
		FOR(i,1,n) A[i] = pi(0, n-1);
		vis.reset();
		auto bad=[&](ll x) -> bool {
			return A[x].f > A[x].s;
		};
		auto put=[&](ll x,pi y) {
			A[x].f = max(A[x].f, y.f);
			A[x].s = min(A[x].s, y.s);
		};
		function<void(ll)>dfs=[&](ll x){
			if(vis[x]||bad(x)) return;
			vis[x]=1;
			for(auto i:v[x]) {
				if(bad(x)) return;
				if(i.s == 0) {
					// x points to i
					tmp=A[i.f], put(i.f, pi(A[x].f+1, A[x].s+1));
					if(tmp != A[i.f]) vis[i.f]=0;
					dfs(i.f);
				} else if(i.s == 1) {
					tmp=A[i.f], put(i.f, pi(A[x].f-1, A[x].s-1));
					if(tmp != A[i.f]) vis[i.f]=0;
					dfs(i.f);
				} else {
					tmp=A[i.f], put(i.f, pi(A[x].f-1, A[x].s+1));
					if(tmp != A[i.f]) vis[i.f]=0;
					dfs(i.f);
				}
			}
		};
		put(s, pi(0,0)), dfs(s);
		// cerr<<'\n';FOR(i,1,n) {
			// cerr<<A[i].f<<' '<<A[i].s<<'\n';
		// }cerr<<'\n';
		vis.reset();
		bool gg = 0;
		FOR(i,1,n) if(bad(i)) gg = 1;
		if(gg) continue;
		vector<ll> me(n+1, 0);
		function<void(ll,ll)>dfs2=[&](ll x,ll num){
			if(vis[x]) return;
			vis[x]=1;
			if(A[x].f > num || num > A[x].s) gg = 1;
			me[x]=num;
			for(auto i:v[x]) {
				if(i.s == 0) {
					if(vis[i.f] && me[i.f]-1!=me[x]) gg=1;
					dfs2(i.f, num+1);
				} else if(i.s == 1) {
					if(vis[i.f] && me[i.f]+1!=me[x]) gg=1;
					dfs2(i.f, num-1);
				} else {
					if(vis[i.f] && abs(me[i.f]-me[x])!=1) gg=1;
					if(num+1>A[i.f].s) dfs2(i.f,num-1);
					else dfs2(i.f,num+1);
				}
			}
		};
		dfs2(s,0);
		if(gg) continue;
		if(*max_element(all(ans)) < *max_element(all(me))) {
			ans = me;
		}
	}
	if(ans[0]==-1) {
		cout<<"NO\n";
	}else{
		cout<<"YES\n";
		cout<<*max_element(all(ans))<<'\n';
		ans.erase(ans.begin());
		for(auto i:ans) cout<<i<<' '; cout<<'\n';
	}
}
