stablegradients/pie-gem5-bysrc huggingface dataset:
// Original C++ solution (slower):
#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;

}

// Optimized solution to the same problem (faster):
#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");

}

// Fastest known solution for this problem:
// Original C++ solution (slower):
#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;

}




// Optimized solution to the same problem (faster):
#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");

}

// Fastest known solution for this problem:
// Original C++ solution (slower):
#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;

}

// Optimized solution to the same problem (faster):
#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");

}

// Fastest known solution for this problem:
// Original C++ solution (slower):
#include<iostream>

#include<vector>

using namespace std;



int par[100001];

int dist[100001];



void init_union_find() {

    fill(par, par+100001, -1);

    fill(dist, dist+100001, 0);

}



int root(int x) {

    if(par[x] < 0) return x;

    int r = root(par[x]);

    dist[x] += dist[par[x]];

    return par[x] = r;

}



bool same(int x, int y) {

    return root(x) == root(y);

}



int weight(int x) {

    root(x);

    return dist[x];

}



int diff(int x, int y) {

    return weight(y) - weight(x);

}



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

    w += weight(x);

    w -= weight(y);

    x = root(x);

    y = root(y);

    if(x == y) return;

    if(par[y] < par[x]) swap(x, y), w = -w;

    par[x] += par[y];

    par[y] = x;

    dist[y] = w;

}



int main() {

    int N, M;

    cin >> N >> M;

    init_union_find();

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

        int l, r, d;

        cin >> l >> r >> d;

        if(same(l, r)) {

            if((diff(l, r)) != d) {

                cout << "No" << endl;

                return 0;

            }

        } else {

            unite(l, r, d);

        }

    }



    cout << "Yes" << endl;



    return 0;

}


// Optimized solution to the same problem (faster):
#include<iostream>

#include<vector>

using namespace std;



#include<iostream>

#include<vector>

#include<utility>

#include<algorithm>



template<class T> struct UnionFind{

    std::vector<int> par;

    std::vector<T> diff_weight;



    UnionFind(int size = 1, T SUM_UNITY = 0){

        init(size, SUM_UNITY);

    }



    void init(int size = 1, T SUM_UNITY = 0) {

        par.resize(size);

        diff_weight.resize(size);

        fill(par.begin(), par.end(), -1);

        fill(diff_weight.begin(), diff_weight.end(), SUM_UNITY);

    }



    int root(int x) {

        if(par[x] < 0) return x;

        int r = root(par[x]);

        diff_weight[x] += diff_weight[par[x]];

        return par[x] = r;

    }



    bool issame(int x, int y) {

        return root(x) == root(y);

    }



    int weight(int x) {

        root(x); // 経路圧縮と重み計算

        return diff_weight[x];

    }



    int diff(int x, int y) {

        return weight(y) - weight(x);

    }



    bool unite(int x, int y, int w) {

        w += weight(x);

        w -= weight(y);

        x = root(x);

        y = root(y);

        if(x == y) return false;



        if(par[y] < par[x]) std::swap(x, y), w = -w; // yの方が気が深いなら交換

        par[x] += par[y];

        par[y] = x;

        diff_weight[y] = w;



        return true;

    }



    int size(int x) {

        return -par[root(x)];

    }

};



int main() {

    int N, M;

    cin >> N >> M;

    UnionFind<int> uf(N);

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

        int l, r, d;

        cin >> l >> r >> d;

        l--; r--;

        if(uf.issame(l, r)) {

            if((uf.diff(l, r)) != d) {

                cout << "No" << endl;

                return 0;

            }

        } else {

            uf.unite(l, r, d);

        }

    }



    cout << "Yes" << endl;



    return 0;

}


// Fastest known solution for this problem:
// Original C++ solution (slower):
#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));

}

// Optimized solution to the same problem (faster):
// 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;

}

// Fastest known solution for this problem:
// Original C++ solution (slower):
#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");

}


// Optimized solution to the same problem (faster):
// 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;

}

// Fastest known solution for this problem:
// Original C++ solution (slower):
//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;

}

// Optimized solution to the same problem (faster):
// 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;

}

// Fastest known solution for this problem:
// Original C++ solution (slower):
#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;

}

// Optimized solution to the same problem (faster):
// 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;

}

// Fastest known solution for this problem: