stablegradients/pie-gem5-pairs huggingface dataset:
// 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: 9.665303876209107x):
// SeptEtavioxy

#include<cstdio>

#include<cctype>

#include<cstring>

#include<algorithm>

#include<cmath>

#define re register

#define ll long long

#define il inline

#define rep(i,s,t) for(re int i=(s);i<=(t);i++)

#define rev_rep(i,s,t) for(re int i=(s);i>=(t);i--)

#define each(i,u) for(int i=head[u];i;i=bow[i].nxt)

#define pt(ch) putchar(ch)

#define pti(x) printf("%d",x)

#define ptll(x) printf("%lld",x)

#define file(s) freopen(s".in","r",stdin),freopen(s".out","w",stdout)

using namespace std;

// c_ints

il int ci(){

	re char ch;int f=1;

	while(!isdigit(ch=getchar()))f= ch=='-'?-1:1 ;

	re int x= ch^'0';

	while(isdigit(ch=getchar()))x=(x*10)+(ch^'0');

	return f*x;

}

enum{N=100024};

int fa[N],dis[N];

void fd(int x){

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

	fd(fa[x]);

	dis[x]+= dis[fa[x]];

	fa[x]= fa[fa[x]];

}

int main(){

	int n=ci(), m=ci();

	rep(i,1,n) fa[i]= i;

	while( m-- ){

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

		fd(l), fd(r);

		if( fa[l]==fa[r] ){

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

				puts("No");

				return 0;

			}

		}

		else{

			int fl=fa[l], fr=fa[r];

			int x= dis[l]+d-dis[r];

//			printf("%d %d\n",fl,fr);

//			if( x<0 ){

//				puts("No");

//				return 0;

//			}

			dis[fr]= x;

			fa[fr]= fl;

		}

//		printf("fa :");rep(i,1,n) printf("%d ",fa[i]); pt('\n');

//		printf("dis:");rep(i,1,n) printf("%d ",dis[i]); pt('\n');

	}

	puts("Yes");

	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: 7.530092909329576x):
// SeptEtavioxy

#include<cstdio>

#include<cctype>

#include<cstring>

#include<algorithm>

#include<cmath>

#define re register

#define ll long long

#define il inline

#define rep(i,s,t) for(re int i=(s);i<=(t);i++)

#define rev_rep(i,s,t) for(re int i=(s);i>=(t);i--)

#define each(i,u) for(int i=head[u];i;i=bow[i].nxt)

#define pt(ch) putchar(ch)

#define pti(x) printf("%d",x)

#define ptll(x) printf("%lld",x)

#define file(s) freopen(s".in","r",stdin),freopen(s".out","w",stdout)

using namespace std;

// c_ints

il int ci(){

	re char ch;int f=1;

	while(!isdigit(ch=getchar()))f= ch=='-'?-1:1 ;

	re int x= ch^'0';

	while(isdigit(ch=getchar()))x=(x*10)+(ch^'0');

	return f*x;

}

enum{N=100024};

int fa[N],dis[N];

void fd(int x){

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

	fd(fa[x]);

	dis[x]+= dis[fa[x]];

	fa[x]= fa[fa[x]];

}

int main(){

	int n=ci(), m=ci();

	rep(i,1,n) fa[i]= i;

	while( m-- ){

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

		fd(l), fd(r);

		if( fa[l]==fa[r] ){

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

				puts("No");

				return 0;

			}

		}

		else{

			int fl=fa[l], fr=fa[r];

			int x= dis[l]+d-dis[r];

//			printf("%d %d\n",fl,fr);

//			if( x<0 ){

//				puts("No");

//				return 0;

//			}

			dis[fr]= x;

			fa[fr]= fl;

		}

//		printf("fa :");rep(i,1,n) printf("%d ",fa[i]); pt('\n');

//		printf("dis:");rep(i,1,n) printf("%d ",dis[i]); pt('\n');

	}

	puts("Yes");

	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: 1.9683441258094356x):
#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;

}
// 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.5383530770387406x):
#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 <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.7933816990300218x):
#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<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.798042938856093x):
#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 <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.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:
//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.5966196928019927x):
#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<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.796519190233252x):
#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 <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.3996410862102986x):
#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;

}