#include <bits/stdc++.h>
using namespace std;
#define int long long
typedef pair<int,int> pi;
#define f first
#define s second
#define FAST ios_base::sync_with_stdio(0); cin.tie(0);
#define all(x) x.begin(),x.end()
typedef pair<int, pi> pii;

const int maxn = 210;
const int mod = 998244353;
const int INF = INT_MAX/2;

int n,e;
int A[maxn][maxn];
int dist[maxn][maxn];
vector <pii> edges;
//dist.

int32_t main() {
	FAST
	cin >> n >> e;
	
	for (int i =1;i<=n;i++) {
		for (int j=1;j<=n;j++) {
			if (i == j) continue;
			dist[i][j] = INF;
		}
	}

	for (int i =0;i<e;i++) {
		int a,b,w; cin >> a >> b >> w;
		if (w == 0) {
			dist[a][b] = 1;
			dist[b][a] = 1;
		} else {
			dist[a][b] = 1;
			dist[b][a] = -1;
		}
		edges.push_back(pii(w,pi(a,b)));
	}

	for (int k =1;k<=n;k++) {
		for (int i =1;i<=n;i++) {
			for (int j =1;j<=n;j++) {
				dist[i][j] = min(dist[i][j], dist[i][k] + dist[k][j]);
			}
		}
	}
	
	//trying to find diameter
	pair <int,int> best = {-1,1};
	for (int i =1;i<=n;i++) {
		if (dist[i][i] < 0) { //negative cycle.
			cout << "NO";
			return 0;
		}
		for (int j =1;j<=n;j++) {
			best = max(best, {dist[i][j], i});
		}
	}
	
	int source = best.s;
	for (auto i : edges) {
		//if parity of distances are the same, then it's not bipartite. Impossible.
		if ((dist[source][i.s.f] % 2) == (dist[source][i.s.s]) % 2) {
			cout << "NO";
			return 0;
		}
	}
	cout << "YES\n";
	cout << best.f << "\n";
	for (int i =1;i<=n;i++) {
		cout << dist[source][i] << " ";
	}
}






