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

#include <iostream>

#include <algorithm>

#include <cstring>

#include <cmath>

#include <queue>

#include <vector>

using namespace std;

struct node{

    int u,w;

};

node p;

vector<node>q[100005];

int visit[100005];

int dis[100005],flag;

void query(int x){

    if(flag==1) return ;

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

        node y=q[x][i];

        if(visit[y.u]==1){

            if(dis[y.u]!=dis[x]+y.w) {

                flag=1;

                return ;

            }

            else continue;

        }

        visit[y.u]=1;

        dis[y.u]=dis[x]+y.w;

        query(y.u);

    }



}

int main(){

    int n,m,k,u,w;

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

        memset(visit,0,sizeof(visit));

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

            scanf("%d%d%d",&k,&u,&w);

            p.u=u,p.w=w;

            q[k].push_back(p);

            p.u=k,p.w=-w;

            q[u].push_back(p);

        }

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

            if(visit[i]==0){

                flag=0;

                query(i);

            }

            if(flag==1){

                printf("No\n");

                break;

            }



        }

        if(flag==0) printf("Yes\n");

    }

    return 0;

}




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

using namespace std;

int main(){

  int N, M;

  cin >> N >> M;

  vector<vector<pair<int, int>>> E(N);

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

    int L, R, D;

    cin >> L >> R >> D;

    L--;

    R--;

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

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

  }

  vector<int> d(N);

  vector<int> comp(N, -1);

  bool ok = true;

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

    if (comp[i] == -1){

      comp[i] = i;

      d[i] = 0;

      queue<int> Q;

      Q.push(i);

      while (!Q.empty()){

        int v = Q.front();

        Q.pop();

        for (auto P : E[v]){

          int dist = P.first;

          int w = P.second;

          if (comp[w] != -1){

            if (d[w] != d[v] + dist){

              ok = false;

            }

          } else {

            comp[w] = i;

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

            Q.push(w);

          }

        }

      }

    }

  }

  if (ok){

    cout << "Yes" << endl;

  } else {

    cout << "No" << endl;

  }

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

#include <cstdio>

#include <cstring>

#include <cmath>

#include <cstdlib>

#include <iostream>

#include <algorithm>

using namespace std;

const int maxn=1e5+5; 

vector <pair<int, int> > adj[maxn];

bool vis[maxn];

int x[maxn];



void dfs(int now,int dist)

{

	vis[now] = true;

	x[now] = dist;

 

	for (int i = 0; i < adj[now].size(); i++)

	{

		int next = adj[now][i].first;

		int d = adj[now][i].second;

		if (vis[next] == false)

		{

			dfs(next, dist + d);

		}

	}

}

 

int main()

{

	int n, m;

	int l, r, d;

	bool ok = true;

 

	cin.tie(0);

 

	while(cin >> n >> m)

	{

		ok=true;

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

	{

		cin >> l >> r >> d;

		adj[l].push_back(make_pair(r, d)); //关联点 

		adj[r].push_back(make_pair(l, -d));

	}

 

	memset(x, 0, sizeof(x));

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

 

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

	{

		if (vis[i]==false)

		{

			dfs(i, 0);

		}

	}



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

	{

		for (int j = 0; j < adj[i].size(); j++)

		{

			int v = adj[i][j].first;

			if (adj[i][j].second != x[v]-x[i])

			{

				ok = false;

				break;

			}

		}

		if (ok == false)

		{

			cout << "No" << '\n';

			break;

		}

 

	}

 

	if (ok == true)

	{

		cout << "Yes" << '\n';

	}

	}

	return 0;

}

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

using namespace std;

int main(){

  int N, M;

  cin >> N >> M;

  vector<vector<pair<int, int>>> E(N);

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

    int L, R, D;

    cin >> L >> R >> D;

    L--;

    R--;

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

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

  }

  vector<int> d(N);

  vector<int> comp(N, -1);

  bool ok = true;

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

    if (comp[i] == -1){

      comp[i] = i;

      d[i] = 0;

      queue<int> Q;

      Q.push(i);

      while (!Q.empty()){

        int v = Q.front();

        Q.pop();

        for (auto P : E[v]){

          int dist = P.first;

          int w = P.second;

          if (comp[w] != -1){

            if (d[w] != d[v] + dist){

              ok = false;

            }

          } else {

            comp[w] = i;

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

            Q.push(w);

          }

        }

      }

    }

  }

  if (ok){

    cout << "Yes" << endl;

  } else {

    cout << "No" << endl;

  }

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

using namespace std;

#define fi first

#define se second

typedef vector<int> VI;

typedef pair<int,int> PII;

typedef long long ll;

#define mp make_pair

#define pb push_back

void solve();

void read_input(){



}

void solve(){



}

vector<PII> edges[100005];



vector<int> order;

bool visited[100005];

ll pos[100005];

void dfs(int i){

	if (visited[i])

		return ;

	visited[i] = true;

	for(PII p:edges[i]){

		if (!visited[p.fi])

			dfs(p.fi);

	}

	order.pb(i);

}

int main(){

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

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

		edges[i] = vector<PII>();

	}	

	int N,M;

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

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

		int a,b,c;

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

		edges[a].pb({b,c});

	}

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

		if (!visited[i]){

			dfs(i);

		}

	} 

	reverse(order.begin(),order.end());

	for(int i:order){

		if (pos[i] == -1){

			pos[i] = 0;

		}

		for(PII p:edges[i]){

			if (pos[p.fi] == -1){

				pos[p.fi] = pos[i]+p.se;

			}else{

				if (pos[p.fi] != pos[i]+p.se){

					cout<<"No"<<endl;

					return 0;

				}

			}

		}

	}

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

		if (pos[i]>1000000000){

			cout<<"No"<<endl;

			return 0;

		}

	}

	cout<<"Yes"<<endl;

	return 0;

}

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

using namespace std;

int main(){

  int N, M;

  cin >> N >> M;

  vector<vector<pair<int, int>>> E(N);

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

    int L, R, D;

    cin >> L >> R >> D;

    L--;

    R--;

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

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

  }

  vector<int> d(N);

  vector<int> comp(N, -1);

  bool ok = true;

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

    if (comp[i] == -1){

      comp[i] = i;

      d[i] = 0;

      queue<int> Q;

      Q.push(i);

      while (!Q.empty()){

        int v = Q.front();

        Q.pop();

        for (auto P : E[v]){

          int dist = P.first;

          int w = P.second;

          if (comp[w] != -1){

            if (d[w] != d[v] + dist){

              ok = false;

            }

          } else {

            comp[w] = i;

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

            Q.push(w);

          }

        }

      }

    }

  }

  if (ok){

    cout << "Yes" << endl;

  } else {

    cout << "No" << endl;

  }

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

using namespace std;



typedef pair<int, int> pi;



int n, m, l, r, d, dist[100001], vis[100001];

vector<pi> adj[100001];



void dfs(int node){

	vis[node] = 1;

	for(auto it:adj[node]){

		if(vis[it.first] != -1){

			if(dist[it.first] != dist[node]+it.second){ cout << "No"; exit(0); }

			continue;

		}

		vis[it.first] = 1;

		dist[it.first] = dist[node]+it.second;

		dfs(it.first);

	}

}



int main(){

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

	cin >> n >> m;

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

		cin >> l >> r >> d;

		adj[l].push_back(pi(r, d));

		adj[r].push_back(pi(l, -d));

	}

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

		if(vis[i] == -1) dfs(i);

	}

	cout << "Yes";

}

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

using namespace std;

int main(){

  int N, M;

  cin >> N >> M;

  vector<vector<pair<int, int>>> E(N);

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

    int L, R, D;

    cin >> L >> R >> D;

    L--;

    R--;

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

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

  }

  vector<int> d(N);

  vector<int> comp(N, -1);

  bool ok = true;

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

    if (comp[i] == -1){

      comp[i] = i;

      d[i] = 0;

      queue<int> Q;

      Q.push(i);

      while (!Q.empty()){

        int v = Q.front();

        Q.pop();

        for (auto P : E[v]){

          int dist = P.first;

          int w = P.second;

          if (comp[w] != -1){

            if (d[w] != d[v] + dist){

              ok = false;

            }

          } else {

            comp[w] = i;

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

            Q.push(w);

          }

        }

      }

    }

  }

  if (ok){

    cout << "Yes" << endl;

  } else {

    cout << "No" << endl;

  }

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

using namespace std;

const int N = 1e5 + 25, M = 1e6 + 25, oo = 1e9+7, mxmsk = 1 << 16;

const long long OO = 1e18+25;

    

#define f first

#define s second

    

int n,m,l,r,d, dis[N], vis[N], v=1;

vector <pair<int, int>> g[N];

stack <int> st;

bool f;



void dfs(int from)

{

    vis[from] = v;

    for(auto pa : g[from])

    {

        if(vis[pa.f] != v)

        {

            dis[pa.f] = dis[from] + pa.s;

            dfs(pa.f);

        }else if(dis[pa.f] != dis[from] + pa.s)

        {

            f =1;

        }

    }

}



void dfs1(int from)

{

    vis[from] = v;

    for(auto pa: g[from])

    {

        if(vis[pa.f] != v)

        {

            dfs1(pa.f);

        }

    }

}



int main() {

    #   ifdef LOCAL_PROJECT

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

    #   endif

    cin >> n >> m;

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

    {

        cin >> l >> r >> d;

        g[l].push_back({r,d});

    }

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

    {

        if(vis[i] != v) 

        {

            st.push(i);

            dfs1(i);

        }

    }

    v++;

    while(!st.empty())

    {

        int i = st.top();

        if(vis[i] != v)

        {

            for(auto pa : g[i])

            {

                if(vis[pa.f] == v)

                {

                    dis[i] = dis[pa.f] - pa.s;

                    break;

                }

            }

            dfs(i);

        }

        st.pop();

    }

    if(f) cout << "No";

    else cout << "Yes";

    return 0;

}

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

using namespace std;

int main(){

  int N, M;

  cin >> N >> M;

  vector<vector<pair<int, int>>> E(N);

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

    int L, R, D;

    cin >> L >> R >> D;

    L--;

    R--;

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

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

  }

  vector<int> d(N);

  vector<int> comp(N, -1);

  bool ok = true;

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

    if (comp[i] == -1){

      comp[i] = i;

      d[i] = 0;

      queue<int> Q;

      Q.push(i);

      while (!Q.empty()){

        int v = Q.front();

        Q.pop();

        for (auto P : E[v]){

          int dist = P.first;

          int w = P.second;

          if (comp[w] != -1){

            if (d[w] != d[v] + dist){

              ok = false;

            }

          } else {

            comp[w] = i;

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

            Q.push(w);

          }

        }

      }

    }

  }

  if (ok){

    cout << "Yes" << endl;

  } else {

    cout << "No" << endl;

  }

}
// Slower C++ solution:
/*|In The Name Of Allah|*/



#include <bits/stdc++.h>



using namespace std;



typedef pair < int , pair < int , int > > pll;



const int N = 1e5+5;



int n;

int m;

int dist[N];

int indeg[N];

vector < pair < int , int > > adj[N];



int main(){

    memset(dist , -1 , sizeof dist);

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

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

        int l , r , d;

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

        adj[l].push_back({r , d});

        indeg[r]++;

    }

    int bad = 0;

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

        if(!indeg[i]){

            queue < int > q;

            q.push(i);

            dist[i] = 0;

            while(!q.empty()){

                int u = q.front();

                q.pop();

                for(auto nw : adj[u]){

                    int v = nw.first;

                    int d = nw.second;

                    if(dist[v] == -1){

                        dist[v] = dist[u] + d;

                        if(dist[v] > 1e9)

                            bad = 1;

                        q.push(v);

                    } else {

                        if(dist[v] != d + dist[u]){

                            bad = 1;

                        }

                    }

                }

            }

        }

    }

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

        if(dist[i] == -1)

            bad = 1;

    }

    puts(bad ? "No" : "Yes");

}


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

using namespace std;

int main(){

  int N, M;

  cin >> N >> M;

  vector<vector<pair<int, int>>> E(N);

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

    int L, R, D;

    cin >> L >> R >> D;

    L--;

    R--;

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

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

  }

  vector<int> d(N);

  vector<int> comp(N, -1);

  bool ok = true;

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

    if (comp[i] == -1){

      comp[i] = i;

      d[i] = 0;

      queue<int> Q;

      Q.push(i);

      while (!Q.empty()){

        int v = Q.front();

        Q.pop();

        for (auto P : E[v]){

          int dist = P.first;

          int w = P.second;

          if (comp[w] != -1){

            if (d[w] != d[v] + dist){

              ok = false;

            }

          } else {

            comp[w] = i;

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

            Q.push(w);

          }

        }

      }

    }

  }

  if (ok){

    cout << "Yes" << endl;

  } else {

    cout << "No" << endl;

  }

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

#include <iostream>

#include <algorithm>

#include <cstring>

#include <cmath>

#include <queue>

#include <vector>

using namespace std;

struct node{

    int u,w;

};

node p;

vector<node>q[100005];

int visit[100005];

int dis[100005],flag;

void query(int x){

    if(flag==1) return ;

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

        node y=q[x][i];

        if(visit[y.u]==1){

            if(dis[y.u]!=dis[x]+y.w) {

                flag=1;

                return ;

            }

            else continue;

        }

        visit[y.u]=1;

        dis[y.u]=dis[x]+y.w;

        query(y.u);

    }



}

int main(){

    int n,m,k,u,w;

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

        memset(visit,0,sizeof(visit));

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

            scanf("%d%d%d",&k,&u,&w);

            p.u=u,p.w=w;

            q[k].push_back(p);

            p.u=k,p.w=-w;

            q[u].push_back(p);

        }

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

            if(visit[i]==0){

                flag=0;

                query(i);

            }

            if(flag==1){

                printf("No\n");

                break;

            }



        }

        if(flag==0) printf("Yes\n");

    }

    return 0;

}




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

using namespace std;



#define int long long

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



typedef pair<int,int> ii;

typedef vector<ii> vii;



vector<vii> g;

int n,m,l,r,d;

int val[100001],ok;

bool visited[100001];



void dfs(int v) {

	visited[v]=true;

	rep(i,0,(int)g[v].size()-1) {

		ii p=g[v][i];

		if(visited[p.first]) {

			if(val[p.first]!=val[v]+p.second) {

					ok=false;

		return;

			}

		}

		else {

			val[p.first]=val[v]+p.second;

			dfs(p.first);

		}

		

	} 

}



signed main() {

	cin >> n >> m;

	g.assign(n+1,vii()) ;

	memset(visited,false,sizeof(visited));

	rep(i,1,m) {

		cin >> l >> r >> d;

		g[l].push_back(make_pair(r,d));

		g[r].push_back(make_pair(l,-d));

	}

	rep(i,1,n) {

		if(!visited[i]) {

			ok=true;

			dfs(i);

			if(ok==false) {

				cout << "No";

				return 0;

			}

		}

	}

	cout << "Yes";

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

#include <cstdio>

#include <cstring>

#include <cmath>

#include <cstdlib>

#include <iostream>

#include <algorithm>

using namespace std;

const int maxn=1e5+5; 

vector <pair<int, int> > adj[maxn];

bool vis[maxn];

int x[maxn];



void dfs(int now,int dist)

{

	vis[now] = true;

	x[now] = dist;

 

	for (int i = 0; i < adj[now].size(); i++)

	{

		int next = adj[now][i].first;

		int d = adj[now][i].second;

		if (vis[next] == false)

		{

			dfs(next, dist + d);

		}

	}

}

 

int main()

{

	int n, m;

	int l, r, d;

	bool ok = true;

 

	cin.tie(0);

 

	while(cin >> n >> m)

	{

		ok=true;

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

	{

		cin >> l >> r >> d;

		adj[l].push_back(make_pair(r, d)); //关联点 

		adj[r].push_back(make_pair(l, -d));

	}

 

	memset(x, 0, sizeof(x));

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

 

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

	{

		if (vis[i]==false)

		{

			dfs(i, 0);

		}

	}



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

	{

		for (int j = 0; j < adj[i].size(); j++)

		{

			int v = adj[i][j].first;

			if (adj[i][j].second != x[v]-x[i])

			{

				ok = false;

				break;

			}

		}

		if (ok == false)

		{

			cout << "No" << '\n';

			break;

		}

 

	}

 

	if (ok == true)

	{

		cout << "Yes" << '\n';

	}

	}

	return 0;

}

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

using namespace std;



#define int long long

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



typedef pair<int,int> ii;

typedef vector<ii> vii;



vector<vii> g;

int n,m,l,r,d;

int val[100001],ok;

bool visited[100001];



void dfs(int v) {

	visited[v]=true;

	rep(i,0,(int)g[v].size()-1) {

		ii p=g[v][i];

		if(visited[p.first]) {

			if(val[p.first]!=val[v]+p.second) {

					ok=false;

		return;

			}

		}

		else {

			val[p.first]=val[v]+p.second;

			dfs(p.first);

		}

		

	} 

}



signed main() {

	cin >> n >> m;

	g.assign(n+1,vii()) ;

	memset(visited,false,sizeof(visited));

	rep(i,1,m) {

		cin >> l >> r >> d;

		g[l].push_back(make_pair(r,d));

		g[r].push_back(make_pair(l,-d));

	}

	rep(i,1,n) {

		if(!visited[i]) {

			ok=true;

			dfs(i);

			if(ok==false) {

				cout << "No";

				return 0;

			}

		}

	}

	cout << "Yes";

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

using namespace std;

#define fi first

#define se second

typedef vector<int> VI;

typedef pair<int,int> PII;

typedef long long ll;

#define mp make_pair

#define pb push_back

void solve();

void read_input(){



}

void solve(){



}

vector<PII> edges[100005];



vector<int> order;

bool visited[100005];

ll pos[100005];

void dfs(int i){

	if (visited[i])

		return ;

	visited[i] = true;

	for(PII p:edges[i]){

		if (!visited[p.fi])

			dfs(p.fi);

	}

	order.pb(i);

}

int main(){

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

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

		edges[i] = vector<PII>();

	}	

	int N,M;

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

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

		int a,b,c;

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

		edges[a].pb({b,c});

	}

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

		if (!visited[i]){

			dfs(i);

		}

	} 

	reverse(order.begin(),order.end());

	for(int i:order){

		if (pos[i] == -1){

			pos[i] = 0;

		}

		for(PII p:edges[i]){

			if (pos[p.fi] == -1){

				pos[p.fi] = pos[i]+p.se;

			}else{

				if (pos[p.fi] != pos[i]+p.se){

					cout<<"No"<<endl;

					return 0;

				}

			}

		}

	}

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

		if (pos[i]>1000000000){

			cout<<"No"<<endl;

			return 0;

		}

	}

	cout<<"Yes"<<endl;

	return 0;

}

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

using namespace std;



#define int long long

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



typedef pair<int,int> ii;

typedef vector<ii> vii;



vector<vii> g;

int n,m,l,r,d;

int val[100001],ok;

bool visited[100001];



void dfs(int v) {

	visited[v]=true;

	rep(i,0,(int)g[v].size()-1) {

		ii p=g[v][i];

		if(visited[p.first]) {

			if(val[p.first]!=val[v]+p.second) {

					ok=false;

		return;

			}

		}

		else {

			val[p.first]=val[v]+p.second;

			dfs(p.first);

		}

		

	} 

}



signed main() {

	cin >> n >> m;

	g.assign(n+1,vii()) ;

	memset(visited,false,sizeof(visited));

	rep(i,1,m) {

		cin >> l >> r >> d;

		g[l].push_back(make_pair(r,d));

		g[r].push_back(make_pair(l,-d));

	}

	rep(i,1,n) {

		if(!visited[i]) {

			ok=true;

			dfs(i);

			if(ok==false) {

				cout << "No";

				return 0;

			}

		}

	}

	cout << "Yes";

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

using namespace std;



typedef pair<int, int> pi;



int n, m, l, r, d, dist[100001], vis[100001];

vector<pi> adj[100001];



void dfs(int node){

	vis[node] = 1;

	for(auto it:adj[node]){

		if(vis[it.first] != -1){

			if(dist[it.first] != dist[node]+it.second){ cout << "No"; exit(0); }

			continue;

		}

		vis[it.first] = 1;

		dist[it.first] = dist[node]+it.second;

		dfs(it.first);

	}

}



int main(){

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

	cin >> n >> m;

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

		cin >> l >> r >> d;

		adj[l].push_back(pi(r, d));

		adj[r].push_back(pi(l, -d));

	}

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

		if(vis[i] == -1) dfs(i);

	}

	cout << "Yes";

}

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

using namespace std;



#define int long long

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



typedef pair<int,int> ii;

typedef vector<ii> vii;



vector<vii> g;

int n,m,l,r,d;

int val[100001],ok;

bool visited[100001];



void dfs(int v) {

	visited[v]=true;

	rep(i,0,(int)g[v].size()-1) {

		ii p=g[v][i];

		if(visited[p.first]) {

			if(val[p.first]!=val[v]+p.second) {

					ok=false;

		return;

			}

		}

		else {

			val[p.first]=val[v]+p.second;

			dfs(p.first);

		}

		

	} 

}



signed main() {

	cin >> n >> m;

	g.assign(n+1,vii()) ;

	memset(visited,false,sizeof(visited));

	rep(i,1,m) {

		cin >> l >> r >> d;

		g[l].push_back(make_pair(r,d));

		g[r].push_back(make_pair(l,-d));

	}

	rep(i,1,n) {

		if(!visited[i]) {

			ok=true;

			dfs(i);

			if(ok==false) {

				cout << "No";

				return 0;

			}

		}

	}

	cout << "Yes";

}