Problem: A society can be represented by a connected, undirected graph of n vertices and m edges. The vertices represent people, and an edge (i,j) represents a friendship between people i and j.

In society, the i-th person has an income a_i. A person i is envious of person j if a_j=a_i+1. That is if person j has exactly 1 more unit of income than person i.

The society is called capitalist if for every pair of friends one is envious of the other. For some friendships, you know which friend is envious of the other. For the remaining friendships, you do not know the direction of envy.

The income inequality of society is defined as max_{1 ≤ i ≤ n} a_i - min_{1 ≤ i ≤ n} a_i.

You only know the friendships and not the incomes. If it is impossible for this society to be capitalist with the given knowledge, you should report about it. Otherwise, you should find an assignment of incomes in which the society is capitalist, and the income inequality is maximized.

Input

The first line contains two integers n, m (1≤ n≤ 200, n-1≤ m≤ 2000) — the number of people and friendships, respectively.

The following m lines describe the friendships. Each friendship is described by three integers i, j, b (1≤ i, j≤ n, i≠ j, 0≤ b≤ 1). This denotes that people i and j are friends. If b=1, we require that person i is envious of person j. If b=0, one friend should be envious of the other in either direction.

There is at most one friendship between each pair of people. It is guaranteed that if we consider the friendships as undirected edges, the graph is connected.

Output

Print "YES" if it is possible that the society is capitalist, or "NO" otherwise. You can print characters in any case (upper or lower).

If the answer is "YES", you should print two additional lines. In the first line, print the maximum possible income inequality. On the next line you should print n integers a_1,…, a_n (0≤ a_i≤ 10^6), where a_i denotes the income of the i-th person.

We can prove that if there exists a solution, there exists one where 0≤ a_i≤ 10^6 for all i.

If there exist multiple solutions, print any.

Examples

Input


6 6
1 2 0
3 2 0
2 5 0
6 5 1
6 3 0
2 4 1


Output


YES
3
3 2 1 3 1 0 


Input


4 4
1 2 1
2 3 0
3 4 1
4 1 1


Output


NO


Input


1 0


Output


YES
0
0 

Note

In the first test, we can show that an income inequality greater than 3 is impossible for the given society. In the given answer with income inequality equal to 3:

  * Person 2 is envious of person 1. 
  * Person 3 is envious of person 2. 
  * Person 5 is envious of person 2. 
  * Person 6 is envious of person 5 (the required direction is satisfied). 
  * Person 6 is envious of person 3. 
  * Person 2 is envious of person 4 (the required direction is satisfied). 



In the second test, we can show that there is no way to assign incomes to satisfy all requirements.

Solution (in CPP):

Solution:
#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';
	}
}