stablegradients/pie-gem5-pairs huggingface dataset:
// Slower C++ solution:
#include<bits/stdc++.h>

using namespace std;

int n,m,dis[200001],l,r,d;

bool Error,f[200001];

struct edge {

	int to,cost;

	edge(int a=0,int b=0) {

		to=a;

		cost=b;

	}

};

vector<edge> path[200001];

void spfa(int x) {

	for(int i=0; i<path[x].size(); i++) {

		edge e=path[x][i];

		if(f[e.to])

			if(e.cost+dis[x]!=dis[e.to]) {

				Error=true;

				return;

			} else continue;

		f[e.to]=true;

		dis[e.to]=dis[x]+e.cost;

		spfa(e.to);

		if(Error) return;

	}

}

int main() {

	cin>>n>>m;

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

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

		path[l].push_back(edge(r,d));

		path[r].push_back(edge(l,-d));

	}

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

		if(!f[i]) {

			spfa(i);

			if(Error) break;

		}

	}

	if(!Error) printf("Yes");

	else printf("No");

	return 0;

}

// Faster C++ solution for the same problem (measured speedup: 7.0292144929340346x):
#pragma GCC optimize(3,"Ofast","inline")

#pragma GCC optimize(2)

#include<cstring>

#include<cstdio>

#include<queue>

#define Re register int

using namespace std;

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

int x,y,z,n,m,o,op,dis[N],vis[N],pan[N],head[N];

struct QAQ{int w,to,next;}a[M];queue<int>Q;

inline void add(Re x,Re y,Re z){a[++o].to=y,a[o].w=z,a[o].next=head[x],head[x]=o;}

inline void in(Re &x){

	Re fu=0;x=0;char ch=getchar();

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

	while(ch>='0'&&ch<='9')x=(x<<1)+(x<<3)+(ch^48),ch=getchar();

	x=fu?-x:x;

}

inline int SPFA(Re st){

	dis[st]=0,pan[st]=1,Q.push(st);

	while(!Q.empty()){

		x=Q.front(),Q.pop();pan[x]=0,vis[x]=1;

		for(Re i=head[x],to;i;i=a[i].next)

			if(dis[to=a[i].to]==inf){

				dis[to]=dis[x]+a[i].w;

				if(!pan[to])pan[to]=1,Q.push(to);

			}

			else if(dis[to]!=dis[x]+a[i].w)return 1;

	}

	return 0;

}

int main(){

	in(n),in(m);

	for(Re i=0;i<=n;++i)dis[i]=inf;

	while(m--)in(x),in(y),in(z),add(x,y,z),add(y,x,-z);//a[y]-a[x]==z: a[y]-a[x]>=z且a[x]-a[y]>=-z 

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

		if(!vis[i])if(SPFA(i))return !puts("No");

	puts("Yes");

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

#include<iostream>

#include<cstring>

using namespace std;

struct node_ {

	int v,c,next;

} node[3000001];

int head[1000001],e;

void addnode(int u,int v,int c) {

	e++;

	node[e].c=c;

	node[e].v=v;

	node[e].next=head[u];

	head[u]=e;

}

int n,m;

bool b[1000001],flag;

int d[1000001];

int L,R,D;

bool dfs(int x) {

	b[x]=1;

	for(int i=head[x]; i!=0; i=node[i].next) {

		int y=node[i].v,c=node[i].c;

		if(d[y]>d[x]+c) {

			if(b[y]) return 1;

			d[y]=d[x]+c;

			if(dfs(y))return 1;

		}

	}

	b[x]=0;

	return 0;

}

int main() {

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

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

		scanf("%d%d%d",&L,&R,&D);

		addnode(R,L,D);

		addnode(L,R,-D);

	}

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

		addnode(0,i,0);

	}

	memset(b,0,sizeof(b));

	memset(d,1000000,sizeof(d));

	d[0]=0;

	if(dfs(0)) printf("No\n");

	else printf("Yes\n");

	return 0;

}

// Faster C++ solution for the same problem (measured speedup: 6.66871042520278x):
#pragma GCC optimize(3,"Ofast","inline")

#pragma GCC optimize(2)

#include<cstring>

#include<cstdio>

#include<queue>

#define Re register int

using namespace std;

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

int x,y,z,n,m,o,op,dis[N],vis[N],pan[N],head[N];

struct QAQ{int w,to,next;}a[M];queue<int>Q;

inline void add(Re x,Re y,Re z){a[++o].to=y,a[o].w=z,a[o].next=head[x],head[x]=o;}

inline void in(Re &x){

	Re fu=0;x=0;char ch=getchar();

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

	while(ch>='0'&&ch<='9')x=(x<<1)+(x<<3)+(ch^48),ch=getchar();

	x=fu?-x:x;

}

inline int SPFA(Re st){

	dis[st]=0,pan[st]=1,Q.push(st);

	while(!Q.empty()){

		x=Q.front(),Q.pop();pan[x]=0,vis[x]=1;

		for(Re i=head[x],to;i;i=a[i].next)

			if(dis[to=a[i].to]==inf){

				dis[to]=dis[x]+a[i].w;

				if(!pan[to])pan[to]=1,Q.push(to);

			}

			else if(dis[to]!=dis[x]+a[i].w)return 1;

	}

	return 0;

}

int main(){

	in(n),in(m);

	for(Re i=0;i<=n;++i)dis[i]=inf;

	while(m--)in(x),in(y),in(z),add(x,y,z),add(y,x,-z);//a[y]-a[x]==z: a[y]-a[x]>=z且a[x]-a[y]>=-z 

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

		if(!vis[i])if(SPFA(i))return !puts("No");

	puts("Yes");

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

using namespace std;

const int MAXN=100007;

typedef long long ll;

struct node {

    int v,w;

    node(int x=0,int y=0) {

        v=x,w=y;

    }

};

int deg[MAXN],X,n,m,x1,x2,y,tot[MAXN];

ll pos[MAXN];

bool vis[MAXN];

char c;

vector<node> edge[MAXN];

inline char nc(){

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

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

}

int read() {

    X=0,c=nc();

    while(!isdigit(c))c=nc();

    while(isdigit(c))X=(X<<1)+(X<<3)+c-'0',c=nc();

    return X;

}

bool ok;

bool check(int &u) {

    vis[u]=true;

    for(int i=0; i<tot[u]; i++) {

        if(vis[edge[u][i].v]) {

            if(pos[edge[u][i].v]-edge[u][i].w!=pos[u])return false;

        } else {

            pos[edge[u][i].v]=pos[u]+edge[u][i].w;

            if(!check(edge[u][i].v))return false;

            else continue;

        }

    }

    return true;

}

int main() {

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

        if(!m){

            puts("Yes");

            return 0;

        }

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

            x1=read(),x2=read(),y=read();

            tot[x1]++;

            deg[x2]++;

            edge[x1].push_back(node(x2,y));

        }

        for(int i=0; i<n; i++)if(!deg[i]&&tot[i]) {

                ok=1;

                if(!check(i)) {

                    puts("No");

                    return 0;

                }

            };

        if(!ok) {

            puts("No");

            return 0;

        }

        puts("Yes");

        return 0;

}

// Faster C++ solution for the same problem (measured speedup: 3.8209627444699654x):
#pragma GCC optimize(3,"Ofast","inline")

#pragma GCC optimize(2)

#include<cstring>

#include<cstdio>

#include<queue>

#define Re register int

using namespace std;

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

int x,y,z,n,m,o,op,dis[N],vis[N],pan[N],head[N];

struct QAQ{int w,to,next;}a[M];queue<int>Q;

inline void add(Re x,Re y,Re z){a[++o].to=y,a[o].w=z,a[o].next=head[x],head[x]=o;}

inline void in(Re &x){

	Re fu=0;x=0;char ch=getchar();

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

	while(ch>='0'&&ch<='9')x=(x<<1)+(x<<3)+(ch^48),ch=getchar();

	x=fu?-x:x;

}

inline int SPFA(Re st){

	dis[st]=0,pan[st]=1,Q.push(st);

	while(!Q.empty()){

		x=Q.front(),Q.pop();pan[x]=0,vis[x]=1;

		for(Re i=head[x],to;i;i=a[i].next)

			if(dis[to=a[i].to]==inf){

				dis[to]=dis[x]+a[i].w;

				if(!pan[to])pan[to]=1,Q.push(to);

			}

			else if(dis[to]!=dis[x]+a[i].w)return 1;

	}

	return 0;

}

int main(){

	in(n),in(m);

	for(Re i=0;i<=n;++i)dis[i]=inf;

	while(m--)in(x),in(y),in(z),add(x,y,z),add(y,x,-z);//a[y]-a[x]==z: a[y]-a[x]>=z且a[x]-a[y]>=-z 

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

		if(!vis[i])if(SPFA(i))return !puts("No");

	puts("Yes");

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

#define base 200000

#define inf 0x3f3f3f3f

using namespace std;

int n,m,x,y,w,ans,maxn,minn,dist[100010],vi[100010];

vector<int> g[100010],l[100010];

queue<int> q;

bool flag=false;



bool spfa(int s){

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

	dist[s]=0,maxn=minn=0,q.push(s),vi[s]=1;

	while(!q.empty()){

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

		for(int i=0;i<g[u].size();i++){

			int v=g[u][i];

			if(!vi[v]){

				dist[v]=dist[u]+l[u][i];

				q.push(v),vi[v]=1;

				maxn=max(maxn,dist[v]),minn=min(minn,dist[v]);

			}

			else if(dist[v]!=dist[u]+l[u][i]) return true;

		}

	}

	return false;

}



int main(){

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

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

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

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

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

		g[x].push_back(y),l[x].push_back(w),g[y].push_back(x),l[y].push_back(-w);

	}

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

		if(!vi[i]){

			flag=spfa(i);

			if(flag){

//				printf("impossible");

				printf("No");

				return 0;

			}

			ans=max(ans,maxn-minn);

		}

	}

//	printf("%d",ans);

	printf("Yes");

}

// Faster C++ solution for the same problem (measured speedup: 7.443722607902283x):
#pragma GCC optimize(3,"Ofast","inline")

#pragma GCC optimize(2)

#include<cstring>

#include<cstdio>

#include<queue>

#define Re register int

using namespace std;

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

int x,y,z,n,m,o,op,dis[N],vis[N],pan[N],head[N];

struct QAQ{int w,to,next;}a[M];queue<int>Q;

inline void add(Re x,Re y,Re z){a[++o].to=y,a[o].w=z,a[o].next=head[x],head[x]=o;}

inline void in(Re &x){

	Re fu=0;x=0;char ch=getchar();

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

	while(ch>='0'&&ch<='9')x=(x<<1)+(x<<3)+(ch^48),ch=getchar();

	x=fu?-x:x;

}

inline int SPFA(Re st){

	dis[st]=0,pan[st]=1,Q.push(st);

	while(!Q.empty()){

		x=Q.front(),Q.pop();pan[x]=0,vis[x]=1;

		for(Re i=head[x],to;i;i=a[i].next)

			if(dis[to=a[i].to]==inf){

				dis[to]=dis[x]+a[i].w;

				if(!pan[to])pan[to]=1,Q.push(to);

			}

			else if(dis[to]!=dis[x]+a[i].w)return 1;

	}

	return 0;

}

int main(){

	in(n),in(m);

	for(Re i=0;i<=n;++i)dis[i]=inf;

	while(m--)in(x),in(y),in(z),add(x,y,z),add(y,x,-z);//a[y]-a[x]==z: a[y]-a[x]>=z且a[x]-a[y]>=-z 

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

		if(!vis[i])if(SPFA(i))return !puts("No");

	puts("Yes");

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

{

    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.570044373869969x):
#pragma GCC optimize(3,"Ofast","inline")

#pragma GCC optimize(2)

#include<cstring>

#include<cstdio>

#include<queue>

#define Re register int

using namespace std;

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

int x,y,z,n,m,o,op,dis[N],vis[N],pan[N],head[N];

struct QAQ{int w,to,next;}a[M];queue<int>Q;

inline void add(Re x,Re y,Re z){a[++o].to=y,a[o].w=z,a[o].next=head[x],head[x]=o;}

inline void in(Re &x){

	Re fu=0;x=0;char ch=getchar();

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

	while(ch>='0'&&ch<='9')x=(x<<1)+(x<<3)+(ch^48),ch=getchar();

	x=fu?-x:x;

}

inline int SPFA(Re st){

	dis[st]=0,pan[st]=1,Q.push(st);

	while(!Q.empty()){

		x=Q.front(),Q.pop();pan[x]=0,vis[x]=1;

		for(Re i=head[x],to;i;i=a[i].next)

			if(dis[to=a[i].to]==inf){

				dis[to]=dis[x]+a[i].w;

				if(!pan[to])pan[to]=1,Q.push(to);

			}

			else if(dis[to]!=dis[x]+a[i].w)return 1;

	}

	return 0;

}

int main(){

	in(n),in(m);

	for(Re i=0;i<=n;++i)dis[i]=inf;

	while(m--)in(x),in(y),in(z),add(x,y,z),add(y,x,-z);//a[y]-a[x]==z: a[y]-a[x]>=z且a[x]-a[y]>=-z 

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

		if(!vis[i])if(SPFA(i))return !puts("No");

	puts("Yes");

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

using namespace std;

inline void fff(){

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

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

}

const int N=1e5+10;

const int INF=0x3f3f3f3f;

inline int read(){

	int x=0,m=1;char ch=getchar();

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

	if(ch=='-') ch=getchar(),m=-1;

	while(ch<='9'&&ch>='0') 

		x=x*10+ch-'0',ch=getchar();

	return x*m;

}

int n,m;

struct Edge{

	int nxt;

	int to,w;

}edge[N<<2];

int head[N],tot=0;

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

	edge[++tot].nxt=head[u];

	edge[tot].to=v;

	edge[tot].w=w;

	head[u]=tot;

}

bool visited[N];

int dist[N],ans,minn,maxx;

queue<int> q;

inline bool SPFA(int str){

	

	q.push(str);

	if(m) minn=INF,maxx=0;

	dist[str]=0;visited[str]=true;

	while(!q.empty()){

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

		visited[u]=false;

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

			Edge e=edge[i];

			if(dist[e.to]<INF){

				if(dist[e.to]!=e.w+dist[u]){

					return false;

				}

				minn=min(minn,dist[e.to]);

				maxx=max(maxx,dist[e.to]);

			}else{

				dist[e.to]=dist[u]+e.w;

				minn=min(minn,dist[e.to]);

				maxx=max(maxx,dist[e.to]);

				if(!visited[e.to]){

					visited[e.to]=true;

					q.push(e.to);

				}

			}

		}

	}

	ans=min(ans,maxx-minn);

	return true;

}

int main(){

//	fff();

	n=read();

	m=read();

	ans=INF;

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

		int u,v,w;

		u=read(),v=read(),w=read();

		add(u,v,w);

		add(v,u,-w);

	}

	memset(dist,INF,sizeof(dist));

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

		if(dist[i]<INF)  continue;

		if(!SPFA(i)){

			printf("No");

			return 0;

		}

	}

	printf("Yes");

}

// Faster C++ solution for the same problem (measured speedup: 1.52013067747954x):
#pragma GCC optimize(3,"Ofast","inline")

#pragma GCC optimize(2)

#include<cstring>

#include<cstdio>

#include<queue>

#define Re register int

using namespace std;

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

int x,y,z,n,m,o,op,dis[N],vis[N],pan[N],head[N];

struct QAQ{int w,to,next;}a[M];queue<int>Q;

inline void add(Re x,Re y,Re z){a[++o].to=y,a[o].w=z,a[o].next=head[x],head[x]=o;}

inline void in(Re &x){

	Re fu=0;x=0;char ch=getchar();

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

	while(ch>='0'&&ch<='9')x=(x<<1)+(x<<3)+(ch^48),ch=getchar();

	x=fu?-x:x;

}

inline int SPFA(Re st){

	dis[st]=0,pan[st]=1,Q.push(st);

	while(!Q.empty()){

		x=Q.front(),Q.pop();pan[x]=0,vis[x]=1;

		for(Re i=head[x],to;i;i=a[i].next)

			if(dis[to=a[i].to]==inf){

				dis[to]=dis[x]+a[i].w;

				if(!pan[to])pan[to]=1,Q.push(to);

			}

			else if(dis[to]!=dis[x]+a[i].w)return 1;

	}

	return 0;

}

int main(){

	in(n),in(m);

	for(Re i=0;i<=n;++i)dis[i]=inf;

	while(m--)in(x),in(y),in(z),add(x,y,z),add(y,x,-z);//a[y]-a[x]==z: a[y]-a[x]>=z且a[x]-a[y]>=-z 

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

		if(!vis[i])if(SPFA(i))return !puts("No");

	puts("Yes");

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

#include<cstring>

#include<iostream>

#include<algorithm>

#define int long long

using namespace std;

const int Top=6666666666666666;

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]==Top)

            {

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

{

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

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

        dis[i]=Top;

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

    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.5611131268017875x):
#pragma GCC optimize(3,"Ofast","inline")

#pragma GCC optimize(2)

#include<cstring>

#include<cstdio>

#include<queue>

#define Re register int

using namespace std;

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

int x,y,z,n,m,o,op,dis[N],vis[N],pan[N],head[N];

struct QAQ{int w,to,next;}a[M];queue<int>Q;

inline void add(Re x,Re y,Re z){a[++o].to=y,a[o].w=z,a[o].next=head[x],head[x]=o;}

inline void in(Re &x){

	Re fu=0;x=0;char ch=getchar();

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

	while(ch>='0'&&ch<='9')x=(x<<1)+(x<<3)+(ch^48),ch=getchar();

	x=fu?-x:x;

}

inline int SPFA(Re st){

	dis[st]=0,pan[st]=1,Q.push(st);

	while(!Q.empty()){

		x=Q.front(),Q.pop();pan[x]=0,vis[x]=1;

		for(Re i=head[x],to;i;i=a[i].next)

			if(dis[to=a[i].to]==inf){

				dis[to]=dis[x]+a[i].w;

				if(!pan[to])pan[to]=1,Q.push(to);

			}

			else if(dis[to]!=dis[x]+a[i].w)return 1;

	}

	return 0;

}

int main(){

	in(n),in(m);

	for(Re i=0;i<=n;++i)dis[i]=inf;

	while(m--)in(x),in(y),in(z),add(x,y,z),add(y,x,-z);//a[y]-a[x]==z: a[y]-a[x]>=z且a[x]-a[y]>=-z 

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

		if(!vis[i])if(SPFA(i))return !puts("No");

	puts("Yes");

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

const int N=1e6+10;

using namespace std;



inline int read(){

	char ch=getchar();int x=0,f=1;

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

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

	return x*f;

} 



struct node{

	int v,nxt,w;

}e[N<<1];

int head[N],cnt;

int dis[N],n,m,INF;

bool used[N],vis[N];



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

	e[++cnt].v=v;

	e[cnt].w=w;

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

	head[u]=cnt;

}



bool spfa(int s){

	queue<int> q;

	q.push(s);

	vis[s]=true;

	dis[s]=0;

	while(!q.empty()){

		int u=q.front();

		q.pop();vis[u]=false;

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

			int v=e[i].v,w=e[i].w;

			if(dis[v]==INF){

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

				used[v]=true;

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

			}

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

		}

	}

	return true;

}



int main(){

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

	INF=dis[1];

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

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

		int x=read(),y=read(),z=read();

		add(x,y,z);add(y,x,-z);

	}

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

		if(!used[i]){

			used[i]=true;

			if(!spfa(i)){

				printf("No");

				return 0;

			}

		}

	}

	printf("Yes");

	return 0;

}




// Faster C++ solution for the same problem (measured speedup: 5.52017014790784x):
#pragma GCC optimize(3,"Ofast","inline")

#pragma GCC optimize(2)

#include<cstring>

#include<cstdio>

#include<queue>

#define Re register int

using namespace std;

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

int x,y,z,n,m,o,op,dis[N],vis[N],pan[N],head[N];

struct QAQ{int w,to,next;}a[M];queue<int>Q;

inline void add(Re x,Re y,Re z){a[++o].to=y,a[o].w=z,a[o].next=head[x],head[x]=o;}

inline void in(Re &x){

	Re fu=0;x=0;char ch=getchar();

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

	while(ch>='0'&&ch<='9')x=(x<<1)+(x<<3)+(ch^48),ch=getchar();

	x=fu?-x:x;

}

inline int SPFA(Re st){

	dis[st]=0,pan[st]=1,Q.push(st);

	while(!Q.empty()){

		x=Q.front(),Q.pop();pan[x]=0,vis[x]=1;

		for(Re i=head[x],to;i;i=a[i].next)

			if(dis[to=a[i].to]==inf){

				dis[to]=dis[x]+a[i].w;

				if(!pan[to])pan[to]=1,Q.push(to);

			}

			else if(dis[to]!=dis[x]+a[i].w)return 1;

	}

	return 0;

}

int main(){

	in(n),in(m);

	for(Re i=0;i<=n;++i)dis[i]=inf;

	while(m--)in(x),in(y),in(z),add(x,y,z),add(y,x,-z);//a[y]-a[x]==z: a[y]-a[x]>=z且a[x]-a[y]>=-z 

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

		if(!vis[i])if(SPFA(i))return !puts("No");

	puts("Yes");

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

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

#define inf 0x3f3f3f3f

#define N 100010

#define M 200010

using namespace std;



struct edge{

	int to,nxt,w;

}e[M << 2];

int h[N],dis[N],vis[N];

int tot,n,m;



inline int read(){

	int x = 0,f = 1;char c = getchar();

	while(!isdigit(c)){if(c == '-')f = -1;c = getchar();}

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

	return f * x;

}



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

	e[++tot] = (edge){y,h[x],z};

	h[x] = tot;

}



inline int spfa(int s){

	queue<int>q;

	q.push(s);vis[s] = 1;dis[s] = 0;

	while(q.size()){

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

		for(register int i = h[x];i;i = e[i].nxt){

			int p = e[i].to;

			if(dis[p] == inf){

				dis[p] = dis[x] + e[i].w;

				if(!vis[p])vis[p] = 1,q.push(p);

			}

			else if(dis[p] != dis[x] + e[i].w)return 0;

		}

	}

	return 1;

}



int main(){

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

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

	fr(i,1,m){

		int x = read(),y = read(),z = read();

		add(x,y,z);add(y,x,-z);

	}

	memset(dis,inf,sizeof(dis));

	memset(vis,0,sizeof(vis));

	fr(i,1,n)

		if(!vis[i]){

			int x = spfa(i);

			if(!x){printf("No");return 0;}

		}

	printf("Yes");

	return 0;

}

// Faster C++ solution for the same problem (measured speedup: 1.9491478182720758x):
#pragma GCC optimize(3,"Ofast","inline")

#pragma GCC optimize(2)

#include<cstring>

#include<cstdio>

#include<queue>

#define Re register int

using namespace std;

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

int x,y,z,n,m,o,op,dis[N],vis[N],pan[N],head[N];

struct QAQ{int w,to,next;}a[M];queue<int>Q;

inline void add(Re x,Re y,Re z){a[++o].to=y,a[o].w=z,a[o].next=head[x],head[x]=o;}

inline void in(Re &x){

	Re fu=0;x=0;char ch=getchar();

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

	while(ch>='0'&&ch<='9')x=(x<<1)+(x<<3)+(ch^48),ch=getchar();

	x=fu?-x:x;

}

inline int SPFA(Re st){

	dis[st]=0,pan[st]=1,Q.push(st);

	while(!Q.empty()){

		x=Q.front(),Q.pop();pan[x]=0,vis[x]=1;

		for(Re i=head[x],to;i;i=a[i].next)

			if(dis[to=a[i].to]==inf){

				dis[to]=dis[x]+a[i].w;

				if(!pan[to])pan[to]=1,Q.push(to);

			}

			else if(dis[to]!=dis[x]+a[i].w)return 1;

	}

	return 0;

}

int main(){

	in(n),in(m);

	for(Re i=0;i<=n;++i)dis[i]=inf;

	while(m--)in(x),in(y),in(z),add(x,y,z),add(y,x,-z);//a[y]-a[x]==z: a[y]-a[x]>=z且a[x]-a[y]>=-z 

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

		if(!vis[i])if(SPFA(i))return !puts("No");

	puts("Yes");

}