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



const long long INF=1e12;



int head[100050],ecnt;



void add(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 dis[100005];

queue<int> que;

bool vis[100050],inq[100050];



bool spfa(int st)

{

    que.push(st);

    inq[st] = true;

    dis[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(dis[v] == INF)

            {

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

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

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

                if(curmax - curmin > 1000000000)

                    return false;

                vis[v] = 1;

                if(!inq[v])

                    que.push(v);

            }

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

                return false;

        }

        inq[u] = false;

    }

    return true;

}



int main()

{

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

        dis[i] = INF;

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

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

    {

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

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

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

using namespace std;

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

{

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

        cout<<"Yes"<<endl;

    else 

        cout<<"No"<<endl;

    return 0;

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

#include <cstdio>

#include <vector>

using namespace std;

struct Path {

	int to, v;

	Path (int To = 0, int V = 0)

	{

		to = To;

		v = V;

	}

};

void node (int l, int r, int d);

vector <Path> ph[100000 + 9];//记录从 i 点出发的边 

bool vis[100000 + 9], inQ[100000 + 9];

int dis[100000 + 9];

bool dfs(int s);

int main()

{

	int n, m;

	

	cin >> n >> m;

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

	{

		int l, r, d;

		cin >> l >> r >> d;

		node (r, l, d);

		node (l, r, -d);

	}

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

		if (dfs(i) == false)

		{

			cout << "No" << endl;

			return 0;

		}

	cout << "Yes" << endl;

	

}

bool dfs(int s)

{

//	if (vis[s] = true) return true;

	inQ[s] = true;

//	vis[s] = true;

	for (int i = 0; i < ph[s].size(); i++)

	{

		Path e = ph[s][i];

		if (dis[e.to] < dis[s] + e.v)

		{

			if (inQ[e.to])

				return false;

			dis[e.to] = dis[s] + e.v;

			if (dfs(e.to) == false)

				return false;

		}

	}

	inQ[s] = false;

	return true;

}

void node (int x1, int x2, int v)

{

	ph[x1].push_back(Path(x2, v));

}

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

#include <cstring>

#include <iostream>

using namespace std;

const int mn=1e5+5,mm=4e5+5;

int dis[mn],vis[mn],nbs[mn],nxt[mm],ev[mm],ew[mm];

int n,m,ok,tot;



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

{

	nxt[++tot]=nbs[u],nbs[u]=tot,ev[tot]=v,ew[tot]=w;

}



void spfa(int i)

{

	vis[i]=1;

	for (int j=nbs[i];j!=0;j=nxt[j])

	{

		int v=ev[j],w=ew[j];

		if (dis[v]>dis[i]+w)

		{

			if ((vis[v]==1)||(ok==1)) return ok=1,void();

			dis[v]=dis[i]+w,spfa(v);

		}

	}

	vis[i]=0;

}



int main()

{

	int x,y,z;

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

	for (int i=1;i<=m;i++) scanf("%d%d%d",&x,&y,&z),add(x,y,z),add(y,x,-z);

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

	printf(ok==1?"No\n":"Yes\n");

	return 0;

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

#include <algorithm>

#include <cstdio>

#include <cstring>

#include <cmath>

#include <queue>

using namespace std;

#define fors(i,a,b) for(int i=(a);i<=(b);++i)

typedef long long ll;

const int Size=1<<18;

inline char getch(){

    static char buf[Size],*p1=buf,*p2=buf;

    return p1==p2 && (p2=(p1=buf)+fread(buf,1,Size,stdin),p1==p2) ? EOF : *p1++;

}

int read(){

    int s=0,f=1;

    char c=getch();

    while(c>'9' || c<'0'){if(c=='-') f=-1; c=getch();}

    while(c<='9' && c>='0'){s=(s<<1)+(s<<3)+c-'0';c=getch();}

    return s*f;

}



const int maxn=100007;

const long long inf=12345678987654321;

struct node

{

    int to,next,val;

}edge[maxn<<2];

int head[maxn],tot,n,m,vis[maxn],visq[maxn];

ll dis[maxn];



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

    edge[++tot].to=y;

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

    head[x]=tot;

    edge[tot].val=w;

}



queue<int> q;

int spfa(int s){

    q.push(s);

    dis[s]=0,vis[s]=1;

    ll maxs=0,mins=0;

    while(!q.empty()){

        int u=q.front();

        q.pop();

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

            int to=edge[i].to;

            if(dis[to]==inf){

                dis[to]=dis[u]+edge[i].val;

                maxs=max(maxs,dis[to]);

                mins=min(mins,dis[to]);

                if(maxs-mins>10000000000) return 0;

                visq[to]=1;

                if(!vis[to])

                    q.push(to);

            }

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

        }

        vis[u]=0;

    }

    return 1;

}

int main(int argc, char const *argv[])

{

    fill(dis,dis+maxn-1,inf);

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

    fors(i,1,m){

        int l=read(),r=read(),w=read();

        add(l,r,w);

        add(r,l,-w);

    }

    fors(i,1,n)

        if(!visq[i]){

            visq[i]=1;

            int flag=spfa(i);

            if(!flag){

                printf("No\n");

                return 0;

            }

        }

    printf("Yes\n");

    return 0;

}

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

#include <cstring>

#include <iostream>

using namespace std;

const int mn=1e5+5,mm=4e5+5;

int dis[mn],vis[mn],nbs[mn],nxt[mm],ev[mm],ew[mm];

int n,m,ok,tot;



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

{

	nxt[++tot]=nbs[u],nbs[u]=tot,ev[tot]=v,ew[tot]=w;

}



void spfa(int i)

{

	vis[i]=1;

	for (int j=nbs[i];j!=0;j=nxt[j])

	{

		int v=ev[j],w=ew[j];

		if (dis[v]>dis[i]+w)

		{

			if ((vis[v]==1)||(ok==1)) return ok=1,void();

			dis[v]=dis[i]+w,spfa(v);

		}

	}

	vis[i]=0;

}



int main()

{

	int x,y,z;

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

	for (int i=1;i<=m;i++) scanf("%d%d%d",&x,&y,&z),add(x,y,z),add(y,x,-z);

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

	printf(ok==1?"No\n":"Yes\n");

	return 0;

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

#include<bits/stdc++.h>

using namespace std;

#define mx 100010

#define inf -9187201950435737472

#define int long long



struct node{

	int t,nt,dis;

}e[400005];

int n,m;

int cnt=0,head[mx],d[mx];



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

	e[++cnt].t=y;

	e[cnt].dis=w;

	e[cnt].nt=head[x];

	head[x]=cnt;

}



void bfs(int p){

	queue<int> q;

	q.push(p);

	d[p]=0;

	int now;

	while(!q.empty()){

		now=q.front();

		q.pop();

		for(int i=head[now];i;i=e[i].nt){

			int v=e[i].t;

//			cout<<d[v]<<' '<<inf<<endl; 

			if(d[v]==inf){

				q.push(v);

				d[v]=d[now]+e[i].dis;

			}else{

//				cout<<v<<' '<<d[v]<<' '<<now<<' '<<d[now]<<endl;

				if(d[v]!=d[now]+e[i].dis){

					printf("No\n");

					exit(0);

				}

			}

		}

	}

}



signed main(){

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

	memset(d,128,sizeof(d));

	int l,r,D;

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

		scanf("%lld%lld%lld",&l,&r,&D);

		add(l,r,D);

		add(r,l,-D);

	}

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

		if(d[i]==inf) bfs(i);

		

	}

	printf("Yes\n");

}


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

#include <cstring>

#include <iostream>

using namespace std;

const int mn=1e5+5,mm=4e5+5;

int dis[mn],vis[mn],nbs[mn],nxt[mm],ev[mm],ew[mm];

int n,m,ok,tot;



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

{

	nxt[++tot]=nbs[u],nbs[u]=tot,ev[tot]=v,ew[tot]=w;

}



void spfa(int i)

{

	vis[i]=1;

	for (int j=nbs[i];j!=0;j=nxt[j])

	{

		int v=ev[j],w=ew[j];

		if (dis[v]>dis[i]+w)

		{

			if ((vis[v]==1)||(ok==1)) return ok=1,void();

			dis[v]=dis[i]+w,spfa(v);

		}

	}

	vis[i]=0;

}



int main()

{

	int x,y,z;

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

	for (int i=1;i<=m;i++) scanf("%d%d%d",&x,&y,&z),add(x,y,z),add(y,x,-z);

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

	printf(ok==1?"No\n":"Yes\n");

	return 0;

}
// 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.8219892470072347x):
#include <cstdio>

#include <cstring>

#include <iostream>

using namespace std;

const int mn=1e5+5,mm=4e5+5;

int dis[mn],vis[mn],nbs[mn],nxt[mm],ev[mm],ew[mm];

int n,m,ok,tot;



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

{

	nxt[++tot]=nbs[u],nbs[u]=tot,ev[tot]=v,ew[tot]=w;

}



void spfa(int i)

{

	vis[i]=1;

	for (int j=nbs[i];j!=0;j=nxt[j])

	{

		int v=ev[j],w=ew[j];

		if (dis[v]>dis[i]+w)

		{

			if ((vis[v]==1)||(ok==1)) return ok=1,void();

			dis[v]=dis[i]+w,spfa(v);

		}

	}

	vis[i]=0;

}



int main()

{

	int x,y,z;

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

	for (int i=1;i<=m;i++) scanf("%d%d%d",&x,&y,&z),add(x,y,z),add(y,x,-z);

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

	printf(ok==1?"No\n":"Yes\n");

	return 0;

}
// Slower C++ solution:
//people on a line

#include<cstdio>

#include<cstring>

#include<string>

#include<algorithm>

#include<iostream>

#include<queue>

using std::queue;

using std::sort;

const int maxn=100010;

const int maxm=400050;

const long long inf=9999999999;

long long dis[maxn];

bool vis[maxn];

int head[maxn]; int cnt=0;

bool inq[maxn];

inline void init(int n) {

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

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

		dis[i]=inf;

	}

	memset(vis,false,sizeof(vis));

	memset(inq,false,sizeof(inq));

}

struct zmm{

	int to,next;

	int dis;

}a[maxm];

inline void add(int from,int to,int dis) {

	a[++cnt].to=to;

	a[cnt].dis=dis;

	a[cnt].next=head[from];

	head[from]=cnt;

	return;

}

queue<int> q;

bool spfa(int s) {



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

	inq[s]=true; q.push(s);

	dis[s]=0;

	while(!q.empty()) {

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

		inq[u]=false;

		int v;

		for(int i=head[u];i!=-1;i=a[i].next){

			v=a[i].to;

			if(dis[v]==inf) {

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

				vis[v]=true;

				if(!inq[v]) {

					q.push(v);

					inq[v]=true;

				}

			}

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

				return false;

				}

		}

	}

	return true;

}

int main()

{

	int n,m;

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

	int u,v,w;

	init(n);

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

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

		add(u,v,w);

		add(v,u,-w);

	}

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

		if(!vis[i]) {

			vis[i]=true;

			if(!spfa(i)) {

				printf("No");

				return 0;

			}

		}

	}

	printf("Yes");

	return 0;

}

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

#include <cstring>

#include <iostream>

using namespace std;

const int mn=1e5+5,mm=4e5+5;

int dis[mn],vis[mn],nbs[mn],nxt[mm],ev[mm],ew[mm];

int n,m,ok,tot;



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

{

	nxt[++tot]=nbs[u],nbs[u]=tot,ev[tot]=v,ew[tot]=w;

}



void spfa(int i)

{

	vis[i]=1;

	for (int j=nbs[i];j!=0;j=nxt[j])

	{

		int v=ev[j],w=ew[j];

		if (dis[v]>dis[i]+w)

		{

			if ((vis[v]==1)||(ok==1)) return ok=1,void();

			dis[v]=dis[i]+w,spfa(v);

		}

	}

	vis[i]=0;

}



int main()

{

	int x,y,z;

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

	for (int i=1;i<=m;i++) scanf("%d%d%d",&x,&y,&z),add(x,y,z),add(y,x,-z);

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

	printf(ok==1?"No\n":"Yes\n");

	return 0;

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

#define ll long long

using namespace std;

const int N=2e5+10;

inline ll read()

{

	ll x=0,f=1;char wty=getchar();

	while(!isdigit(wty)){if(wty=='-')f=0;wty=getchar();}

	while(isdigit(wty)){x=x*10+wty-'0';wty=getchar();}

	return f?x:-x;

}

struct mmp

{

	int nxt,to,w;

}e[N*2];

int n,m,cnt;

int vis[N],dis[N],head[N*2],pu[N];

inline void ade(int x,int y,int w)

{

	e[++cnt].nxt=head[x];

	e[cnt].to=y;

	e[cnt].w=w;

	head[x]=cnt;

}

queue<int> q;

inline bool spfa(int s)

{

	dis[s]=0,vis[s]=1;

	q.push(s);

	while(!q.empty())

	{

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

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

		{

			int v=e[i].to;

			if(dis[v]==0x3f3f3f3f)

			{

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

				pu[v]=1;

				if(vis[v]) continue;

				q.push(v);

			}

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

		}

		vis[u]=0;

	}

	return true;

}

int main()

{

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

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

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

	{

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

		ade(l,r,d),ade(r,l,-d);

	}

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

	{

		if(pu[i]) continue;

		pu[i]=1;

		if(!spfa(i))

		{

			cout<<"No";

			return 0;

		}

	}

	cout<<"Yes";

	return 0;

}

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

#include <cstring>

#include <iostream>

using namespace std;

const int mn=1e5+5,mm=4e5+5;

int dis[mn],vis[mn],nbs[mn],nxt[mm],ev[mm],ew[mm];

int n,m,ok,tot;



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

{

	nxt[++tot]=nbs[u],nbs[u]=tot,ev[tot]=v,ew[tot]=w;

}



void spfa(int i)

{

	vis[i]=1;

	for (int j=nbs[i];j!=0;j=nxt[j])

	{

		int v=ev[j],w=ew[j];

		if (dis[v]>dis[i]+w)

		{

			if ((vis[v]==1)||(ok==1)) return ok=1,void();

			dis[v]=dis[i]+w,spfa(v);

		}

	}

	vis[i]=0;

}



int main()

{

	int x,y,z;

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

	for (int i=1;i<=m;i++) scanf("%d%d%d",&x,&y,&z),add(x,y,z),add(y,x,-z);

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

	printf(ok==1?"No\n":"Yes\n");

	return 0;

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

int dist[100005];

queue<int> que;

bool vis[100050],inq[100050];



bool spfa(int st) {

	que.push(st);

	inq[st] = 1;

	dist[st] = 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] == 1061109567) {

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

				vis[v] = 1;

				if(!inq[v]) que.push(v);

			}

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

				

		}

		inq[u] = 0;

	}

	return 1;

}



int main() {

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

	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;

			if(!spfa(i)) {

				printf("No\n");

				return 0;

			}

		}

	}

	printf("Yes\n");

	return 0;

}

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

#include <cstring>

#include <iostream>

using namespace std;

const int mn=1e5+5,mm=4e5+5;

int dis[mn],vis[mn],nbs[mn],nxt[mm],ev[mm],ew[mm];

int n,m,ok,tot;



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

{

	nxt[++tot]=nbs[u],nbs[u]=tot,ev[tot]=v,ew[tot]=w;

}



void spfa(int i)

{

	vis[i]=1;

	for (int j=nbs[i];j!=0;j=nxt[j])

	{

		int v=ev[j],w=ew[j];

		if (dis[v]>dis[i]+w)

		{

			if ((vis[v]==1)||(ok==1)) return ok=1,void();

			dis[v]=dis[i]+w,spfa(v);

		}

	}

	vis[i]=0;

}



int main()

{

	int x,y,z;

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

	for (int i=1;i<=m;i++) scanf("%d%d%d",&x,&y,&z),add(x,y,z),add(y,x,-z);

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

	printf(ok==1?"No\n":"Yes\n");

	return 0;

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

#include <iostream>

#include <algorithm>

#include <cstring>

#include <queue>



using namespace std;



struct edge

{

    int v,w,nxt;

}e[400050];



const long long INF=1e12;



int head[100050],ecnt;



void add(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 dis[100005];

queue<int> que;

bool vis[100050],inq[100050];



bool spfa(int st)

{

    que.push(st);

    inq[st] = true;

    dis[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(dis[v] == INF)

            {

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

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

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

                if(curmax - curmin > 1000000000)

                    return false;

                vis[v] = 1;

                if(!inq[v])

                    que.push(v);

            }

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

                return false;

        }

        inq[u] = false;

    }

    return true;

}



int main()

{

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

        dis[i] = INF;

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

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

    {

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

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

        add(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.8219892470072347x):
#include <cstdio>

#include <cstring>

#include <iostream>

using namespace std;

const int mn=1e5+5,mm=4e5+5;

int dis[mn],vis[mn],nbs[mn],nxt[mm],ev[mm],ew[mm];

int n,m,ok,tot;



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

{

	nxt[++tot]=nbs[u],nbs[u]=tot,ev[tot]=v,ew[tot]=w;

}



void spfa(int i)

{

	vis[i]=1;

	for (int j=nbs[i];j!=0;j=nxt[j])

	{

		int v=ev[j],w=ew[j];

		if (dis[v]>dis[i]+w)

		{

			if ((vis[v]==1)||(ok==1)) return ok=1,void();

			dis[v]=dis[i]+w,spfa(v);

		}

	}

	vis[i]=0;

}



int main()

{

	int x,y,z;

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

	for (int i=1;i<=m;i++) scanf("%d%d%d",&x,&y,&z),add(x,y,z),add(y,x,-z);

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

	printf(ok==1?"No\n":"Yes\n");

	return 0;

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

#define repd(i,a,b) for (int i=(a);i<(b);i++)

#define rep(i,n) repd(i,0,n)

#define int long long

#define double long double

#define PI 3.141592653589793

typedef long long ll;

const int MOD = 1000000007;

const int INF = LLONG_MAX;

const double EPS = 1e-10;

using namespace std;

const pair<int,int> fd[] = {make_pair(1,0),make_pair(-1,0),make_pair(0,1),make_pair(0,-1)}; 



vector<int> divisor(int n){

  vector<int> ret;

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

    if(n%i == 0){

      ret.push_back(i);

      if(i*i != n)ret.push_back(n/i);

    }

  }

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

  return ret;

}



int n,m;vector<pair<int,int>> v[110000];

int inds[110000];



bool dfs(int ind, int node){

  if(inds[node] != INF)return (inds[node] == ind);

  inds[node] = ind;

  bool ret = true;

  rep(i,v[node].size()){

    ret = ret && dfs(ind+v[node][i].second, v[node][i].first);

  }

  return ret;

}



signed main(){

  cin>>n>>m;

  rep(i,m){

    int l,r,d;cin>>l>>r>>d;

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

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

  }

  rep(i,110000)inds[i] = INF;

  bool ans = true;

  repd(i,1,n+1){

    if(inds[i] == INF)ans = ans && dfs(0,i);

  }

  cout << (ans ? "Yes" : "No") << endl;

}




// Faster C++ solution for the same problem (measured speedup: 1.2591446140744542x):
//#define _GLIBCXX_DEBUG

#include <bits/stdc++.h>

using namespace std;

#define repd(i,a,b) for (int i=(a);i<(b);i++)

#define rep(i,n) repd(i,0,n)

typedef long long ll;

typedef long double lb;

#define int long long

#define double long double

#define endn "\n"

typedef pair<int,int> P;

template<class T> inline bool chmin(T& a, T b){if(a>b){a = b;return 1;}return 0;}

template<class T> inline bool chmax(T& a, T b){if(a<b){a = b;return 1;}return 0;}

const int MOD = 1000000007;

const ll INF = 1e16;

const double EPS = 1e-10;

const double PI = 3.141592653589793;

const string abc="abcdefghijklmnopqrstuvwxyz";

const string ABC="ABCDEFGHIJKLMNOPQRSTUVWXYZ";

const pair<int,int> fd[] = {make_pair(1,0),make_pair(-1,0),make_pair(0,1),make_pair(0,-1)}; 





////////////////////////////////////////////////////////////////////



int n,m;vector<P> v[110000];

bool visited[110000];

int d[110000], mx, mm;

bool dfs(int x){

  chmax(mx, d[x]);chmin(mm, d[x]);

  if(visited[x])return true;

  visited[x] = true;

  bool ret = true;

  rep(i,v[x].size()){

    int to = v[x][i].first, dis = v[x][i].second;

    if(d[to] == INF){

      d[to] = d[x] + dis;

      ret = ret && dfs(to);

    }else if(d[to] == d[x] + dis){

      ret = ret && dfs(to);

    }else{

      return false;

    }

  }

  return ret;

}

signed main(){

  cin>>n>>m;

  rep(i,m){

    int l, r, d;cin>>l>>r>>d;

    l--;r--;

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

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

  }

  rep(i,n)d[i] = INF;

  bool ans = true;

  rep(i,n){

    if(!visited[i]){

      d[i] = 0;mx = -INF, mm = INF;

      ans = ans && dfs(i);

      if(mx - mm > 1000000000)ans = false;

    }

  }

  cout << (ans ? "Yes" : "No") << endl;

}