stablegradients/pie-gem5-pairs huggingface dataset:
// Slower C++ solution:
#include <cstdio>

#include <iostream>

#include <algorithm>

#include <cstring>

#include <queue>



using namespace std;



struct edge

{

    int v,w,nxt;

}e[400050];



int head[100050],ecnt;



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

{

    e[++ecnt].v = v;

    e[ecnt].w = w;

    e[ecnt].nxt = head[u];

    head[u] = ecnt;

}



int N,M;

int l[200050],r[200050];

int d[200050];

long long dist[100005];

queue<int> que;

bool vis[100050],inq[100050];



bool spfa(int st)

{

    que.push(st);

    inq[st] = true;

    dist[st] = 0;

    long long curmax = 0,curmin = 0;

    while(!que.empty())

    {

        int u = que.front();

        que.pop();

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

        {

            int v = e[i].v;

            if(dist[v] == 12345678987654321)

            {

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

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

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

                if(curmax - curmin > 1000000000)

                    return false;

                vis[v] = 1;

                if(!inq[v])

                    que.push(v);

            }

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

                return false;

        }

        inq[u] = false;

    }

    return true;

}



int main()

{

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

        dist[i] = 12345678987654321;

    scanf("%d%d",&N,&M);

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

    {

        scanf("%d%d%d",&l[i],&r[i],&d[i]);

        adde(l[i],r[i],d[i]);

        adde(r[i],l[i],-d[i]);

    }

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

using namespace std;

typedef long long ll;

typedef double lf;

#define reg register

#define gc() (p1==p2&&(p2=(p1=buf)+fread(buf,1,1<<21,stdin),p1==p2)?EOF:*p1++)

#define input(a){a=0;char c=gc();int f=1;while(c<'0'||c>'9'){if(c=='-')f=-1;c=gc();}while(c>='0'&&c<='9'){a=(a<<3)+(a<<1)+(c&15);c=gc();}a*=f;}

static char buf[1<<21],*p1=buf,*p2=buf;

char bu[1<<21],cha[20];int p,pp=-1;

#define flush(){fwrite(bu,1,pp+1,stdout),pp=-1;}

#define output(x){if(pp>1<<20)flush();if(x<0)bu[++pp]=45,x=-x;do{cha[++p]=x%10+48;}while(x/=10);do{bu[++pp]=cha[p];}while(--p);}

#define Endl bu[++pp]='\n'

#define Space bu[++pp]=' '

#define pc(c) bu[++pp]=c

const int N=100010;

int n,m,f[N],d[N];

bool ok=1;

int find(int x)

{

    if(f[x]!=x){int ff=f[x];f[x]=find(f[x]);d[x]+=d[ff];}

    return f[x];

}

int main()

{

    input(n);input(m);

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

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

	{

        int l,r,x;

        input(l);input(r);input(x);

        int fl=find(l),fr=find(r);

        if(fl==fr&&d[l]-d[r]!=x){ok=0;break;}

        if(fl!=fr){f[fl]=fr;d[fl]=x+d[r]-d[l];}

    }

    if(ok)puts("Yes");

    else puts("No");

    return 0;

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

#include<queue>

#include<iostream>

#include<cstring>

using namespace std;

int hd[100010],nxt[400010],edg[400010],ver[400010];

int n,m;

int l,r,dd;

int tot,nuuum;

int dist[100010],visnum[100010];

bool ins[100010];

int mmnb;

inline int rd()

{

    char ch;

    int res;

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

    res=ch-'0';

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

    return res;

}

inline void add_edge(int x,int y,int z)

{

    ver[++tot]=y,edg[tot]=z,nxt[tot]=hd[x],hd[x]=tot;

}

int main()

{

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

    n=rd(),m=rd();

    if(m==0) {printf("Yes");return 0;}

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

    {

        l=rd(),r=rd(),dd=rd();

        add_edge(r,l,dd);

        add_edge(l,r,-dd);

    }

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

    {

        if(dist[ttt]==1061109567)

        {

            ++nuuum;

            int s=ttt;

            queue<int> que;

    int summ=1;

    que.push(s);

    visnum[s]=nuuum;

    while(!que.empty())

    {

        int ttemp=que.front();

        que.pop();

        for(int m=hd[ttemp];m;m=nxt[m])

        {

            int y=ver[m];

            if(visnum[y]==0) {visnum[y]=nuuum,++summ;que.push(y);}

        }

    }

    queue<int> q;

    q.push(s);

    dist[s]=0;

    while(!q.empty())

    {

        int y=q.front();

        q.pop();

        ins[y]=0;

        for(int i=hd[y];i;i=nxt[i])

        {

            int z=ver[i];

            if(visnum[z]==nuuum)

            {

                if(dist[z]>dist[y]+edg[i])

                {

                	if(dist[z]==1061109567) {dist[z]=dist[y]+edg[i];q.push(z);}

                }

                else

                if(dist[z]!=dist[y]+edg[i]) {printf("No");return 0;}

            }

        }

    }

        }

    }

    printf("Yes");

}

// Faster C++ solution for the same problem (measured speedup: 1.4209526452227006x):
#include<bits/stdc++.h>

using namespace std;

typedef long long ll;

typedef double lf;

#define reg register

#define gc() (p1==p2&&(p2=(p1=buf)+fread(buf,1,1<<21,stdin),p1==p2)?EOF:*p1++)

#define input(a){a=0;char c=gc();int f=1;while(c<'0'||c>'9'){if(c=='-')f=-1;c=gc();}while(c>='0'&&c<='9'){a=(a<<3)+(a<<1)+(c&15);c=gc();}a*=f;}

static char buf[1<<21],*p1=buf,*p2=buf;

char bu[1<<21],cha[20];int p,pp=-1;

#define flush(){fwrite(bu,1,pp+1,stdout),pp=-1;}

#define output(x){if(pp>1<<20)flush();if(x<0)bu[++pp]=45,x=-x;do{cha[++p]=x%10+48;}while(x/=10);do{bu[++pp]=cha[p];}while(--p);}

#define Endl bu[++pp]='\n'

#define Space bu[++pp]=' '

#define pc(c) bu[++pp]=c

const int N=100010;

int n,m,f[N],d[N];

bool ok=1;

int find(int x)

{

    if(f[x]!=x){int ff=f[x];f[x]=find(f[x]);d[x]+=d[ff];}

    return f[x];

}

int main()

{

    input(n);input(m);

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

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

	{

        int l,r,x;

        input(l);input(r);input(x);

        int fl=find(l),fr=find(r);

        if(fl==fr&&d[l]-d[r]!=x){ok=0;break;}

        if(fl!=fr){f[fl]=fr;d[fl]=x+d[r]-d[l];}

    }

    if(ok)puts("Yes");

    else puts("No");

    return 0;

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

# include <cstdio>

# include <iostream>

# include <queue>

# define N 100050 //N为顶点个数 

# define M 200050 //N为顶点个数 

# define WQD 0x7f7f7f7f//无穷大 

int n;//图的顶点个数

int m;//图的边数 

struct Edge{int next,to, w;}  e[M<<1];//不用0号单元 

int head[N+1]; 

int dis[N+1];//存放源点到其他点的路径

bool vis[N+1];

bool book[N+1];

bool spfa(int s);//差分约束判断 

using namespace std;

int main()

{

	ios::sync_with_stdio ( false ) ;

	int u,v,w;

	memset(head,-1,sizeof(head));

	cin>>n>>m;

	for(int i=1; i<=m; i++)  //本题约束关系为=，要添加两条边 

	{

		cin>>u>>v>>w;//输入第i条边 ,i为编号 

		e[i]=(Edge){head[u],v,w};head[u]=i;

		e[m+i]=(Edge){head[v],u,-w};head[v]=m+i;

	}

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

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

	for(int i=1; i<=n; i++)//每一片的连通区域都要判断 

		if(!vis[i]) 

		{

			vis[i]=1;

			if(spfa(i)==false)  {cout<<"No";return 0;}//有约束自相矛盾 

		}

	cout<<"Yes";//所以的点都符合条件 

	return 0;

}

bool spfa(int s)

{

 	queue<int>q;

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

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

	dis[s]=0;

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

	while(q.size()>0)//如果没松弛就松弛，如果松弛过就判断是否符合约束条件，如果自相矛盾就是不可能的数据 

	{

		int k=q.front();q.pop();//对头元素出队 

		book[k]=0;

		for(int i=head[k]; i!=-1; i=e[i].next)

		{

			int v=e[i].to;

			if(dis[v]==WQD && dis[k]<WQD)//如果v点没松弛过，就松弛更新dis[v]的值 				

			{	//题目的约束条件是= 			

				dis[v]=dis[k]+e[i].w;//更新 

				if(book[v]==0)	{q.push(v);	book[v]=1;}//入队标记

				vis[v]=1;//标记该点已经松弛过 

			}

			else if(dis[v]<WQD && dis[k]<WQD && dis[v]!=dis[k]+e[i].w)	return false;//据题意理解差分系统约束条件，不相等，自相矛盾 

		}		

    }

	return true;//别掉了这句 

}

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

#include <iostream>

#include <algorithm>

#include <cstring>

#include <queue>

#include <cmath>

using namespace std;



int N,M,cnt;

int head[100050];

long long dis[100050];

bool vis[100050],inq[100050];

struct edge{

    int u,v,w,next;

}t[400050];

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

    t[++cnt].u=u;

	t[cnt].v=v;

    t[cnt].w=w;

    t[cnt].next=head[u];

    head[u]=cnt;

}

queue<int>q;

inline bool spfa(int start){

    

    q.push(start);

    inq[start]=true;

    dis[start]=0;

    

    while(!q.empty()){

        int u=q.front();

        	q.pop();

        inq[u]=false;

    	

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

            int v=t[i].v;

            	if(dis[v]==12345678987654321){

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

                		vis[v]=true;

                	if(!inq[v])

                   		q.push(v);

            	}

            	else 

				if(dis[v]!=dis[u]+t[i].w)

                	return false;

        }

    }

    return true;

}



int main(){

	scanf("%d%d",&N,&M);

    for(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(int i=1;i<=N;i++)

		dis[i]=12345678987654321;

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

        if(!vis[i]){

            vis[i]=true;

            	bool flag=spfa(i);

            	if(!flag){

                	printf("No\n");

                		return 0;

            	}

        }

    }

    printf("Yes\n");

    return 0;

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

#include<algorithm>

#include<cstdio>

#include<cmath>

#include<cstring>

#include<queue>

using namespace std;



const int N = 100010;

const int M = 200010;

const int INFM = 0x8c8c8c8c;



struct edge{

	int v , w , n ; 

}e[M<<1];int head[N];

int dis[N];

int n , m ;

bool book[N]; 

bool con[N];

queue< int > q ; 



bool spfa( ){

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

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

		if( !con[k] ){

			q.push( k );

			dis[k] = 0 ; 

			while( q.size() ){

				int ts = q.front();

				con[ts] = 1;

				q.pop();

				book[ts] = 0 ;

				for( int i = head[ts] ; i ; i = e[i].n ){

					int tv = e[i].v;					

					if( dis[tv] == INFM ){

						dis[tv] = dis[ts]+e[i].w ;

						if( !book[tv] )q.push( tv );

					}

					else if( dis[tv] != dis[ts] + e[i].w )

						return 0 ;

				}

			}

		}

	}

	return 1 ; 

}



int main()

{

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

	int u , v , w ; 

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

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

		e[i] = ( edge ){ u , w  , head[v] };

		e[i+m] = ( edge ){ v , -w , head[u] };

		head[v] = i ; head[u] = i + m ;

	}

	if( spfa( ) ) printf("Yes");

	else printf("No");

	return 0;

} 

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

#include <iostream>

#include <algorithm>

#include <cstring>

#include <queue>

#include <cmath>

using namespace std;



int N,M,cnt;

int head[100050];

long long dis[100050];

bool vis[100050],inq[100050];

struct edge{

    int u,v,w,next;

}t[400050];

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

    t[++cnt].u=u;

	t[cnt].v=v;

    t[cnt].w=w;

    t[cnt].next=head[u];

    head[u]=cnt;

}

queue<int>q;

inline bool spfa(int start){

    

    q.push(start);

    inq[start]=true;

    dis[start]=0;

    

    while(!q.empty()){

        int u=q.front();

        	q.pop();

        inq[u]=false;

    	

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

            int v=t[i].v;

            	if(dis[v]==12345678987654321){

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

                		vis[v]=true;

                	if(!inq[v])

                   		q.push(v);

            	}

            	else 

				if(dis[v]!=dis[u]+t[i].w)

                	return false;

        }

    }

    return true;

}



int main(){

	scanf("%d%d",&N,&M);

    for(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(int i=1;i<=N;i++)

		dis[i]=12345678987654321;

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

        if(!vis[i]){

            vis[i]=true;

            	bool flag=spfa(i);

            	if(!flag){

                	printf("No\n");

                		return 0;

            	}

        }

    }

    printf("Yes\n");

    return 0;

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

#include<cstring>

#include<iostream>

#include<algorithm>

#define int long long

using namespace std;

int n,m,cnt=0;

int head[410000],nxt[410000],to[410000],val[410000];

int ma=0,mi=0;

int q[1000000],dis[100100],f[100100],vis[100100];

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

{

    cnt++;

    nxt[cnt]=head[x];

    head[x]=cnt;

    to[cnt]=y;

    val[cnt]=z;

}

bool spfa(int x)

{

    int l=0,r=1;

    q[1]=x;vis[x]=1;dis[x]=0;

    while(l<r)

    {

        int u=q[++l];

        for(int i=head[u];i!=-1;i=nxt[i])

        {

            int v=to[i];

            if(dis[v]==12345678987654321)

            {

                dis[v]=dis[u]+val[i];

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

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

                if(ma-mi>1e9) return 0;

                vis[v]=1;

                if(!f[v]) q[++r]=v,f[v]=1;

            }

            else if(dis[v]!=dis[u]+val[i]) return 0;

        }

        f[u]=0;

    }

    return 1;

}

signed main()

{

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

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

    memset(head,-1,sizeof(head));

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

        dis[i]=12345678987654321;

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

    if(!m) {printf("Yes");return 0;}

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

    {

        int x,y,z;

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

        addedge(x,y,z);

        addedge(y,x,-z);

    }

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

        if(!vis[i]) {if(!spfa(i)) {printf("No");return 0;}}

    printf("Yes");

    return 0;

}

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

#include <iostream>

#include <algorithm>

#include <cstring>

#include <queue>

#include <cmath>

using namespace std;



int N,M,cnt;

int head[100050];

long long dis[100050];

bool vis[100050],inq[100050];

struct edge{

    int u,v,w,next;

}t[400050];

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

    t[++cnt].u=u;

	t[cnt].v=v;

    t[cnt].w=w;

    t[cnt].next=head[u];

    head[u]=cnt;

}

queue<int>q;

inline bool spfa(int start){

    

    q.push(start);

    inq[start]=true;

    dis[start]=0;

    

    while(!q.empty()){

        int u=q.front();

        	q.pop();

        inq[u]=false;

    	

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

            int v=t[i].v;

            	if(dis[v]==12345678987654321){

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

                		vis[v]=true;

                	if(!inq[v])

                   		q.push(v);

            	}

            	else 

				if(dis[v]!=dis[u]+t[i].w)

                	return false;

        }

    }

    return true;

}



int main(){

	scanf("%d%d",&N,&M);

    for(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(int i=1;i<=N;i++)

		dis[i]=12345678987654321;

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

        if(!vis[i]){

            vis[i]=true;

            	bool flag=spfa(i);

            	if(!flag){

                	printf("No\n");

                		return 0;

            	}

        }

    }

    printf("Yes\n");

    return 0;

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

# include <cstdio>

# include <iostream>

# include <queue>

# define N 100050 //N为顶点个数 

# define M 200050 //N为顶点个数 

# define WQD 0x7f7f7f7f//无穷大 

int n;//图的顶点个数

int m;//图的边数 

struct Edge{int next,to, w;}  e[M<<1];//不用0号单元 

int head[N+1]; 

int dis[N+1];//存放源点到其他点的路径

bool vis[N+1];

bool book[N+1];

bool spfa(int s);//差分约束判断 

using namespace std;

int main()

{

	ios::sync_with_stdio ( false ) ;

	int u,v,w;

	memset(head,-1,sizeof(head));

	cin>>n>>m;

	for(int i=1; i<=m; i++)  //本题约束关系为=，要添加两条边 

	{

		cin>>u>>v>>w;//输入第i条边 ,i为编号 

		e[i]=(Edge){head[u],v,w};head[u]=i;

		e[m+i]=(Edge){head[v],u,-w};head[v]=m+i;

	}

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

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

	for(int i=1; i<=n; i++)//每一片的连通区域都要判断 

		if(!vis[i]) 

		{

			vis[i]=1;

			if(spfa(i)==false)  {cout<<"No";return 0;}//有约束自相矛盾 

		}

	cout<<"Yes";//所以的点都符合条件 

	return 0;

}

bool spfa(int s)

{

 	queue<int>q;

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

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

	dis[s]=0;

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

	while(q.size()>0)//如果没松弛就松弛，如果松弛过就判断是否符合约束条件，如果自相矛盾就是不可能的数据 

	{

		int k=q.front();q.pop();//对头元素出队 

		book[k]=0;

		for(int i=head[k]; i!=-1; i=e[i].next)

		{

			int v=e[i].to;

			if(dis[v]==WQD && dis[k]<WQD)//如果v点没松弛过，就松弛更新dis[v]的值 				

			{	//题目的约束条件是= 			

				dis[v]=dis[k]+e[i].w;//更新 

				if(book[v]==0)	{q.push(v);	book[v]=1;}//入队标记

				vis[v]=1;//标记该点已经松弛过 

			}

			else if(dis[v]<WQD && dis[k]<WQD && dis[v]!=dis[k]+e[i].w)	return false;//据题意理解差分系统约束条件，不相等，自相矛盾 

		}		

    }

	return true;//别掉了这句 

}

// Faster C++ solution for the same problem (measured speedup: 1.948517661754775x):
#include<bits/stdc++.h>

using namespace std;

int n, m, ERR;

int f[100010], val[100010];

int find(int x) {

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

	int px = f[x];

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

	val[x] += val[px];

	return f[x];

}

void merge(int x, int y, int d) {

	int px = find(x);

	int py = find(y);

	f[px] = f[py];

	val[x] = -val[x] + val[y] + d;

}

int main() {

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

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

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

		int x, y, d;

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

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

		if(px == py && val[x] - val[y] != d) ERR = 1;

		else if(px != py) {

			f[px] = py;

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

		}

	}

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

	else printf("Yes\n");

	return 0;

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

#include<algorithm>

#include<cstdio>

#include<cmath>

#include<cstring>

#include<queue>

using namespace std;



const int N = 100010;

const int M = 200010;

const int INFM = 0x8c8c8c8c;



struct edge{

	int v , w , n ; 

}e[M<<1];int head[N];

int dis[N];

int n , m ;

bool book[N]; 

bool con[N];

queue< int > q ; 



bool spfa( ){

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

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

		if( !con[k] ){

			q.push( k );

			dis[k] = 0 ; 

			while( q.size() ){

				int ts = q.front();

				con[ts] = 1;

				q.pop();

				book[ts] = 0 ;

				for( int i = head[ts] ; i ; i = e[i].n ){

					int tv = e[i].v;					

					if( dis[tv] == INFM ){

						dis[tv] = dis[ts]+e[i].w ;

						if( !book[tv] )q.push( tv );

					}

					else if( dis[tv] != dis[ts] + e[i].w )

						return 0 ;

				}

			}

		}

	}

	return 1 ; 

}



int main()

{

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

	int u , v , w ; 

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

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

		e[i] = ( edge ){ u , w  , head[v] };

		e[i+m] = ( edge ){ v , -w , head[u] };

		head[v] = i ; head[u] = i + m ;

	}

	if( spfa( ) ) printf("Yes");

	else printf("No");

	return 0;

} 

// Faster C++ solution for the same problem (measured speedup: 1.4151612609786433x):
#include<bits/stdc++.h>

using namespace std;

int n, m, ERR;

int f[100010], val[100010];

int find(int x) {

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

	int px = f[x];

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

	val[x] += val[px];

	return f[x];

}

void merge(int x, int y, int d) {

	int px = find(x);

	int py = find(y);

	f[px] = f[py];

	val[x] = -val[x] + val[y] + d;

}

int main() {

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

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

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

		int x, y, d;

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

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

		if(px == py && val[x] - val[y] != d) ERR = 1;

		else if(px != py) {

			f[px] = py;

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

		}

	}

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

	else printf("Yes\n");

	return 0;

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

#include<cstring>

#include<iostream>

#include<algorithm>

#define int long long

using namespace std;

int n,m,cnt=0;

int head[410000],nxt[410000],to[410000],val[410000];

int ma=0,mi=0;

int q[1000000],dis[100100],f[100100],vis[100100];

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

{

    cnt++;

    nxt[cnt]=head[x];

    head[x]=cnt;

    to[cnt]=y;

    val[cnt]=z;

}

bool spfa(int x)

{

    int l=0,r=1;

    q[1]=x;vis[x]=1;dis[x]=0;

    while(l<r)

    {

        int u=q[++l];

        for(int i=head[u];i!=-1;i=nxt[i])

        {

            int v=to[i];

            if(dis[v]==12345678987654321)

            {

                dis[v]=dis[u]+val[i];

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

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

                if(ma-mi>1e9) return 0;

                vis[v]=1;

                if(!f[v]) q[++r]=v,f[v]=1;

            }

            else if(dis[v]!=dis[u]+val[i]) return 0;

        }

        f[u]=0;

    }

    return 1;

}

signed main()

{

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

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

    memset(head,-1,sizeof(head));

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

        dis[i]=12345678987654321;

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

    if(!m) {printf("Yes");return 0;}

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

    {

        int x,y,z;

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

        addedge(x,y,z);

        addedge(y,x,-z);

    }

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

        if(!vis[i]) {if(!spfa(i)) {printf("No");return 0;}}

    printf("Yes");

    return 0;

}

// Faster C++ solution for the same problem (measured speedup: 5.1903707312124325x):
#include<bits/stdc++.h>

using namespace std;

int n, m, ERR;

int f[100010], val[100010];

int find(int x) {

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

	int px = f[x];

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

	val[x] += val[px];

	return f[x];

}

void merge(int x, int y, int d) {

	int px = find(x);

	int py = find(y);

	f[px] = f[py];

	val[x] = -val[x] + val[y] + d;

}

int main() {

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

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

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

		int x, y, d;

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

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

		if(px == py && val[x] - val[y] != d) ERR = 1;

		else if(px != py) {

			f[px] = py;

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

		}

	}

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

	else printf("Yes\n");

	return 0;

}