stablegradients/pie-gem5-bysrc huggingface dataset:
// Original C++ solution (slower):
#include<bits/stdc++.h>

using namespace std;

int n,m;

struct edge{

	int next;

	int to;

	int w;

}e[4000020];

int head[2000020];

bool dijia(int s);

int dis[2000020];

bool book[2000020],vis[2000020];

int main(){

	scanf("%d %d",&n,&m);

	int u,v,w;

	for(int x=1;x<=m;x++){

		scanf("%d %d %d",&u,&v,&w);

		e[x].to=v;

		e[x].w=w;

		e[x].next=head[u];

		head[u]=x;

		e[x+m].next=head[v];

		e[x+m].to=u;

		e[x+m].w=-w;

		head[v]=x+m;

	}

	for(int x=1;x<=n;x++){

		if(vis[x]){

			continue;

		}

		if(!dijia(x)){

			printf("No");

			return 0;

		}

		else{

			continue;

		}

	}

	printf("Yes");

	return 0;

}

bool dijia(int s){

	dis[s]=0;

	queue<int> q;

	q.push(s);

	book[s]=1;

	while(q.size()){

		int k=q.front();

		q.pop();

		book[k]=0;

		for(int x=head[k];x;x=e[x].next){

			if(!vis[e[x].to]){

				dis[e[x].to]=dis[k]+e[x].w;

				q.push(e[x].to);

				book[e[x].to]=1;

				vis[e[x].to]=1;

			}

			else{

				if(dis[e[x].to]!=dis[k]+e[x].w){

					return false;

				}

			}

		}

	}

	return true;

}

// Optimized solution to the same problem (faster):
// luogu-judger-enable-o2

// SeptEtavioxy

#include<cstdio>

#include<cctype>

#include<cstring>

#include<algorithm>

#include<cmath>

#define re register

#define ll long long

#define il inline

#define rep(i,s,t) for(re int i=(s);i<=(t);i++)

#define rev_rep(i,s,t) for(re int i=(s);i>=(t);i--)

#define each(i,u) for(int i=head[u];i;i=bow[i].nxt)

#define pt(ch) putchar(ch)

#define pti(x) printf("%d",x)

#define ptll(x) printf("%lld",x)

#define file(s) freopen(s".in","r",stdin),freopen(s".out","w",stdout)

using namespace std;

// c_ints

il int ci(){

	re char ch;int f=1;

	while(!isdigit(ch=getchar()))f= ch=='-'?-1:1 ;

	re int x= ch^'0';

	while(isdigit(ch=getchar()))x=(x*10)+(ch^'0');

	return f*x;

}

enum{N=100024};

int fa[N],dis[N];

void fd(int x){

	if( fa[x]==x ) return ;

	fd(fa[x]);

	dis[x]+= dis[fa[x]];

	fa[x]= fa[fa[x]];

}

int main(){

	int n=ci(), m=ci();

	rep(i,1,n) fa[i]= i;

	while( m-- ){

		int l=ci(), r=ci(), d=ci();

		fd(l), fd(r);

		if( fa[l]==fa[r] ){

			if( dis[r]-dis[l]!=d ){

				puts("No");

				return 0;

			}

		}

		else{

			int fl=fa[l], fr=fa[r];

			int x= dis[l]+d-dis[r];

//			printf("%d %d\n",fl,fr);

//			if( x<0 ){

//				puts("No");

//				return 0;

//			}

			dis[fr]= x;

			fa[fr]= fl;

		}

//		printf("fa :");rep(i,1,n) printf("%d ",fa[i]); pt('\n');

//		printf("dis:");rep(i,1,n) printf("%d ",dis[i]); pt('\n');

	}

	puts("Yes");

	return 0;

}

// Fastest known solution for this problem:
// Original C++ solution (slower):
#include<cstdio>

#include<iostream>

#include<cstring>

#include<algorithm>

#include<queue>

int dis[100005],flag[100005],vis[100005],h[100005];

int n,m,cnt;

struct wf{

    int to,nxt,w;

}edge[200005*2];

using namespace std;

queue < int > Q;

void add(int u,int v,int w)

{

    edge[++cnt].to=v;

    edge[cnt].w=w;

    edge[cnt].nxt=h[u];

    h[u]=cnt;

}

bool spfa(int s)

{

    dis[s]=0;

    //vis[s]=1;

    Q.push(s);

    flag[s]=1;

    while(!Q.empty())

    {

        int u=Q.front();

        Q.pop();

        //vis[u]=0;

        for (int j=h[u];j;j=edge[j].nxt)

        {

            int v=edge[j].to;

            if (dis[v]==99999999)

            {

                dis[v]=dis[u]+edge[j].w;

                vis[v]=1;

                if (!flag[v]) Q.push(v);

            }

            else if (dis[v]!=dis[u]+edge[j].w) return false;

        }

        flag[u]=0;

    }

    return true;

}

int main()

{

    scanf("%d%d",&n,&m);

    for (int i=0;i<=n;i++)

	  dis[i]=99999999;

    for (int i=1;i<=m;i++)

    {

        int k,l,q;

        scanf("%d%d%d",&k,&l,&q);

        add(k,l,q);

        add(l,k,-q);

    }

    for (int i=1;i<=n;i++)

    {

        if (!vis[i])

        {

            vis[i]=1;

            if (!spfa(i))

            {

                printf("No");

                return 0;

            }

        }

    }

    printf("Yes");

    //while(1);

    return 0;

}


// Optimized solution to the same problem (faster):
// luogu-judger-enable-o2

// SeptEtavioxy

#include<cstdio>

#include<cctype>

#include<cstring>

#include<algorithm>

#include<cmath>

#define re register

#define ll long long

#define il inline

#define rep(i,s,t) for(re int i=(s);i<=(t);i++)

#define rev_rep(i,s,t) for(re int i=(s);i>=(t);i--)

#define each(i,u) for(int i=head[u];i;i=bow[i].nxt)

#define pt(ch) putchar(ch)

#define pti(x) printf("%d",x)

#define ptll(x) printf("%lld",x)

#define file(s) freopen(s".in","r",stdin),freopen(s".out","w",stdout)

using namespace std;

// c_ints

il int ci(){

	re char ch;int f=1;

	while(!isdigit(ch=getchar()))f= ch=='-'?-1:1 ;

	re int x= ch^'0';

	while(isdigit(ch=getchar()))x=(x*10)+(ch^'0');

	return f*x;

}

enum{N=100024};

int fa[N],dis[N];

void fd(int x){

	if( fa[x]==x ) return ;

	fd(fa[x]);

	dis[x]+= dis[fa[x]];

	fa[x]= fa[fa[x]];

}

int main(){

	int n=ci(), m=ci();

	rep(i,1,n) fa[i]= i;

	while( m-- ){

		int l=ci(), r=ci(), d=ci();

		fd(l), fd(r);

		if( fa[l]==fa[r] ){

			if( dis[r]-dis[l]!=d ){

				puts("No");

				return 0;

			}

		}

		else{

			int fl=fa[l], fr=fa[r];

			int x= dis[l]+d-dis[r];

//			printf("%d %d\n",fl,fr);

//			if( x<0 ){

//				puts("No");

//				return 0;

//			}

			dis[fr]= x;

			fa[fr]= fl;

		}

//		printf("fa :");rep(i,1,n) printf("%d ",fa[i]); pt('\n');

//		printf("dis:");rep(i,1,n) printf("%d ",dis[i]); pt('\n');

	}

	puts("Yes");

	return 0;

}

// Fastest known solution for this problem:
// Original C++ solution (slower):
#include<iostream>  

using namespace std;  

int fa[100500];  

int dis[100500];  

int find(int x) {  

    if(fa[x]==x) return x;  

    int f1=fa[x];  

    int f2=find(fa[x]);  

    fa[x]=f2;  

    dis[x]=dis[x]+dis[f1];  

    return f2;  

}

 

int find_dis(int x) {  

    if(fa[x]==x) return 0;  

    return find_dis(fa[x])+dis[x];

}

   

int main() {  

    int n,m,a,b,d;  

    cin>>n>>m;  

    for(int i=0;i<=n;i++) {  

        fa[i]=i;  

        dis[i]=0;  

    }  

    while(m>0) {

        m--;

        cin>>a>>b>>d;  

        int f1=find(a);  

        int f2=find(b);  

        if(f1==f2) {  

            if(dis[a]+d!=dis[b]) {  

                cout<<"No";  

                return 0;

            }  

        } 

        else{  

            fa[f2]=f1; 

            dis[f2]=find_dis(a)-find_dis(b)+d;  

        }  

    }  

    cout<<"Yes";

}

// Optimized solution to the same problem (faster):
// luogu-judger-enable-o2

// SeptEtavioxy

#include<cstdio>

#include<cctype>

#include<cstring>

#include<algorithm>

#include<cmath>

#define re register

#define ll long long

#define il inline

#define rep(i,s,t) for(re int i=(s);i<=(t);i++)

#define rev_rep(i,s,t) for(re int i=(s);i>=(t);i--)

#define each(i,u) for(int i=head[u];i;i=bow[i].nxt)

#define pt(ch) putchar(ch)

#define pti(x) printf("%d",x)

#define ptll(x) printf("%lld",x)

#define file(s) freopen(s".in","r",stdin),freopen(s".out","w",stdout)

using namespace std;

// c_ints

il int ci(){

	re char ch;int f=1;

	while(!isdigit(ch=getchar()))f= ch=='-'?-1:1 ;

	re int x= ch^'0';

	while(isdigit(ch=getchar()))x=(x*10)+(ch^'0');

	return f*x;

}

enum{N=100024};

int fa[N],dis[N];

void fd(int x){

	if( fa[x]==x ) return ;

	fd(fa[x]);

	dis[x]+= dis[fa[x]];

	fa[x]= fa[fa[x]];

}

int main(){

	int n=ci(), m=ci();

	rep(i,1,n) fa[i]= i;

	while( m-- ){

		int l=ci(), r=ci(), d=ci();

		fd(l), fd(r);

		if( fa[l]==fa[r] ){

			if( dis[r]-dis[l]!=d ){

				puts("No");

				return 0;

			}

		}

		else{

			int fl=fa[l], fr=fa[r];

			int x= dis[l]+d-dis[r];

//			printf("%d %d\n",fl,fr);

//			if( x<0 ){

//				puts("No");

//				return 0;

//			}

			dis[fr]= x;

			fa[fr]= fl;

		}

//		printf("fa :");rep(i,1,n) printf("%d ",fa[i]); pt('\n');

//		printf("dis:");rep(i,1,n) printf("%d ",dis[i]); pt('\n');

	}

	puts("Yes");

	return 0;

}

// Fastest known solution for this problem:
// Original C++ solution (slower):
#include<iostream>

#include<cstdio>

#include<queue>

using namespace std;

inline void read(int&ans)

{

	ans=0;

	register char ch=getchar();

	while(ch<'0' or ch>'9')ch=getchar();

	while(ch>='0' and ch<='9')ans=ans*10+(ch^48),ch=getchar();

}

int fa[100010],n,m,dis[100010];

int find(int x)

{

	if(fa[x]!=x){

		int a=fa[x];fa[x]=find(fa[x]),dis[x]+=dis[a];	

	}

	return fa[x];

}

int main()

{

	read(n),read(m);

	for(int i=1;i<=n;i++)fa[i]=i;

	for(register int i=1;i<=m;i++)

	{

		int l,r,d;

		read(l);read(r);read(d);

		int ll=find(l),rr=find(r);

		if(ll==rr and dis[l]-dis[r]!=d)

		{

			cout<<"No";return 0;

		}

		else if(ll!=rr)

		{

			fa[ll]=rr;

			dis[ll]=dis[r]+d-dis[l];

		}

	}

	cout<<"Yes";

}

// Optimized solution to the same problem (faster):
// luogu-judger-enable-o2

// SeptEtavioxy

#include<cstdio>

#include<cctype>

#include<cstring>

#include<algorithm>

#include<cmath>

#define re register

#define ll long long

#define il inline

#define rep(i,s,t) for(re int i=(s);i<=(t);i++)

#define rev_rep(i,s,t) for(re int i=(s);i>=(t);i--)

#define each(i,u) for(int i=head[u];i;i=bow[i].nxt)

#define pt(ch) putchar(ch)

#define pti(x) printf("%d",x)

#define ptll(x) printf("%lld",x)

#define file(s) freopen(s".in","r",stdin),freopen(s".out","w",stdout)

using namespace std;

// c_ints

il int ci(){

	re char ch;int f=1;

	while(!isdigit(ch=getchar()))f= ch=='-'?-1:1 ;

	re int x= ch^'0';

	while(isdigit(ch=getchar()))x=(x*10)+(ch^'0');

	return f*x;

}

enum{N=100024};

int fa[N],dis[N];

void fd(int x){

	if( fa[x]==x ) return ;

	fd(fa[x]);

	dis[x]+= dis[fa[x]];

	fa[x]= fa[fa[x]];

}

int main(){

	int n=ci(), m=ci();

	rep(i,1,n) fa[i]= i;

	while( m-- ){

		int l=ci(), r=ci(), d=ci();

		fd(l), fd(r);

		if( fa[l]==fa[r] ){

			if( dis[r]-dis[l]!=d ){

				puts("No");

				return 0;

			}

		}

		else{

			int fl=fa[l], fr=fa[r];

			int x= dis[l]+d-dis[r];

//			printf("%d %d\n",fl,fr);

//			if( x<0 ){

//				puts("No");

//				return 0;

//			}

			dis[fr]= x;

			fa[fr]= fl;

		}

//		printf("fa :");rep(i,1,n) printf("%d ",fa[i]); pt('\n');

//		printf("dis:");rep(i,1,n) printf("%d ",dis[i]); pt('\n');

	}

	puts("Yes");

	return 0;

}

// Fastest known solution for this problem:
// Original C++ solution (slower):
#include <iostream>

#include <cstdio>

#include <algorithm>

#define N 400005

#define inf 0x7fffffff

using namespace std;



struct E {int next, to, dis;} e[N];

int n, m, num, flag, cnt;

int h[N], a[N], pos[N], obj[N];

bool vis[N];



int read()

{

	int x = 0; char c = getchar();

	while(c < '0' || c > '9') c = getchar();

	while(c >= '0' && c <= '9') {x = x * 10 + c - '0'; c = getchar();}

	return x;

}



void add(int u, int v, int w)

{

	e[++num].next = h[u];

	e[num].to = v;

	e[num].dis = w;

	h[u] = num;

}



void dfs(int x)

{

	if(flag) return;

	vis[x] = 1;

	for(int i = h[x]; i != 0; i = e[i].next)

	{

		int t = pos[x] + e[i].dis;

		if(pos[e[i].to] == inf) pos[e[i].to] = t, dfs(e[i].to);

		else if(t != pos[e[i].to]) {flag = 1; return;}

	}

}



int main()

{

	cin >> n >> m;

	for(int i = 1; i <= m; i++)

	{

		int a = read(), b = read(), c = read();

		add(a, b, c), add(b, a, -c);

		pos[a] = pos[b] = inf;

		obj[++cnt] = a, obj[++cnt] = b;

	}

	sort(obj + 1, obj + 1 + cnt);

	cnt = unique(obj + 1, obj + 1 + cnt) - obj - 1;

	for(int i = 1; i <= cnt; i++)

		if(!vis[obj[i]])

		{

			flag = 0;

			pos[obj[i]] = 0;

			dfs(obj[i]);

			if(flag) {cout << "No"; return 0;}

		}

	cout << "Yes";

	return 0;

}


// Optimized solution to the same problem (faster):
// luogu-judger-enable-o2

// SeptEtavioxy

#include<cstdio>

#include<cctype>

#include<cstring>

#include<algorithm>

#include<cmath>

#define re register

#define ll long long

#define il inline

#define rep(i,s,t) for(re int i=(s);i<=(t);i++)

#define rev_rep(i,s,t) for(re int i=(s);i>=(t);i--)

#define each(i,u) for(int i=head[u];i;i=bow[i].nxt)

#define pt(ch) putchar(ch)

#define pti(x) printf("%d",x)

#define ptll(x) printf("%lld",x)

#define file(s) freopen(s".in","r",stdin),freopen(s".out","w",stdout)

using namespace std;

// c_ints

il int ci(){

	re char ch;int f=1;

	while(!isdigit(ch=getchar()))f= ch=='-'?-1:1 ;

	re int x= ch^'0';

	while(isdigit(ch=getchar()))x=(x*10)+(ch^'0');

	return f*x;

}

enum{N=100024};

int fa[N],dis[N];

void fd(int x){

	if( fa[x]==x ) return ;

	fd(fa[x]);

	dis[x]+= dis[fa[x]];

	fa[x]= fa[fa[x]];

}

int main(){

	int n=ci(), m=ci();

	rep(i,1,n) fa[i]= i;

	while( m-- ){

		int l=ci(), r=ci(), d=ci();

		fd(l), fd(r);

		if( fa[l]==fa[r] ){

			if( dis[r]-dis[l]!=d ){

				puts("No");

				return 0;

			}

		}

		else{

			int fl=fa[l], fr=fa[r];

			int x= dis[l]+d-dis[r];

//			printf("%d %d\n",fl,fr);

//			if( x<0 ){

//				puts("No");

//				return 0;

//			}

			dis[fr]= x;

			fa[fr]= fl;

		}

//		printf("fa :");rep(i,1,n) printf("%d ",fa[i]); pt('\n');

//		printf("dis:");rep(i,1,n) printf("%d ",dis[i]); pt('\n');

	}

	puts("Yes");

	return 0;

}

// Fastest known solution for this problem:
// Original C++ solution (slower):
#include <bits/stdc++.h>

#define INL inline

#define REG register

#define DB double

#define LDB long double

#define ULL unsigned long long

#define LL long long



#define RPT(i,x,y) for (REG int i=(x);i<(y);i++)

#define DRPT(i,x,y) for (REG int i=(x);i>(y);i--)

#define MST(a,b) memset((a),(b),sizeof(a))

#define MRK() cout<<"Mark"<<endl;

#define WRT(x) cout<<#x<<" = "<<(x)<<endl;



#define MAXN 110000

#define MAXM 10000

#define MOD 998244353

#define INF 0x3f3f3f3f

#define LLINF 0x3f3f3f3f3f3f3f3f

#define EPS 1e-5



#define _ 0

using namespace std;



int pa[MAXN],dis[MAXN];



int getpa(int x)

{

	if (pa[x]==x)

		return x;

	int f=pa[x];

	pa[x]=getpa(pa[x]);

	dis[x]+=dis[f];

	return pa[x];

}



bool merge(int x,int y,int d)

{

	int px=getpa(x),py=getpa(y);

	if (px==py && d!=dis[x]-dis[y])

		return false;

	pa[px]=py;

	dis[px]=d+dis[y]-dis[x];

	return true;

}



int n,m;



int main()

{

	int x,y,z;

	cin>>n>>m;

	RPT(i,1,n+1)

		pa[i]=i;

	RPT(i,0,m)

	{

		scanf("%d%d%d",&x,&y,&z);

		if (!merge(y,x,z))

		{

			cout<<"No";

			return 0;

		}

		/*

		cout<<endl<<"--------------\n\n";

		RPT(i,1,n+1)

		{

			cout<<pa[i]<<' '<<dis[i]<<endl;

		}

		*/

	}

	cout<<"Yes";

	return ~~(0^_^0);

}




// Optimized solution to the same problem (faster):
// luogu-judger-enable-o2

// SeptEtavioxy

#include<cstdio>

#include<cctype>

#include<cstring>

#include<algorithm>

#include<cmath>

#define re register

#define ll long long

#define il inline

#define rep(i,s,t) for(re int i=(s);i<=(t);i++)

#define rev_rep(i,s,t) for(re int i=(s);i>=(t);i--)

#define each(i,u) for(int i=head[u];i;i=bow[i].nxt)

#define pt(ch) putchar(ch)

#define pti(x) printf("%d",x)

#define ptll(x) printf("%lld",x)

#define file(s) freopen(s".in","r",stdin),freopen(s".out","w",stdout)

using namespace std;

// c_ints

il int ci(){

	re char ch;int f=1;

	while(!isdigit(ch=getchar()))f= ch=='-'?-1:1 ;

	re int x= ch^'0';

	while(isdigit(ch=getchar()))x=(x*10)+(ch^'0');

	return f*x;

}

enum{N=100024};

int fa[N],dis[N];

void fd(int x){

	if( fa[x]==x ) return ;

	fd(fa[x]);

	dis[x]+= dis[fa[x]];

	fa[x]= fa[fa[x]];

}

int main(){

	int n=ci(), m=ci();

	rep(i,1,n) fa[i]= i;

	while( m-- ){

		int l=ci(), r=ci(), d=ci();

		fd(l), fd(r);

		if( fa[l]==fa[r] ){

			if( dis[r]-dis[l]!=d ){

				puts("No");

				return 0;

			}

		}

		else{

			int fl=fa[l], fr=fa[r];

			int x= dis[l]+d-dis[r];

//			printf("%d %d\n",fl,fr);

//			if( x<0 ){

//				puts("No");

//				return 0;

//			}

			dis[fr]= x;

			fa[fr]= fl;

		}

//		printf("fa :");rep(i,1,n) printf("%d ",fa[i]); pt('\n');

//		printf("dis:");rep(i,1,n) printf("%d ",dis[i]); pt('\n');

	}

	puts("Yes");

	return 0;

}

// Fastest known solution for this problem:
// Original C++ solution (slower):
#ifndef chafen

#define chafen



# include <cstdio>

# include <iostream>

# include <cstring>

# include <queue>

# pragma GCC optimize(2)

# define N 300000

# define INF 0x7f7f7f7f //0x7fffffff

# define _cin std::ios::sync_with_stdio(false)

# define rg register

# define il inline

struct edge{

    int next;

    int to;

    int w;

}e[(N+1)<<1];

int head[N+1];

int book[N+1];

int vis[N+1];

int dis[N+1];

int n,m;

using namespace std;

//template <class A> il bool SPFA(A s);

bool SPFA(int s);

int main()

{

    _cin;

    rg int edge_sum=0;

    rg int u,v,w;

    cin>>n>>m;

    for(rg int i = 1;i<=m;i++){

        cin>>u>>v>>w;

        //edge_sum++;

        e[i].next=head[u];

        e[i].to=v;

        e[i].w=w;

        head[u]=i;

        

        //edge_sum++;

        e[i+m].next=head[v];

        e[i+m].to=u;

        e[i+m].w=-w;

        head[v]=i+m;

    }

    memset(dis,0x7f,sizeof(dis));

    memset(vis,0,sizeof(vis));

    memset(book,0,sizeof(book));

    for(rg int i = 1;i<=n;i++){

        if(!vis[i]){

            vis[i]=1;

            if(!SPFA(i)){

                cout<<"No"<<endl;

                return 0;

            }

        }

    }

    cout<<"Yes"<<endl;

    return 0;

}

//template <class A> il bool SPFA(A s)

il bool SPFA(int s)

{

    queue <int> q;

    dis[s]=0;

    q.push(s);book[s]=1;

    while(q.size()>0){

        rg int k=q.front();q.pop();

        book[k]=0;

        for(rg int i = head[k];i;i=e[i].next){

            rg int tt=e[i].to;

            if(dis[k]<INF && dis[tt]<INF && dis[tt]!=dis[k]+e[i].w) return false;

			else if(dis[k]<INF && dis[tt] == INF){

                dis[tt]=dis[k]+e[i].w;

                if(book[tt] == false) {q.push(tt);book[tt]=1;}

                vis[tt]=1;

            }

        }

    }

    return true;

}



#endif

// Optimized solution to the same problem (faster):
#include<cstdio>

int n,m,fa[100005],dis[100005];

bool ok=1;

int find(int x){

    if(fa[x]!=x){

        int nf=fa[x];

        fa[x]=find(fa[x]);

        dis[x]+=dis[nf];

    }

    return fa[x];

}

int main(){

    scanf("%d%d",&n,&m);

    for(int i=1;i<=n;i++)

        fa[i]=i;

    for(int i=1;i<=m;i++){

        int l,r,d;

        scanf("%d%d%d",&l,&r,&d);

        int rl=find(l),rr=find(r);

        if(rl==rr&&dis[l]-dis[r]!=d)

            ok=0;

        if(rl!=rr){

            fa[rl]=rr;

            dis[rl]=d+dis[r]-dis[l];

        }

    }

    if(ok)printf("Yes");

    else printf("No");

    return 0;

} 

// Fastest known solution for this problem:
// Original C++ solution (slower):
#include <iostream>

#include <cstdio>

#include <cstring>

#include <algorithm>

#include <queue>

#include <vector>

#include <cmath>

#define LL long long

using namespace std;

const int MOD=1e9+7;

const int INF=0x3f3f3f3f;

const int M=200100;

const int N=100100;

inline void read(int &x){

	x=0;int mm=1; char ch=getchar();

	while((ch>'9'||ch<'0')&&ch!='-') ch=getchar();

	if(ch=='-') mm=-1,ch=getchar();

	while(ch>='0'&&ch<='9') x=(x<<3)+(x<<1)+ch-'0',ch=getchar();

	x=x*mm;

}

inline void read(LL &x){

	x=0;LL mm=1; char ch=getchar();

	while((ch>'9'||ch<'0')&&ch!='-') ch=getchar();

	if(ch=='-') mm=-1,ch=getchar();

	while(ch>='0'&&ch<='9') x=(x<<3)+(x<<1)+ch-'0',ch=getchar();

	x=x*mm;

}

struct Edge{

	int nxt;

	int v,w;

}edge[M<<2];

int head[N],tot;

void add(int u,int v,int w){

	edge[++tot].nxt=head[u];

	edge[tot].v=v;

	edge[tot].w=w;

	head[u]=tot;

}

int n,m;

int dist[N];

bool visited[N],inque[N];

queue <int> q;

bool SPFA(int beginn){

	visited[beginn]=true;

	inque[beginn]=true;

	dist[beginn]=0;

	q.push(beginn);

	int maxx=0,minn=0;

	while(!q.empty()){

		int u=q.front();q.pop();

		inque[u]=false;

		for(int i=head[u];i;i=edge[i].nxt){

			Edge &e=edge[i];

			if(dist[e.v]<INF){

				if(dist[e.v]!=e.w+dist[u]){

					return false;

				}

			}else{

				dist[e.v]=e.w+dist[u];

				maxx=max(maxx,dist[e.v]);

				minn=min(minn,dist[e.v]);

				if(maxx-minn>INF) return false;

				visited[e.v]=true;

				if(!inque[e.v]){

					inque[e.v]=true;

					q.push(e.v);

				}

			}

		}

	}

	return true;

}

int main(){

	read(n),read(m);

	memset(head,0,sizeof(head));

	for(int i=1;i<=m;i++){

		int u,v,w;

		read(u),read(v),read(w);

		add(u,v,w);

		add(v,u,-w);

	}

	memset(dist,INF,sizeof(dist));

	for(int i=1;i<=n;i++){

		if(!visited[i])

			if(!SPFA(i)){

				printf("No");

				return 0;

			}

	}

	printf("Yes");

	return 0;

}

// Optimized solution to the same problem (faster):
#include<cstdio>

int n,m,fa[100005],dis[100005];

bool ok=1;

int find(int x){

    if(fa[x]!=x){

        int nf=fa[x];

        fa[x]=find(fa[x]);

        dis[x]+=dis[nf];

    }

    return fa[x];

}

int main(){

    scanf("%d%d",&n,&m);

    for(int i=1;i<=n;i++)

        fa[i]=i;

    for(int i=1;i<=m;i++){

        int l,r,d;

        scanf("%d%d%d",&l,&r,&d);

        int rl=find(l),rr=find(r);

        if(rl==rr&&dis[l]-dis[r]!=d)

            ok=0;

        if(rl!=rr){

            fa[rl]=rr;

            dis[rl]=d+dis[r]-dis[l];

        }

    }

    if(ok)printf("Yes");

    else printf("No");

    return 0;

} 

// Fastest known solution for this problem:
// Original C++ solution (slower):
#include <bits/stdc++.h>

using namespace std;

#define Rint register int

typedef long long ll;

ll hd[100010],nxt[400010],eds[400010],val[400010],et=0;

inline ll read(){

	ll x=0,w=1;char c=getchar();

	while(!isdigit(c)){

		if(c=='-')w=-1;

		c=getchar();

	}

	while(isdigit(c)){

		x=(x<<1)+(x<<3)+c-'0';

		c=getchar();

	}

	return x*w;

}

inline void ad(ll u,ll v,ll w){

	eds[++et]=v;

	val[et]=w;

	nxt[et]=hd[u];

	hd[u]=et;

}

ll n,m;

ll dis[100010];

bool vstd[100010];

bool inq[100010];

queue<ll> q;

ll spfa(ll u){

	memset(vstd,0,sizeof(vstd));

	ll minn=0,maxx=0;

	dis[u]=0;

	while(!q.empty())q.pop();

	q.push(u);

	inq[u]=true;

	while(!q.empty()){

		ll now=q.front();

		q.pop();

		inq[now]=false;

		for (Rint i=hd[now];i;i=nxt[i])

			if (dis[eds[i]]>dis[now]+val[i]){

				if(vstd[eds[i]])return -1;

				vstd[eds[i]]=true;

				dis[eds[i]]=dis[now]+val[i];

				maxx=max(maxx,dis[eds[i]]);

				minn=min(minn,dis[eds[i]]);

				if(!inq[eds[i]]){

					inq[eds[i]]=true;

					q.push(eds[i]);

				}

			}

	}

	return maxx-minn;

}

int main(){

	//freopen("line.in","r",stdin);

//	freopen("line.out","w",stdout);

	n=read(),m=read();

	ll t1,t2,t3;

	for (Rint i=1;i<=m;i++){

		t1=read(),t2=read(),t3=read();

		ad(t1,t2,t3);

		ad(t2,t1,-t3);

	}

	memset(dis,0x3f,sizeof(dis));

	ll maxx=0;

	for (Rint i=1;i<=n;i++)

		if (dis[i]==0x3f3f3f3f3f3f3f3f){

			ll tmp=spfa(i);

			if (tmp==-1){

				puts("No");

				return 0;

			}

			maxx=max(maxx,tmp);

		}

	puts("Yes");

	return 0;

} 

// Optimized solution to the same problem (faster):
#include<cstdio>

int n,m,fa[100005],dis[100005];

bool ok=1;

int find(int x){

    if(fa[x]!=x){

        int nf=fa[x];

        fa[x]=find(fa[x]);

        dis[x]+=dis[nf];

    }

    return fa[x];

}

int main(){

    scanf("%d%d",&n,&m);

    for(int i=1;i<=n;i++)

        fa[i]=i;

    for(int i=1;i<=m;i++){

        int l,r,d;

        scanf("%d%d%d",&l,&r,&d);

        int rl=find(l),rr=find(r);

        if(rl==rr&&dis[l]-dis[r]!=d)

            ok=0;

        if(rl!=rr){

            fa[rl]=rr;

            dis[rl]=d+dis[r]-dis[l];

        }

    }

    if(ok)printf("Yes");

    else printf("No");

    return 0;

} 

// Fastest known solution for this problem: