stablegradients/pie-gem5-pairs huggingface dataset:
// 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: 3.664187859892025x):
#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");

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

#include<vector>

using namespace std;

int a,b,c,n,m,dis[100005];

bool vis[100005];

struct edge{

	int to,v;

	edge(int a=0,int b=0){to=a;v=b;}

};

vector<edge> path[200005];

bool spfa(int x){

	vis[x]=true;

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

		edge e=path[x][i];

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

			if(vis[e.to])return true;

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

			if(spfa(e.to))return true;

		}

	}

	vis[x]=false;

	return false;

}

int main(){

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

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

		scanf("%d%d%d",&a,&b,&c);//b-a=c

		path[b].push_back(edge(a,c));

		path[a].push_back(edge(b,-c));

	}

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

		dis[i]=-9999999;

		path[0].push_back(edge(i,0));

	}

	if(spfa(0))printf("No");

	else printf("Yes");

	return 0;

}

// Faster C++ solution for the same problem (measured speedup: 1.2464981920287659x):
#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;

}
// 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: 1.2639941559643395x):
#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;

}
// 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: 1.199168273175909x):
#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;

}
// 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: 1.3385310527180716x):
#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;

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

# include <cstdio>

# include <iostream>

# include <queue>

# define N 100050

# define M 200050 

# define WQD 0x7f7f7f7f

int n;

int m;

struct Edge{int next,to, w;}  e[M<<1];

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

{

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

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

	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;

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

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

	}

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

		if(!vis[i]) 

		{

			vis[i]=1;

			if(!spfa(i))  {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[v]=dis[k]+e[i].w;

				if( ! book[v])	{q.push(v);	book[v]=1;}

				vis[v]=1;

			}

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

		}		

    }

	return true;

}

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

#include<cstdio>

using namespace std;

struct Edge

{

	int to,next,cost;	

}e[400005];

int head[100005],cnt=0;

bool vis[100005];

int d[100005];

bool use[100005];

void addedge(int from,int to,int cost)

{

	e[++cnt].to=to;

	e[cnt].cost=cost;

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

	head[from]=cnt;

}

bool flag=0;

void dfs(int x)

{

	vis[x]=1;

	for(int i=head[x];i;i=e[i].next)

	{

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

		if(d[v]>d[x]+w)

		{

			d[v]=d[x]+w;

			if(vis[v])

			{

				flag=1;

				return;

			}

			dfs(v);	

		}	

	} 

	vis[x]=0;

	return;

}

inline int read()

{

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

	while(!isdigit(x))

	{

		if(x=='-') f=-1;

		x=getchar();

	}

	while(isdigit(x))

	{

		s=(s<<1)+(s<<3)+(x^48);

		x=getchar();

	}

	return s*f;

}

int main()

{

	int n,m;

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

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

	{

		int x,y,z;

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

		addedge(y,x,z);

		addedge(x,y,-z);

	}

	flag=0;

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

	{

		d[i]=0;

		if(!use[i])

		{

			use[i]=1;

			dfs(i);

		}	

	}

	if(flag) cout<<"No";

	else cout<<"Yes";

	return 0;

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

using namespace std;

typedef long long ll;

const int N=100005;

struct node

{

	int to;

	ll v;

	node(int a=0,int b=0){to=a;v=b;}

};

vector<node> path[N];

bool use[N];

ll d[N];

bool dfs(int o)

{

	use[o]=true;

	for(int i=path[o].size()-1;i>=0;i--)

	{

		node e=path[o][i];

		if(d[e.to]>d[o]+e.v)

		{

			if(use[e.to]) return true;

			d[e.to]=d[o]+e.v;

			if(dfs(e.to)) return true;

		}

	}

	use[o]=false;

	return false;

}

int main()

{

	int n,m,a,b;

	ll dd;

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

	while(m--)

	{

		scanf("%d%d%lld",&a,&b,&dd);

		path[a].push_back(node(b,dd));

		path[b].push_back(node(a,-dd));

	}

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

	{

		d[i]=LLONG_MAX;

		path[0].push_back(node(i,0));

	}

	if(dfs(0)) puts("No");

	else puts("Yes");

	return 0;

}

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

#include<cstdio>

using namespace std;

struct Edge

{

	int to,next,cost;	

}e[400005];

int head[100005],cnt=0;

bool vis[100005];

int d[100005];

bool use[100005];

void addedge(int from,int to,int cost)

{

	e[++cnt].to=to;

	e[cnt].cost=cost;

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

	head[from]=cnt;

}

bool flag=0;

void dfs(int x)

{

	vis[x]=1;

	for(int i=head[x];i;i=e[i].next)

	{

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

		if(d[v]>d[x]+w)

		{

			d[v]=d[x]+w;

			if(vis[v])

			{

				flag=1;

				return;

			}

			dfs(v);	

		}	

	} 

	vis[x]=0;

	return;

}

inline int read()

{

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

	while(!isdigit(x))

	{

		if(x=='-') f=-1;

		x=getchar();

	}

	while(isdigit(x))

	{

		s=(s<<1)+(s<<3)+(x^48);

		x=getchar();

	}

	return s*f;

}

int main()

{

	int n,m;

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

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

	{

		int x,y,z;

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

		addedge(y,x,z);

		addedge(x,y,-z);

	}

	flag=0;

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

	{

		d[i]=0;

		if(!use[i])

		{

			use[i]=1;

			dfs(i);

		}	

	}

	if(flag) cout<<"No";

	else cout<<"Yes";

	return 0;

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

#include<vector>

using namespace std;

int a,b,c,n,m,dis[100005];

bool vis[100005];

struct edge{

	int to,v;

	edge(int a=0,int b=0){to=a;v=b;}

};

vector<edge> path[200005];

bool spfa(int x){

	vis[x]=true;

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

		edge e=path[x][i];

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

			if(vis[e.to])return true;

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

			if(spfa(e.to))return true;

		}

	}

	vis[x]=false;

	return false;

}

int main(){

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

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

		scanf("%d%d%d",&a,&b,&c);//b-a=c

		path[b].push_back(edge(a,c));

		path[a].push_back(edge(b,-c));

	}

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

		dis[i]=-9999999;

		path[0].push_back(edge(i,0));

	}

	if(spfa(0))printf("No");

	else printf("Yes");

	return 0;

}

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

#include<cstdio>

using namespace std;

struct Edge

{

	int to,next,cost;	

}e[400005];

int head[100005],cnt=0;

bool vis[100005];

int d[100005];

bool use[100005];

void addedge(int from,int to,int cost)

{

	e[++cnt].to=to;

	e[cnt].cost=cost;

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

	head[from]=cnt;

}

bool flag=0;

void dfs(int x)

{

	vis[x]=1;

	for(int i=head[x];i;i=e[i].next)

	{

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

		if(d[v]>d[x]+w)

		{

			d[v]=d[x]+w;

			if(vis[v])

			{

				flag=1;

				return;

			}

			dfs(v);	

		}	

	} 

	vis[x]=0;

	return;

}

inline int read()

{

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

	while(!isdigit(x))

	{

		if(x=='-') f=-1;

		x=getchar();

	}

	while(isdigit(x))

	{

		s=(s<<1)+(s<<3)+(x^48);

		x=getchar();

	}

	return s*f;

}

int main()

{

	int n,m;

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

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

	{

		int x,y,z;

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

		addedge(y,x,z);

		addedge(x,y,-z);

	}

	flag=0;

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

	{

		d[i]=0;

		if(!use[i])

		{

			use[i]=1;

			dfs(i);

		}	

	}

	if(flag) cout<<"No";

	else cout<<"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];

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.824017782042927x):
#include<iostream>

#include<cstdio>

using namespace std;

struct Edge

{

	int to,next,cost;	

}e[400005];

int head[100005],cnt=0;

bool vis[100005];

int d[100005];

bool use[100005];

void addedge(int from,int to,int cost)

{

	e[++cnt].to=to;

	e[cnt].cost=cost;

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

	head[from]=cnt;

}

bool flag=0;

void dfs(int x)

{

	vis[x]=1;

	for(int i=head[x];i;i=e[i].next)

	{

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

		if(d[v]>d[x]+w)

		{

			d[v]=d[x]+w;

			if(vis[v])

			{

				flag=1;

				return;

			}

			dfs(v);	

		}	

	} 

	vis[x]=0;

	return;

}

inline int read()

{

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

	while(!isdigit(x))

	{

		if(x=='-') f=-1;

		x=getchar();

	}

	while(isdigit(x))

	{

		s=(s<<1)+(s<<3)+(x^48);

		x=getchar();

	}

	return s*f;

}

int main()

{

	int n,m;

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

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

	{

		int x,y,z;

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

		addedge(y,x,z);

		addedge(x,y,-z);

	}

	flag=0;

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

	{

		d[i]=0;

		if(!use[i])

		{

			use[i]=1;

			dfs(i);

		}	

	}

	if(flag) cout<<"No";

	else cout<<"Yes";

	return 0;

}
// 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: 6.565453311077421x):
#include<iostream>

#include<cstdio>

using namespace std;

struct Edge

{

	int to,next,cost;	

}e[400005];

int head[100005],cnt=0;

bool vis[100005];

int d[100005];

bool use[100005];

void addedge(int from,int to,int cost)

{

	e[++cnt].to=to;

	e[cnt].cost=cost;

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

	head[from]=cnt;

}

bool flag=0;

void dfs(int x)

{

	vis[x]=1;

	for(int i=head[x];i;i=e[i].next)

	{

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

		if(d[v]>d[x]+w)

		{

			d[v]=d[x]+w;

			if(vis[v])

			{

				flag=1;

				return;

			}

			dfs(v);	

		}	

	} 

	vis[x]=0;

	return;

}

inline int read()

{

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

	while(!isdigit(x))

	{

		if(x=='-') f=-1;

		x=getchar();

	}

	while(isdigit(x))

	{

		s=(s<<1)+(s<<3)+(x^48);

		x=getchar();

	}

	return s*f;

}

int main()

{

	int n,m;

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

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

	{

		int x,y,z;

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

		addedge(y,x,z);

		addedge(x,y,-z);

	}

	flag=0;

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

	{

		d[i]=0;

		if(!use[i])

		{

			use[i]=1;

			dfs(i);

		}	

	}

	if(flag) cout<<"No";

	else cout<<"Yes";

	return 0;

}