stablegradients/pie-gem5-pairs huggingface dataset:
// Slower C++ solution:
#include <iostream>

#include <vector>

using namespace std;

 

int n,m; //input intergers:n,m

vector<pair<int,int> > e[100010]; //the vector array of DFS

long long pos[100010]; //the positions of each person 

bool vis[100010]; //the bool array of DFS to know each person has visited or not

 

inline void dfs(int x) //DFS

{

	vis[x]=1; //visited this person(x)

	for(int i=0;i<e[x].size();i++) //visit the person who has relation of this person(x)

	{

		pair<int,int> cur=e[x][i];

		if(vis[cur.first]) //if(this person(e[x][i])'s position has known)

		{

			if(pos[cur.first]-pos[x]!=cur.second) {cout<<"No";exit(0);} //if this person(e[x][i]) is wrongful then exit

		}

		else //if this person(e[x][i])'s position hasn't known then take notes and DFS

		{

			pos[cur.first]=pos[x]+cur.second;

			dfs(cur.first);

		}

	}

}

 

int main()

{

	cin>>n>>m; //input

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

	{

		int l,r,d;

		cin>>l>>r>>d; //input

		e[l].push_back({r,d}); //take notes

		e[r].push_back({l,-d}); //take notes

	}

	

	for(int i=0;i<n;i++) if(!vis[i]) dfs(i); //DFS

	

	cout<<"Yes"; //if every one isn't wrongful then print 'Yes'

	

	return 0; //END

}

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

#include <queue>

#include <stdio.h>

using namespace std;

int f=0;

int seedis(int x,int *arr,long long *dis)

{

    if(arr[x]==0) return dis[x];

    else return seedis(arr[x],arr,dis) + dis[x];

}

int seef(int l,int *arr,long long *dis)

{

    if(arr[l]==0) return l;

    int a1=arr[l];

    int a2=seef(arr[l],arr,dis);

    arr[l]=a2;

    dis[l]=dis[l]+dis[a1];

    return a2;

}

void hebing(int l,int r,int d,int *arr,long long *dis)

{

    int lf=seef(l,arr,dis);

    int rf=seef(r,arr,dis);

    if(rf==lf)

    {

        if(seedis(r,arr,dis)-seedis(l,arr,dis)!=d)

            f=1;

        return;

    }

    arr[rf]=lf;

    dis[rf]=seedis(l,arr,dis)+d-seedis(r,arr,dis);

}

int main()

{

    int n,m;

    int arr[100500];

    long long dis[100500];

    cin>>n>>m;

    int l,r,d;

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

    {

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

        hebing(l,r,d,arr,dis);

        if(f==1) break;

    }

    if(f) cout<<"No";

    else cout<<"Yes";

    return 0;

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

#include <vector>

using namespace std;

 

int n,m; //input intergers:n,m

vector<pair<int,int> > e[100010]; //the vector array of DFS

long long pos[100010]; //the positions of each person 

bool vis[100010]; //the bool array of DFS to know each person has visited or not

 

inline void dfs(int x) //DFS

{

	vis[x]=1; //visited this person(x)

	for(int i=0;i<e[x].size();i++) //visit the person who has relation of this person(x)

	{

		pair<int,int> cur=e[x][i];

		if(vis[cur.first]) //if(this person(e[x][i])'s position has known)

		{

			if(pos[cur.first]-pos[x]!=cur.second) {cout<<"No";exit(0);} //if this person(e[x][i]) is wrongful then exit

		}

		else //if this person(e[x][i])'s position hasn't known then take notes and DFS

		{

			pos[cur.first]=pos[x]+cur.second;

			dfs(cur.first);

		}

	}

}

 

int main()

{

	cin>>n>>m; //input

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

	{

		int l,r,d;

		cin>>l>>r>>d; //input

		e[l].push_back({r,d}); //take notes

		e[r].push_back({l,-d}); //take notes

	}

	

	for(int i=0;i<n;i++) if(!vis[i]) dfs(i); //DFS

	

	cout<<"Yes"; //if every one isn't wrongful then print 'Yes'

	

	return 0; //END

}

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

#include <cstdio>

#include <map>

#include <algorithm>

#include <cstring>

#include <string>

#include <cmath>



using namespace std;



const int N = 1e5+5;

int n,m;

int fa[N],r[N];



void init()

{

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

    {

        fa[i] = i;

    }

    memset(r,0,sizeof(r));

}



int Find(int x)

{

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

    int root = Find(fa[x]);

    r[x] += r[fa[x]];

    return fa[x] = root;

}



bool Merge(int x, int y, int d)

{

    int fx = Find(x);

    int fy = Find(y);

    if(fx==fy)

    {

        return d == r[y]-r[x];

    }

    fa[fy] = fx;

    r[fy] = r[x] + d - r[y];

    return 1;

}



int main()

{

    while(scanf("%d%d",&n,&m) != EOF)

    {

        int ok = 1;

        int L,R,D;

        init();

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

        {

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

            if(ok && !Merge(L,R,D))

            {

                ok = 0;

            }

        }

        if(ok) printf("Yes\n");

        else printf("No\n");

    }

    return 0;

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

#include<cstdio>

#include<algorithm>

#include<vector>

#define Max 100010

using namespace std;

struct node

{

    int n,d;

}push;

vector<node>  e[Max];

bool vis[Max];

int flag=0;

int dis[Max];

void dfs(int x)

{

    vis[x]=true;

    if(flag)

    return;

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

    {

        node tmp;

        tmp=e[x][i];

        if(vis[tmp.n])

        {

            if(dis[tmp.n]!=dis[x]+tmp.d)

            {

                flag=1;

                break;

            }

        }

        else

        {

            dis[tmp.n]=dis[x]+tmp.d;

            dfs(tmp.n);

        }

    }

}

int main()

{

    int N,M;

    int l,r,d;

    scanf("%d%d",&N,&M);

    int i;

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

    {

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

        push.n=r;

        push.d=d;

        e[l].push_back(push);

        push.n=l;

        push.d=-1*d;

        e[r].push_back(push);

    }

    for(i=0;i<N;i++)

    {

        if(vis[i]==false)

        {

            dfs(i);

        }

        if(flag)

            break;

    }

    if(flag)

        printf("No\n");

    else printf("Yes\n");

    return 0;

}


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

#include <cstdio>

#include <map>

#include <algorithm>

#include <cstring>

#include <string>

#include <cmath>



using namespace std;



const int N = 1e5+5;

int n,m;

int fa[N],r[N];



void init()

{

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

    {

        fa[i] = i;

    }

    memset(r,0,sizeof(r));

}



int Find(int x)

{

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

    int root = Find(fa[x]);

    r[x] += r[fa[x]];

    return fa[x] = root;

}



bool Merge(int x, int y, int d)

{

    int fx = Find(x);

    int fy = Find(y);

    if(fx==fy)

    {

        return d == r[y]-r[x];

    }

    fa[fy] = fx;

    r[fy] = r[x] + d - r[y];

    return 1;

}



int main()

{

    while(scanf("%d%d",&n,&m) != EOF)

    {

        int ok = 1;

        int L,R,D;

        init();

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

        {

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

            if(ok && !Merge(L,R,D))

            {

                ok = 0;

            }

        }

        if(ok) printf("Yes\n");

        else printf("No\n");

    }

    return 0;

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

#include <cstring>

#include <cstdio>

#include <vector>



using namespace std;



#define MAXN 100005



int N,M;

bool mark[MAXN];



vector<pair<int,int>> v[MAXN];

int len[MAXN];



bool DFS(int t)

{

	vector<pair<int,int>>::iterator it;

	for(it = v[t].begin() ; it!=v[t].end() ; it++)

	{

		int p = (*it).first;

		int val = (*it).second;

		if(!mark[p])

		{

			mark[p] = true;

			len[p] = len[t]+val;

			if(!DFS(p))return false;

		}

		else if(len[p] != len[t]+val)return false;

	}

	return true;

}



int main()

{

	cin>>N>>M;

	int L,R,D;

	while(M--)

	{

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

		v[L].push_back(make_pair(R,D));

		v[R].push_back(make_pair(L,-D));

	}

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

	{

		if(!mark[i])

		{

			mark[i] = true;

			if(!DFS(i))

			{

				printf("No\n");

				return 0;

			}

		}

	}

	printf("Yes\n");

	return 0;

}

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

#include <cstdio>

#include <map>

#include <algorithm>

#include <cstring>

#include <string>

#include <cmath>



using namespace std;



const int N = 1e5+5;

int n,m;

int fa[N],r[N];



void init()

{

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

    {

        fa[i] = i;

    }

    memset(r,0,sizeof(r));

}



int Find(int x)

{

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

    int root = Find(fa[x]);

    r[x] += r[fa[x]];

    return fa[x] = root;

}



bool Merge(int x, int y, int d)

{

    int fx = Find(x);

    int fy = Find(y);

    if(fx==fy)

    {

        return d == r[y]-r[x];

    }

    fa[fy] = fx;

    r[fy] = r[x] + d - r[y];

    return 1;

}



int main()

{

    while(scanf("%d%d",&n,&m) != EOF)

    {

        int ok = 1;

        int L,R,D;

        init();

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

        {

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

            if(ok && !Merge(L,R,D))

            {

                ok = 0;

            }

        }

        if(ok) printf("Yes\n");

        else printf("No\n");

    }

    return 0;

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

#include<cstdio>

#include<cstring>

#include<vector>

using namespace std;

const int MAXN=1e5+5;

int p[MAXN],vis[MAXN],error;

struct node{

	int x,y;

}push;

int n,m;

vector <node> vec[MAXN];

void solve(int x){

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

		node g=vec[x][i];

		if (vis[g.x])

		  if (g.y+p[x]!=p[g.x]){

		  	error=1;		

		  	return;

		  }

		  else continue;

		 vis[g.x]=1;

		 p[g.x]=p[x]+g.y;

		 solve(g.x);

		 if (error) return;

	}

}

int main(){

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

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

		memset(p,0,sizeof(p));

		error=0;

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

			int a,b,l;

			scanf("%d%d%d",&a,&b,&l);

			push.x=b;

			push.y=l;

			vec[a].push_back(push);

			push.x=a;

			push.y=-l;

			vec[b].push_back(push);

		}

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

		  if (!vis[i]){

		  	solve(i);

		  	if (error) break;

		  }

		if (!error) printf("Yes\n");

		else printf("No\n");

	

	return 0;

}

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

#include <cstdio>

#include <map>

#include <algorithm>

#include <cstring>

#include <string>

#include <cmath>



using namespace std;



const int N = 1e5+5;

int n,m;

int fa[N],r[N];



void init()

{

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

    {

        fa[i] = i;

    }

    memset(r,0,sizeof(r));

}



int Find(int x)

{

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

    int root = Find(fa[x]);

    r[x] += r[fa[x]];

    return fa[x] = root;

}



bool Merge(int x, int y, int d)

{

    int fx = Find(x);

    int fy = Find(y);

    if(fx==fy)

    {

        return d == r[y]-r[x];

    }

    fa[fy] = fx;

    r[fy] = r[x] + d - r[y];

    return 1;

}



int main()

{

    while(scanf("%d%d",&n,&m) != EOF)

    {

        int ok = 1;

        int L,R,D;

        init();

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

        {

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

            if(ok && !Merge(L,R,D))

            {

                ok = 0;

            }

        }

        if(ok) printf("Yes\n");

        else printf("No\n");

    }

    return 0;

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

#include <vector>

using namespace std;

 

int n,m; //input intergers:n,m

vector<pair<int,int> > e[100010]; //the vector array of DFS

long long pos[100010]; //the positions of each person 

bool vis[100010]; //the bool array of DFS to know each person has visited or not

 

inline void dfs(int x) //DFS

{

	vis[x]=1; //visited this person(x)

	for(int i=0;i<e[x].size();i++) //visit the person who has relation of this person(x)

	{

		pair<int,int> cur=e[x][i];

		if(vis[cur.first]) //if(this person(e[x][i])'s position has known)

		{

			if(pos[cur.first]-pos[x]!=cur.second) {cout<<"No";exit(0);} //if this person(e[x][i]) is wrongful then exit

		}

		else //if this person(e[x][i])'s position hasn't known then take notes and DFS

		{

			pos[cur.first]=pos[x]+cur.second;

			dfs(cur.first);

		}

	}

}

 

int main()

{

	cin>>n>>m; //input

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

	{

		int l,r,d;

		cin>>l>>r>>d; //input

		e[l].push_back({r,d}); //take notes

		e[r].push_back({l,-d}); //take notes

	}

	

	for(int i=0;i<n;i++) if(!vis[i]) dfs(i); //DFS

	

	cout<<"Yes"; //if every one isn't wrongful then print 'Yes'

	

	return 0; //END

}

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

using namespace std;

int parent[100005];

int d[100005];

int find(int x)

{

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

	int l=find(parent[x]);

	d[x]=d[parent[x]]+d[x];

	parent[x]=l;

	return l;

} 

int Unit(int x,int y,int z)

{

	int px=find(x);

	int py=find(y);

	if(px==py)

	return z==d[y]-d[x];

	parent[py]=px;

	d[py]=d[x]-d[y]+z;

	return 1;

} 

int main()

{

	int n,m;

	while(cin>>n>>m)

	{

		int i,ok=1;int x,y,z;

		for(i=1;i<=n;i++) parent[i]=i;

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

		{

			cin>>x>>y>>z;

			if(ok)

			{

				ok=Unit(x,y,z);

			}

		}

		if(!ok) cout<<"No"<<endl;

		else cout<<"Yes"<<endl;

	}

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

#include<cstdio>

#include<algorithm>

#include<vector>

#define Max 100010

using namespace std;

struct node

{

    int n,d;

}push;

vector<node>  e[Max];

bool vis[Max];

int flag=0;

int dis[Max];

void dfs(int x)

{

    vis[x]=true;

    if(flag)

    return;

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

    {

        node tmp;

        tmp=e[x][i];

        if(vis[tmp.n])

        {

            if(dis[tmp.n]!=dis[x]+tmp.d)

            {

                flag=1;

                break;

            }

        }

        else

        {

            dis[tmp.n]=dis[x]+tmp.d;

            dfs(tmp.n);

        }

    }

}

int main()

{

    int N,M;

    int l,r,d;

    scanf("%d%d",&N,&M);

    int i;

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

    {

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

        push.n=r;

        push.d=d;

        e[l].push_back(push);

        push.n=l;

        push.d=-1*d;

        e[r].push_back(push);

    }

    for(i=0;i<N;i++)

    {

        if(vis[i]==false)

        {

            dfs(i);

        }

        if(flag)

            break;

    }

    if(flag)

        printf("No\n");

    else printf("Yes\n");

    return 0;

}


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

using namespace std;

int parent[100005];

int d[100005];

int find(int x)

{

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

	int l=find(parent[x]);

	d[x]=d[parent[x]]+d[x];

	parent[x]=l;

	return l;

} 

int Unit(int x,int y,int z)

{

	int px=find(x);

	int py=find(y);

	if(px==py)

	return z==d[y]-d[x];

	parent[py]=px;

	d[py]=d[x]-d[y]+z;

	return 1;

} 

int main()

{

	int n,m;

	while(cin>>n>>m)

	{

		int i,ok=1;int x,y,z;

		for(i=1;i<=n;i++) parent[i]=i;

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

		{

			cin>>x>>y>>z;

			if(ok)

			{

				ok=Unit(x,y,z);

			}

		}

		if(!ok) cout<<"No"<<endl;

		else cout<<"Yes"<<endl;

	}

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

#include <cstring>

#include <cstdio>

#include <vector>



using namespace std;



#define MAXN 100005



int N,M;

bool mark[MAXN];



vector<pair<int,int>> v[MAXN];

int len[MAXN];



bool DFS(int t)

{

	vector<pair<int,int>>::iterator it;

	for(it = v[t].begin() ; it!=v[t].end() ; it++)

	{

		int p = (*it).first;

		int val = (*it).second;

		if(!mark[p])

		{

			mark[p] = true;

			len[p] = len[t]+val;

			if(!DFS(p))return false;

		}

		else if(len[p] != len[t]+val)return false;

	}

	return true;

}



int main()

{

	cin>>N>>M;

	int L,R,D;

	while(M--)

	{

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

		v[L].push_back(make_pair(R,D));

		v[R].push_back(make_pair(L,-D));

	}

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

	{

		if(!mark[i])

		{

			mark[i] = true;

			if(!DFS(i))

			{

				printf("No\n");

				return 0;

			}

		}

	}

	printf("Yes\n");

	return 0;

}

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

using namespace std;

int parent[100005];

int d[100005];

int find(int x)

{

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

	int l=find(parent[x]);

	d[x]=d[parent[x]]+d[x];

	parent[x]=l;

	return l;

} 

int Unit(int x,int y,int z)

{

	int px=find(x);

	int py=find(y);

	if(px==py)

	return z==d[y]-d[x];

	parent[py]=px;

	d[py]=d[x]-d[y]+z;

	return 1;

} 

int main()

{

	int n,m;

	while(cin>>n>>m)

	{

		int i,ok=1;int x,y,z;

		for(i=1;i<=n;i++) parent[i]=i;

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

		{

			cin>>x>>y>>z;

			if(ok)

			{

				ok=Unit(x,y,z);

			}

		}

		if(!ok) cout<<"No"<<endl;

		else cout<<"Yes"<<endl;

	}

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

#include<cstdio>

#include<cstring>

#include<vector>

using namespace std;

const int MAXN=1e5+5;

int p[MAXN],vis[MAXN],error;

struct node{

	int x,y;

}push;

int n,m;

vector <node> vec[MAXN];

void solve(int x){

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

		node g=vec[x][i];

		if (vis[g.x])

		  if (g.y+p[x]!=p[g.x]){

		  	error=1;		

		  	return;

		  }

		  else continue;

		 vis[g.x]=1;

		 p[g.x]=p[x]+g.y;

		 solve(g.x);

		 if (error) return;

	}

}

int main(){

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

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

		memset(p,0,sizeof(p));

		error=0;

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

			int a,b,l;

			scanf("%d%d%d",&a,&b,&l);

			push.x=b;

			push.y=l;

			vec[a].push_back(push);

			push.x=a;

			push.y=-l;

			vec[b].push_back(push);

		}

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

		  if (!vis[i]){

		  	solve(i);

		  	if (error) break;

		  }

		if (!error) printf("Yes\n");

		else printf("No\n");

	

	return 0;

}

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

using namespace std;

int parent[100005];

int d[100005];

int find(int x)

{

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

	int l=find(parent[x]);

	d[x]=d[parent[x]]+d[x];

	parent[x]=l;

	return l;

} 

int Unit(int x,int y,int z)

{

	int px=find(x);

	int py=find(y);

	if(px==py)

	return z==d[y]-d[x];

	parent[py]=px;

	d[py]=d[x]-d[y]+z;

	return 1;

} 

int main()

{

	int n,m;

	while(cin>>n>>m)

	{

		int i,ok=1;int x,y,z;

		for(i=1;i<=n;i++) parent[i]=i;

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

		{

			cin>>x>>y>>z;

			if(ok)

			{

				ok=Unit(x,y,z);

			}

		}

		if(!ok) cout<<"No"<<endl;

		else cout<<"Yes"<<endl;

	}

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

#include <cstdio>

#include <map>

#include <algorithm>

#include <cstring>

#include <string>

#include <cmath>



using namespace std;



const int N = 1e5+5;

int n,m;

int fa[N],r[N];



void init()

{

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

    {

        fa[i] = i;

    }

    memset(r,0,sizeof(r));

}



int Find(int x)

{

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

    int root = Find(fa[x]);

    r[x] += r[fa[x]];

    return fa[x] = root;

}



bool Merge(int x, int y, int d)

{

    int fx = Find(x);

    int fy = Find(y);

    if(fx==fy)

    {

        return d == r[y]-r[x];

    }

    fa[fy] = fx;

    r[fy] = r[x] + d - r[y];

    return 1;

}



int main()

{

    while(scanf("%d%d",&n,&m) != EOF)

    {

        int ok = 1;

        int L,R,D;

        init();

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

        {

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

            if(ok && !Merge(L,R,D))

            {

                ok = 0;

            }

        }

        if(ok) printf("Yes\n");

        else printf("No\n");

    }

    return 0;

}


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

using namespace std;

int parent[100005];

int d[100005];

int find(int x)

{

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

	int l=find(parent[x]);

	d[x]=d[parent[x]]+d[x];

	parent[x]=l;

	return l;

} 

int Unit(int x,int y,int z)

{

	int px=find(x);

	int py=find(y);

	if(px==py)

	return z==d[y]-d[x];

	parent[py]=px;

	d[py]=d[x]-d[y]+z;

	return 1;

} 

int main()

{

	int n,m;

	while(cin>>n>>m)

	{

		int i,ok=1;int x,y,z;

		for(i=1;i<=n;i++) parent[i]=i;

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

		{

			cin>>x>>y>>z;

			if(ok)

			{

				ok=Unit(x,y,z);

			}

		}

		if(!ok) cout<<"No"<<endl;

		else cout<<"Yes"<<endl;

	}

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

#include <vector>

using namespace std;

 

int n,m; //input intergers:n,m

vector<pair<int,int> > e[100010]; //the vector array of DFS

long long pos[100010]; //the positions of each person 

bool vis[100010]; //the bool array of DFS to know each person has visited or not

 

inline void dfs(int x) //DFS

{

	vis[x]=1; //visited this person(x)

	for(int i=0;i<e[x].size();i++) //visit the person who has relation of this person(x)

	{

		pair<int,int> cur=e[x][i];

		if(vis[cur.first]) //if(this person(e[x][i])'s position has known)

		{

			if(pos[cur.first]-pos[x]!=cur.second) {cout<<"No";exit(0);} //if this person(e[x][i]) is wrongful then exit

		}

		else //if this person(e[x][i])'s position hasn't known then take notes and DFS

		{

			pos[cur.first]=pos[x]+cur.second;

			dfs(cur.first);

		}

	}

}

 

int main()

{

	cin>>n>>m; //input

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

	{

		int l,r,d;

		cin>>l>>r>>d; //input

		e[l].push_back({r,d}); //take notes

		e[r].push_back({l,-d}); //take notes

	}

	

	for(int i=0;i<n;i++) if(!vis[i]) dfs(i); //DFS

	

	cout<<"Yes"; //if every one isn't wrongful then print 'Yes'

	

	return 0; //END

}

// Faster C++ solution for the same problem (measured speedup: 3.582333006892638x):
#include <stdio.h>

#include <string.h>

#include <stdlib.h>

#include <math.h>

#include <time.h>

#include <iostream>

#include <algorithm>

#include <string>

#include <set>

#include <map>

#include <queue>

#include <stack>

#include <bitset>

#include <vector>

using namespace std;



#define bll long long

#define dou double

#define For(i,a,b) for (int i=(a),_##i=(b); i<=_##i; ++i)

#define Rof(i,a,b) for (int i=(a),_##i=(b); i>=_##i; --i)

#define Mem(a,b) memset(a,b,sizeof(a))

#define Cpy(a,b) memcpy(a,b,sizeof(b))



const int maxn=1e5+100;

int N,M,u[maxn],link[maxn];

int dlt[maxn];



int get_u(int x,int &ret)

{

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

    u[x]=get_u(u[x],ret);

    ret+=dlt[x];

    dlt[x]=ret;

    return u[x];

}



bool check(int x,int y,int d)

{

    int rx=0,ry=0;

    int a=get_u(x,rx),b=get_u(y,ry);

    if (a==b) return (dlt[y]-dlt[x]==d);

    if (link[a]<link[b]) swap(a,b),swap(x,y),d=-d;

    u[b]=a;

    link[a]+=(link[a]==link[b]);

    dlt[b]=dlt[x]-dlt[y]+d;

    return 1;

}



int main()

{

    for (; scanf("%d%d",&N,&M)!=EOF; )

    {

        bool flag=1;

        For(i,1,N) u[i]=i,link[i]=0,dlt[i]=0;

        For(i,1,M)

        {

            int x,y,d;

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

            if (flag) flag=check(x,y,d);

        }

        if (flag)

            printf("Yes\n");

        else

            printf("No\n");

    }

    return 0;

}