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: 6.860843259028732x):
#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 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: 1.9206815507641553x):
#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: 1.3613168322578793x):
#include <bits/stdc++.h>

using namespace std;

const int N=1e5+5,M=2e5+5;

int n,m;



inline int in(){

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

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

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

	return x;

}



int cnt,head[N],to[2*M],wi[2*M],nxt[2*M];

inline void adds(int x,int y,int z){

	to[++cnt]=y,wi[cnt]=z,nxt[cnt]=head[x],head[x]=cnt;

	return ;

}



inline void solve_in(){

	int a,b,c;

	n=in(),m=in();

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

		a=in(),b=in(),c=in();

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

	}

	return ;

}



bool co[N];

int dis[N];

bool vis[N];

queue< int > Q;

inline bool SPFA(int st){

	int mis=0,mas=0;

	dis[st]=0,vis[st]=true,Q.push(st);

	while(!Q.empty()){

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

		vis[u]=false,co[u]=true;

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

			int v=to[i],w=wi[i];

			co[v]=true;

			if(dis[v]==0x3f3f3f3f){

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

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

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

				if(mas-mis>1e9) return false;

				if(!vis[v]) vis[v]=true,Q.push(v);

			}

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

		}

	}

	return true;

}



int main(){

	solve_in();

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

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

		if(!co[i]){

			if(!SPFA(i)){

				puts("No");

				return 0;

			}

		}

	}

	puts("Yes");

	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: 2.5488965573618043x):
#include <bits/stdc++.h>

using namespace std;

const int N=1e5+5,M=2e5+5;

int n,m;



inline int in(){

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

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

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

	return x;

}



int cnt,head[N],to[2*M],wi[2*M],nxt[2*M];

inline void adds(int x,int y,int z){

	to[++cnt]=y,wi[cnt]=z,nxt[cnt]=head[x],head[x]=cnt;

	return ;

}



inline void solve_in(){

	int a,b,c;

	n=in(),m=in();

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

		a=in(),b=in(),c=in();

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

	}

	return ;

}



bool co[N];

int dis[N];

bool vis[N];

queue< int > Q;

inline bool SPFA(int st){

	int mis=0,mas=0;

	dis[st]=0,vis[st]=true,Q.push(st);

	while(!Q.empty()){

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

		vis[u]=false,co[u]=true;

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

			int v=to[i],w=wi[i];

			co[v]=true;

			if(dis[v]==0x3f3f3f3f){

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

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

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

				if(mas-mis>1e9) return false;

				if(!vis[v]) vis[v]=true,Q.push(v);

			}

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

		}

	}

	return true;

}



int main(){

	solve_in();

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

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

		if(!co[i]){

			if(!SPFA(i)){

				puts("No");

				return 0;

			}

		}

	}

	puts("Yes");

	return 0;

}
// 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: 4.597883798734119x):
#include <bits/stdc++.h>

using namespace std;

const int N=1e5+5,M=2e5+5;

int n,m;



inline int in(){

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

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

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

	return x;

}



int cnt,head[N],to[2*M],wi[2*M],nxt[2*M];

inline void adds(int x,int y,int z){

	to[++cnt]=y,wi[cnt]=z,nxt[cnt]=head[x],head[x]=cnt;

	return ;

}



inline void solve_in(){

	int a,b,c;

	n=in(),m=in();

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

		a=in(),b=in(),c=in();

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

	}

	return ;

}



bool co[N];

int dis[N];

bool vis[N];

queue< int > Q;

inline bool SPFA(int st){

	int mis=0,mas=0;

	dis[st]=0,vis[st]=true,Q.push(st);

	while(!Q.empty()){

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

		vis[u]=false,co[u]=true;

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

			int v=to[i],w=wi[i];

			co[v]=true;

			if(dis[v]==0x3f3f3f3f){

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

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

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

				if(mas-mis>1e9) return false;

				if(!vis[v]) vis[v]=true,Q.push(v);

			}

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

		}

	}

	return true;

}



int main(){

	solve_in();

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

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

		if(!co[i]){

			if(!SPFA(i)){

				puts("No");

				return 0;

			}

		}

	}

	puts("Yes");

	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: 1.2871698494444574x):
#include <bits/stdc++.h>

using namespace std;

const int N=1e5+5,M=2e5+5;

int n,m;



inline int in(){

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

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

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

	return x;

}



int cnt,head[N],to[2*M],wi[2*M],nxt[2*M];

inline void adds(int x,int y,int z){

	to[++cnt]=y,wi[cnt]=z,nxt[cnt]=head[x],head[x]=cnt;

	return ;

}



inline void solve_in(){

	int a,b,c;

	n=in(),m=in();

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

		a=in(),b=in(),c=in();

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

	}

	return ;

}



bool co[N];

int dis[N];

bool vis[N];

queue< int > Q;

inline bool SPFA(int st){

	int mis=0,mas=0;

	dis[st]=0,vis[st]=true,Q.push(st);

	while(!Q.empty()){

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

		vis[u]=false,co[u]=true;

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

			int v=to[i],w=wi[i];

			co[v]=true;

			if(dis[v]==0x3f3f3f3f){

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

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

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

				if(mas-mis>1e9) return false;

				if(!vis[v]) vis[v]=true,Q.push(v);

			}

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

		}

	}

	return true;

}



int main(){

	solve_in();

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

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

		if(!co[i]){

			if(!SPFA(i)){

				puts("No");

				return 0;

			}

		}

	}

	puts("Yes");

	return 0;

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

}

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

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

}

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

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

using namespace std;

using ll = long long;

using vl = vector<ll>;

#define rp(i,s,e) for(int i=(s);i<(e);++i)

using II = pair<int,int>;

using VII = vector<II>;

using VVII = vector<VII>;



#define V_MAX 100000

vl visited(V_MAX+1);

vl dist(V_MAX+1);



void dfs(VVII &T, int p, ll w){

	if(visited[p]) return;

	visited[p] = true;

	dist[p] = w;

	for(auto cw:T[p]){

		int np,nw; tie(np,nw) = cw;

		dfs(T, np, w+nw);

	}

}



int main(){

	int N,M; cin>>N>>M;

	if(M==0){ puts("Yes"); return 0; }



	VVII V(N+1);

	int l,r,d, mini = INT_MAX, maxi = 0;

	rp(i, 0, M){

		cin>>l>>r>>d;

		V[l].emplace_back(r, d);

		V[r].emplace_back(l,-d);

		mini = min(mini, l);

		maxi = max(maxi, r);

	}



	rp(l, mini, maxi+1){

		dfs(V, l, 0);

		for(auto rd:V[l]){

			tie(r,d) = rd;

			if(abs(d) != abs(dist[r]-dist[l])){ puts("No"); return 0; }

		}

	}

	puts("Yes");

}

// Faster C++ solution for the same problem (measured speedup: 1.4479453162730975x):
// D - People on a Line

#include <bits/stdc++.h>

using namespace std;

using vi = vector<int>;

#define rp(i,s,e) for(int i=(s);i<(e);++i)

using VVII = vector<vector<pair<int,int>>>;



#define V_MAX 100000

vi visited(V_MAX+1);

vi dist(V_MAX+1);



void dfs(VVII &T, int p, int w){

	if(visited[p]) return;

	visited[p] = true;

	dist[p] = w;

	for(auto cw:T[p]){

		int np,nw; tie(np,nw) = cw;

		dfs(T, np, w+nw);

	}

}



int main(){

	int N,M; cin>>N>>M;

	if(M==0){ puts("Yes"); return 0; }



	VVII V(N+1);

	int l,r,d, L = INT_MAX, R = 0;

	rp(i, 0, M){

		cin>>l>>r>>d;

		V[l].emplace_back(r, d);

		V[r].emplace_back(l,-d);

		L = min(L, l);

		R = max(R, r);

	}



	rp(l, L, R+1){

		dfs(V, l, 0);

		for(auto rd:V[l]){

			tie(r,d) = rd;

			if(abs(d) != abs(dist[r]-dist[l])){ puts("No"); return 0; }

		}

	}

	puts("Yes");

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

using namespace std;

using ll = long long;

using vl = vector<ll>;

#define rp(i,s,e) for(int i=(s);i<(e);++i)

using II = pair<int,int>;

using VII = vector<II>;

using VVII = vector<VII>;



#define V_MAX 100000

vl visited(V_MAX+1);

vl dist(V_MAX+1);



void dfs(VVII &T, int p, ll w){

	if(visited[p]) return;

	visited[p] = true;

	dist[p] = w;

	for(auto cw:T[p]){

		int np,nw; tie(np,nw) = cw;

		dfs(T, np, w+nw);

	}

}



int main(){

	int N,M; cin>>N>>M;

	if(M==0){ puts("Yes"); return 0; }



	VVII V(N+1);

	int l,r,d, mini = INT_MAX, maxi = 0;

	rp(i, 0, M){

		cin>>l>>r>>d;

		V[l].emplace_back(r, d);

		V[r].emplace_back(l,-d);

		mini = min(mini, l);

		maxi = max(maxi, r);

	}



	rp(l, mini, maxi+1){

		dfs(V, l, 0);

		for(auto rd:V[l]){

			tie(r,d) = rd;

			if(abs(d) != abs(dist[r]-dist[l])){ puts("No"); return 0; }

		}

	}

	puts("Yes");

}

// Faster C++ solution for the same problem (measured speedup: 1.8653809258266438x):
// D - People on a Line

#include <bits/stdc++.h>

using namespace std;

using vi = vector<int>;

#define rp(i,s,e) for(int i=(s);i<(e);++i)

using VVII = vector<vector<pair<int,int>>>;



#define V_MAX 100000

vi dist(V_MAX+1, INT_MAX);



void dfs(VVII &T, int p, int w){

	if(dist[p] != INT_MAX) return;

	dist[p] = w;

	for(auto cw:T[p]){

		int np,nw; tie(np,nw) = cw;

		dfs(T, np, w+nw);

	}

}



int main(){

	int N,M; cin>>N>>M;

	if(M==0){ puts("Yes"); return 0; }



	VVII T(N+1);

	int l,r,d, L = INT_MAX, R = 0;

	rp(i, 0, M){

		cin>>l>>r>>d;

		T[l].emplace_back(r, d);

		T[r].emplace_back(l,-d);

		L = min(L, l);

		R = max(R, r);

	}



	rp(l, L, R+1){

		dfs(T, l, 0);

		for(auto rd:T[l]){

			tie(r,d) = rd;

			if(abs(d) != abs(dist[r]-dist[l])){ puts("No"); return 0; }

		}

	}

	puts("Yes");

}