#include<algorithm>
#include<cstdio>
#include<iostream>
#include<cstring>
#include<cmath>
#include<map>
#include<queue>
#include<set>
#include<sstream>
#include<stack>
#include<string>
#include<vector>
using namespace std;
#define MP make_pair
typedef long long LL;
#define F first
#define S second

int n,m;
vector<pair<int,int> > v[100100];
map<LL,int> mp[100100];
bool vis[100100];

int D(int a,int b){
	int x=min(a,b);
	int y=max(a,b);
	return x*100000+y;
}

void dfs(int x){
	vis[x]=1;
	for(int i=0;i<v[x].size();i++){
		if(!vis[v[x][i].F]){
			if(mp[D(x,v[x][i].F)] != mp.end()){
				if(mp[D(x,v[x][i].F)]!=v[x][i].S && mp[D(x,v[x][i].F)]!=0){
					cout<<"NO"<<endl;
					exit(0);
				}else{
					mp[D(x,v[x][i].F)]=v[x][i].S;
					
				}
			}
		}
	}
}

int main(){
	ios::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	cin>>n>>m;
	int a,b,c;
	for(int i=1;i<=m;i++){
		cin>>a>>b>>c;
		v[a].push_back(MP(b,c));
		v[b].push_back(MP(a,c));
	}
	dfs(a);
	cout<<"Yes"<<endl;
	return 0;
}