stablegradients/pie-gem5-pairs huggingface dataset:
// Slower C++ solution:
#include<bits/stdc++.h>

using namespace std;

long long d[100005];

int n,m;

bool vis[100005],use[100005];

vector<int>v[100005];

vector<int>e[100005];

bool dfs(int fa)

{

    vis[fa]=true;

    use[fa]=true;

    for(int i=0;i<v[fa].size();i++)

    {

        int y=v[fa][i];

        int z=e[fa][i];

        if(d[y]>d[fa]+z)

        {

            if(vis[y])return true;

            d[y]=d[fa]+z;

            if(dfs(y))return true;

        }

    }

    vis[fa]=false;

    return false;

}

int main()

{

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

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

    {

        d[i]=0x7fffffffffffffff;

    }

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

    {

        int x,y,z;

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

        v[x].push_back(y);

        e[x].push_back(z);

        v[y].push_back(x);

        e[y].push_back(-z);

    }

    bool ok=false;

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

    {

        if(!use[i])

        {

            d[i]=false;

            if(dfs(i))

            {

                ok=true;

            }

        }

    }

    if(ok)printf("No\n");

    else printf("Yes\n");

    return 0;

}

// Faster C++ solution for the same problem (measured speedup: 33.77671609022246x):
#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;

}
// Slower C++ solution:
#include<iostream>

using namespace std;

const int maxn=100005;

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

bool ok=true;

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()

{

    cin>>n>>m;

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

        fa[i]=i;

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

    {

        int l,r,d;

        cin>>l>>r>>d;

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

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

            ok=false;

        if(ll!=rr)

        {

            fa[ll]=rr;

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

        }

    }

    if(ok)

        cout<<"Yes"<<endl;

    else

        cout<<"No"<<endl;

    return 0;

} 

// Faster C++ solution for the same problem (measured speedup: 5.279282682180813x):
#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;

}
// Slower C++ solution:
#include<iostream>

#include<cstdio>

#include<cstring>

#include<algorithm>

#include<cmath>

using namespace std;

#define LL long long

#define R register

int n,m,fa[100005],val[100005],x,y,z;

int find(int x)

{

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

	int par=fa[x];

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

	val[x]+=val[par];

	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++)

	{

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

		int xx=find(x),yy=find(y);

		if(xx==yy)

		{

			if(val[x]-val[y]!=z)

			{

				puts("No");

				return 0;

			}

		}

		else

		{

			fa[xx]=yy;

			val[xx]=val[y]+z-val[x];

		}

	}

	puts("Yes");

	return 0;

}

// Faster C++ solution for the same problem (measured speedup: 5.203890242229033x):
#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;

}
// Slower C++ solution:
#include <bits/stdc++.h>

using namespace std;

#define N 100005

#define M 200005

#define INF 0x3f3f3f3f

#define set(a,v) memset(a,v,sizeof(a))

int n,m,a[N],dst[N];bool ext[N],vs[N],fl[N];

int cntE,hd[N];struct Edge {int v,w,nxt;}e[M<<1];

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

{

	e[++cntE]=(Edge) {v,w,hd[u]};

	hd[u]=cntE;

}

bool SPFA(int u)

{

	vs[u]=fl[u]=1;

	for(int i=hd[u],v,w;~i;i=e[i].nxt)

	{

		v=e[i].v;

		w=e[i].w;

		if(dst[u]+w<dst[v])

		{

			if(vs[v]) return 0;

			dst[v]=dst[u]+w;

			if(!SPFA(v)) return 0;

		}

	}

	vs[u]=0;

	return 1;

}

int main()

{

	set(hd,-1);

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

	for(int i=1,F[3];i<=m;++i)

	{

		scanf("%d %d %d",&F[0],&F[1],&F[2]);

		ext[F[0]]=ext[F[1]]=1;

		addE(F[0],F[1],F[2]);

		addE(F[1],F[0],-F[2]);

	}

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

		if(ext[i] && !fl[i])

		{

			set(dst,INF);

			dst[i]=0;

			if(!SPFA(i))

			{

				puts("No");

				return 0;

			}

		}

	puts("Yes");

	return 0;

}

// Faster C++ solution for the same problem (measured speedup: 9.455734957144776x):
#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;

}
// Slower C++ solution:
# include <bits/stdc++.h>

# define rr register

# define int long long

const int N=400000,M=800000;

struct Edge{

	int to,next,v;

}edge[M];

int head[N],sum;

int dis[N];

bool vst[N];

int n,m;

inline int read(void){

	int res,f=1;

	char c;

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

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

	res=c-48;

	while((c=getchar())>='0'&&c<='9')	

		res=res*10+c-48;

	return res*f;		

}

void print(int x){

	if(x<0)

		putchar('-'),x=-x;

	if(x>9)

		print(x/10);

	putchar(x%10+'0');

	return;	

}

inline void add(int x,int y,int w){

	edge[++sum].to=y;

	edge[sum].next=head[x];

	edge[sum].v=w;

	head[x]=sum;

	return;

}

bool spfa(int i,int w){

//	printf("now visit %d\n",i);

	if(vst[i]&&dis[i]!=w)

		return false;

	if(w>1e9)

		return false;

	dis[i]=w;

	vst[i]=true;

	for(rr int j=head[i];j;j=edge[j].next){

		if(vst[edge[j].to]&&dis[edge[j].to]!=dis[i]+edge[j].v){

			return false;

		}

		if(vst[edge[j].to])

			continue;

		if(!spfa(edge[j].to,dis[i]+edge[j].v))

			return false;

	}

	return true;

}

signed main(void){

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

	for(rr int i=1,x,y,w;i<=m;++i){

		x=read(),y=read(),w=read();

		add(x,y,w),add(y,x,-w);

	}

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

		if(vst[i])

			continue;

		if(!spfa(i,0)){

			puts("No");

			return 0;

		}

	}

	puts("Yes");

	return 0;

}

// Faster C++ solution for the same problem (measured speedup: 5.1846028090128025x):
#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;

}
// Slower C++ solution:
#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

// Faster C++ solution for the same problem (measured speedup: 5.0141025694818655x):
#include <cstdio>

#include <queue>

#define MAXN 100005

#define INF 1e9

using namespace std;

queue <int> q;

struct Edge{

	int next,to,w;

}edge[MAXN<<2];

int n,m,cnt,head[MAXN],tot[MAXN],dis[MAXN];

bool vis[MAXN],flag,checked[MAXN];

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

	edge[++cnt].next=head[u];

	edge[cnt].to=v;

	edge[cnt].w=w;

	head[u]=cnt;

}

bool spfa(int s){

	vis[s]=1;

	dis[s]=0;

	q.push(s);

	while(!q.empty()){

		int u=q.front();

		q.pop();

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

			int v=edge[i].to;

			if(dis[v]==INF){

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

				checked[v]=1;

				if(!vis[v])

					q.push(v);

			} else if(dis[v]!=dis[u]+edge[i].w) return 0;

		}

		vis[u]=0;

	}

	return 1;

}

int main(){

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

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

		dis[i]=INF;

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

		int u,v,w;

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

		add(u,v,w);

		add(v,u,-w);

	}

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

		if(!checked[i]){

			bool ret=spfa(i);

			checked[i]=1;

			if(!ret){

				printf("No\n");

				return 0;

			}

		}

	printf("Yes\n");

	return 0;

}
// Slower C++ solution:
#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;

}

// Faster C++ solution for the same problem (measured speedup: 1.9240999740456377x):
#include <cstdio>

#include <queue>

#define MAXN 100005

#define INF 1e9

using namespace std;

queue <int> q;

struct Edge{

	int next,to,w;

}edge[MAXN<<2];

int n,m,cnt,head[MAXN],tot[MAXN],dis[MAXN];

bool vis[MAXN],flag,checked[MAXN];

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

	edge[++cnt].next=head[u];

	edge[cnt].to=v;

	edge[cnt].w=w;

	head[u]=cnt;

}

bool spfa(int s){

	vis[s]=1;

	dis[s]=0;

	q.push(s);

	while(!q.empty()){

		int u=q.front();

		q.pop();

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

			int v=edge[i].to;

			if(dis[v]==INF){

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

				checked[v]=1;

				if(!vis[v])

					q.push(v);

			} else if(dis[v]!=dis[u]+edge[i].w) return 0;

		}

		vis[u]=0;

	}

	return 1;

}

int main(){

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

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

		dis[i]=INF;

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

		int u,v,w;

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

		add(u,v,w);

		add(v,u,-w);

	}

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

		if(!checked[i]){

			bool ret=spfa(i);

			checked[i]=1;

			if(!ret){

				printf("No\n");

				return 0;

			}

		}

	printf("Yes\n");

	return 0;

}
// Slower C++ solution:
#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;

} 

// Faster C++ solution for the same problem (measured speedup: 2.0313217603651115x):
#include <cstdio>

#include <queue>

#define MAXN 100005

#define INF 1e9

using namespace std;

queue <int> q;

struct Edge{

	int next,to,w;

}edge[MAXN<<2];

int n,m,cnt,head[MAXN],tot[MAXN],dis[MAXN];

bool vis[MAXN],flag,checked[MAXN];

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

	edge[++cnt].next=head[u];

	edge[cnt].to=v;

	edge[cnt].w=w;

	head[u]=cnt;

}

bool spfa(int s){

	vis[s]=1;

	dis[s]=0;

	q.push(s);

	while(!q.empty()){

		int u=q.front();

		q.pop();

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

			int v=edge[i].to;

			if(dis[v]==INF){

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

				checked[v]=1;

				if(!vis[v])

					q.push(v);

			} else if(dis[v]!=dis[u]+edge[i].w) return 0;

		}

		vis[u]=0;

	}

	return 1;

}

int main(){

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

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

		dis[i]=INF;

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

		int u,v,w;

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

		add(u,v,w);

		add(v,u,-w);

	}

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

		if(!checked[i]){

			bool ret=spfa(i);

			checked[i]=1;

			if(!ret){

				printf("No\n");

				return 0;

			}

		}

	printf("Yes\n");

	return 0;

}
// Slower C++ solution:
#include<iostream>

#include<cstdio>

#include<vector>

#include<queue>

#include<algorithm>

using namespace std;

struct node

{

	int to,dis;

	node(){}

	node(int x,int y):to(x),dis(y){}

};

#define INF 1000000000

int n,m,f[100005],b[100005];

vector<node> a[100005];

void spfa(int x)

{

	queue<int> p;

	p.push(x);

	b[x]=1;

	f[x]=0;

	while (!p.empty())

	{

		int v=p.front();

		p.pop();

		for (int i=0;i<a[v].size();i++)

		{

			if (f[a[v][i].to]==INF)

			{

				f[a[v][i].to]=f[v]+a[v][i].dis;

				b[a[v][i].to]=1;

				p.push(a[v][i].to);

			}

			else if (f[a[v][i].to]!=f[v]+a[v][i].dis)

			{

				cout<<"No";

				exit(0);

			}

		}

	}

}

int main()

{

	cin>>n>>m;

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

	{

		f[i]=INF;

	}

	int x,y,z;

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

	{

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

		a[x].push_back(node(y,z));

		a[y].push_back(node(x,-z));

	} 

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

	{

		if (b[i]==0)

		{

			spfa(i);

		}

	}

	cout<<"Yes";

} 

// Faster C++ solution for the same problem (measured speedup: 3.8033975039456025x):
#include <cstdio>

#include <queue>

#define MAXN 100005

#define INF 1e9

using namespace std;

queue <int> q;

struct Edge{

	int next,to,w;

}edge[MAXN<<2];

int n,m,cnt,head[MAXN],tot[MAXN],dis[MAXN];

bool vis[MAXN],flag,checked[MAXN];

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

	edge[++cnt].next=head[u];

	edge[cnt].to=v;

	edge[cnt].w=w;

	head[u]=cnt;

}

bool spfa(int s){

	vis[s]=1;

	dis[s]=0;

	q.push(s);

	while(!q.empty()){

		int u=q.front();

		q.pop();

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

			int v=edge[i].to;

			if(dis[v]==INF){

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

				checked[v]=1;

				if(!vis[v])

					q.push(v);

			} else if(dis[v]!=dis[u]+edge[i].w) return 0;

		}

		vis[u]=0;

	}

	return 1;

}

int main(){

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

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

		dis[i]=INF;

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

		int u,v,w;

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

		add(u,v,w);

		add(v,u,-w);

	}

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

		if(!checked[i]){

			bool ret=spfa(i);

			checked[i]=1;

			if(!ret){

				printf("No\n");

				return 0;

			}

		}

	printf("Yes\n");

	return 0;

}
// Slower C++ solution:
#include <cstdio>

#include <iostream>

#include <algorithm>

#include <cstring>

#include <queue>

using namespace std;



struct ed{

    int to;

	int dis;

	int next;

} edge[400050];

int head[100050];

int edge_tot;



void addedge(int from,int to,int dis)

{

	edge_tot += 1;

    edge[edge_tot].to = to;

    edge[edge_tot].dis = dis;

    edge[edge_tot].next = head[from];

    head[from] = edge_tot;

}



int n,m;

long long dis[100005];

queue<int> q;

bool vis[100050],inq[100050];



bool spfa(int s){

    q.push(s);

    inq[s] = true;

    dis[s] = 0;

    long long curmax = 0;

	long long curmin = 0;

    while(!q.empty()){

        int u = q.front();

        q.pop();

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

            int v = edge[i].to;

            if(dis[v] == 12345678987654321){

                dis[v] = dis[u] + edge[i].dis;

                curmax = max(curmax,dis[v]);

                curmin = min(curmin,dis[v]);

                if(curmax - curmin > 1000000000) return false;

                vis[v] = 1;

                if(!inq[v])

                    q.push(v);

            }

            else if(dis[v] != dis[u] + edge[i].dis)

                return false;

        }

        inq[u] = false;

    }

    return true;

}



int main()

{

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

        dis[i] = 12345678987654321;

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

    int tmp1,tmp2,tmp3;

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

    {

        scanf("%d%d%d",&tmp1,&tmp2,&tmp3);

        addedge(tmp1,tmp2,tmp3);

        addedge(tmp2,tmp1,-tmp3);

    }

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

        if(!vis[i]){

            vis[i] = 1;

			bool l = spfa(i);

            if(!l){

                printf("No\n");

                return 0;

            }

        }

    }

    printf("Yes\n");

    return 0;

}

// Faster C++ solution for the same problem (measured speedup: 1.9276709466389101x):
#include <cstdio>

#include <queue>

#define MAXN 100005

#define INF 1e9

using namespace std;

queue <int> q;

struct Edge{

	int next,to,w;

}edge[MAXN<<2];

int n,m,cnt,head[MAXN],tot[MAXN],dis[MAXN];

bool vis[MAXN],flag,checked[MAXN];

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

	edge[++cnt].next=head[u];

	edge[cnt].to=v;

	edge[cnt].w=w;

	head[u]=cnt;

}

bool spfa(int s){

	vis[s]=1;

	dis[s]=0;

	q.push(s);

	while(!q.empty()){

		int u=q.front();

		q.pop();

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

			int v=edge[i].to;

			if(dis[v]==INF){

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

				checked[v]=1;

				if(!vis[v])

					q.push(v);

			} else if(dis[v]!=dis[u]+edge[i].w) return 0;

		}

		vis[u]=0;

	}

	return 1;

}

int main(){

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

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

		dis[i]=INF;

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

		int u,v,w;

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

		add(u,v,w);

		add(v,u,-w);

	}

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

		if(!checked[i]){

			bool ret=spfa(i);

			checked[i]=1;

			if(!ret){

				printf("No\n");

				return 0;

			}

		}

	printf("Yes\n");

	return 0;

}