stablegradients/pie-gem5-pairs huggingface dataset:
// 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: 18.994387332565175x):
#include <cstdio>

#include <cstdlib>

#include <cstring>

#include <algorithm>



using namespace std;

#define N 100010



inline int read(){

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

	for (;c<'0'||c>'9';){if(c=='-')sign=-1;c=getchar();}

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

	return x*sign;

}



int n,m,Max,Min,en,vis[N];

struct edge{

	int e,d;

	edge *next;

}*v[N],ed[N<<2];



inline void add_edge(int s,int e,int d){

	ed[++en].next = v[s];

	v[s] = ed + en;

	v[s] -> e = e;

	v[s] -> d = d;

}



int dis[N];



inline int dfs(int u){

	Max = max(Max,dis[u]);

	Min = min(Min,dis[u]);

	vis[u] = 1;

	int mark = 1;

	for (edge *e=v[u];e;e=e->next)

		if (!vis[e->e]) {dis[e->e]=dis[u]+e->d;mark&=dfs(e->e);}

		else mark&=(dis[e->e]==dis[u]+e->d);

	return mark;

}



int main()

{

	n = read();

	m = read();

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

		int x,y,z;

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

		add_edge(x,y,z);

		add_edge(y,x,-z);

	}

	Max = 0; Min = 0;

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

		if (!vis[i]){

			dis[i] = 0;

			if (!dfs(i)){

				printf("No");

				return 0;

			}

		}

		if (Max-Min>1e9){

			printf("No");

			return 0;

		}

	}

	printf("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.9678913114777032x):
#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");

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



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;

}
// 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.590294686656151x):
#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<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.8244374908897658x):
#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 <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: 2.2161527212714613x):
//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;

}
// 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.1261560576774623x):
//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;

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

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

}