stablegradients/pie-gem5-bysrc huggingface dataset:
// Original C++ solution (slower):
#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";

} 

// 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<algorithm>

using namespace std;

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

int find(int x)

{

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

	int y=find(fa[x]);

	f[x]+=f[fa[x]];

	fa[x]=y;

	return fa[x];

}

void merge(int x,int y,int z)

{

	int fx=find(x),fy=find(y);

	if (fx==fy)

	{

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

		{

			cout<<"No";

			exit(0);

		}

		return; 

	}

	fa[fy]=fx;

	f[fy]+=f[x]+z-f[y];

}

int main()

{

	cin>>n>>m;

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

	{

		fa[i]=i;

		f[i]=0;

	}

	int x,y,z;

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

	{

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

		if (z<0)

		{

			int t=x;

			x=y;

			y=t;

			z=-z;

		}

		merge(x,y,z);

//		for (int i=1;i<=n;i++) cout<<fa[i]<<' '<<f[i]<<'\n';

//		cout<<'\n';

	}

	cout<<"Yes";

//	int ans=0;

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

//	{

//		find(i);

//		ans=max(f[i],ans);

//	}

//	cout<<ans;

} 

// 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 maxn 100010

#define maxm 200010

#define INF 0x7f7f7f7f



inline void read(int &x) {

  x = 0;

  bool sign = false;

  char ch = 0;

  while (!isdigit(ch)) { sign |= (ch == '-'); ch = getchar(); }

  while (isdigit(ch)) { x = x * 10 + (ch ^ 48); ch = getchar(); }

  x = sign ? -x : x;

}



int n, m, Li, Ri, Di, ans = 0;

int fa[maxm], r[maxn];



inline int get(int x) {

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

  else {

    int l = get(fa[x]);

    r[x] = r[fa[x]] + r[x];

    fa[x] = l;

    return l;

  }

}



int main() {

  read(n); read(m);

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

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

    read(Li); read(Ri); read(Di);

    int fl = get(Li), dl = r[Li];

    int fr = get(Ri), dr = r[Ri];

    if (fl == fr) {

      if (dl + Di != dr) {

        printf("No");

        return 0;

      }

    } else {

      fa[fr] = fl;

      r[fr] = dl + Di - dr;

    }

  }

  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<iostream>

#include<cstdio>

using namespace std;

const int maxn=5*1e5+7;

const int INF=1e9+7;

int cur,E,V,head[maxn],dist[maxn];

int A,B,C;

bool vis[maxn];

struct edge{

	int to,nex,cost;

	edge(){}

	edge(int _a,int _b,int _c){

		to=_a,nex=_b,cost=_c;

	}	

}eg[maxn];

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

	eg[++cur]=edge(v,head[u],w);

	head[u]=cur;

}

bool SPFA(int x){

	vis[x]=true;

	for(int i=head[x];i;i=eg[i].nex){

		int v=eg[i].to;

		if(dist[v]>dist[x]+eg[i].cost){

			dist[v]=dist[x]+eg[i].cost;

			if(vis[v]||!SPFA(v)){

				return false;

			}

		}

	}

	vis[x]=false;

	return true;

}

int main(){

	cin>>V>>E;

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

		cin>>A>>B>>C;

		add_eg(A,B,C);

		add_eg(B,A,-C);

	}

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

		dist[i]=0;

		if(!SPFA(i)){

			cout<<"No"<<endl;

			return 0;

		}

	}

	cout<<"Yes"<<endl;

	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 <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;

}

// 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;

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;

}

// 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 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;

}

// 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>

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;

} 

// 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<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;

}

// 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>

# 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;

}

// 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;



using ll = long long int;



const int MAX_N = (int)1e5 + 5;



struct rd {int v, cost;};



int n, m;



int l, r, d;

ll grid[MAX_N];

bool visited[MAX_N];

vector<vector<rd>> graph(MAX_N);

vector<int> nodes;



int main(void){

  // Here your code !

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

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

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

    rd tokenl;

    tokenl.v = r;

    tokenl.cost = d;

    graph[l].push_back(tokenl);

    rd tokenr;

    tokenr.v = l;

    tokenr.cost = -1 * d;

    graph[r].push_back(tokenr);

    nodes.push_back(l);

    nodes.push_back(r);

  }

  fill(visited, visited + MAX_N, false);



  sort(nodes.begin(), nodes.end());

  nodes.erase(unique(nodes.begin(), nodes.end()), nodes.end());



  stack<int> stk;

  for (int i = 0; i < nodes.size(); ++i) {

    int cnode = nodes[i];

    if (visited[cnode]) continue;

    grid[cnode] = 0;

    visited[cnode] = true;



    stk.push(cnode);

    while (!stk.empty()) {

      int tnode = stk.top();

      stk.pop();

      vector<rd> cgraph = graph[tnode];



      for (int j = 0; j < cgraph.size(); ++j) {

        if (visited[cgraph[j].v]) {

            if (grid[tnode] + cgraph[j].cost != grid[cgraph[j].v]) {

              printf("No\n");

              return 0;

            }

            else {continue;}

        }

        grid[cgraph[j].v] = grid[tnode] + cgraph[j].cost;

        stk.push(cgraph[j].v);

        visited[cgraph[j].v] = true;

      }

    }

  }

  printf("Yes\n");



  return 0;

}

// Optimized solution to the same problem (faster):
#include <bits/stdc++.h>

using namespace std;



const int MAX_N = (int)1e5 + 5;



int n, m, p[MAX_N], grid[MAX_N];



int l, r, d;



int findset(int x) {

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

	int f = p[x];

	p[x] = findset(p[x]);

	grid[x] += grid[f];

	return p[x];

}



int main(void) {

  // Here your code !

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

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

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

		int u, v, w;

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



		int pl = findset(l), pr = findset(r);



		if(pl != pr) {

			p[pr] = pl;

			grid[pr] = grid[l] + d - grid[r];

		}

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

      printf("No\n");

      return 0;

    }

	}

	printf("Yes\n");

}


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

#include <iostream>

#include <utility>

#include <vector>

using namespace std;

#define MINF -1e12



vector<pair <int, long long> > v[100001];

long long d[100001];



int s(int i){

  int val = 0;

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

    if (d[v[i][j].first] == MINF) {

      d[v[i][j].first] = d[i] + v[i][j].second;

      val += s(v[i][j].first);

    }

    else {

      if (d[v[i][j].first] != d[i] + v[i][j].second){

        return -1;

      }

    }

  }

  return val;

}



int main(){





  int n, m;

  cin >> n >> m;

  for (int cas = 0; cas < m; cas++){

    int l, r; long long d;

    cin >> l >> r >> d;

    v[l].push_back(make_pair(r, d));

    v[r].push_back(make_pair(l, -d));

  }



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

    d[i+1] = MINF;

  }



  int u;

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

    if (d[i] == MINF) {

      d[i] = 0;

      u = s(i);

    }

    if (u < 0){

      printf("No\n");

      return 0;

    }

  }





  printf("Yes\n");

  return 0;

}

// Optimized solution to the same problem (faster):
#include <bits/stdc++.h>

using namespace std;



// one-based numbering

template<class Abel> struct UnionFind {

    vector<int> data;

    vector<Abel> diff_weight;



    UnionFind(int n, Abel identity) {

      data.resize(n+1, -1);

      diff_weight.resize(n+1, identity);

    }

    int find(int x) {

        if(data[x] < 0) return x;

        else {

          int root = find(data[x]);

          diff_weight[x] += diff_weight[data[x]];

          return data[x] = root;

        }

    }

    int size(int x) {

      return -data[find(x)];

    }

    bool same(int x, int y) {

        x = find(x); y = find(y);

        return x == y;

    }

    bool unite(int x, int y, Abel w) {

        w += weight(x); w -= weight(y);

        x = find(x); y = find(y);

        if(x == y) return false;

        if (data[x] > data[y]) swap(x, y), w = -w;

        data[x] += data[y];

        data[y] = x;

        diff_weight[y] = w;

        return true;

    }

    Abel weight(int x) {

        find(x);

        return diff_weight[x];

    }

    Abel diff(int x, int y) {

        return weight(y) - weight(x);

    }

};





int main(){

  int n, m; cin >> n >> m;

  UnionFind<int> uf(n, 0);

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

    int left, right, dist; cin >> left >> right >> dist;

    if (uf.same(left, right)) {

      if (uf.diff(left, right) != dist) {

        cout << "No" << endl;

        return 0;

      }

    } else {

      uf.unite(left, right, dist);

    }

  }

  cout << "Yes" << endl;

  return 0;

}


// Fastest known solution for this problem: