stablegradients/pie-gem5-pairs huggingface dataset:
// Slower C++ solution:
#include<bits/stdc++.h>

using namespace std;

#define int long long



typedef pair<int, int> P;

const int N = 2e5;

const int INF = 1e18;



struct edge{ int to,cost; };

vector< edge > G[N];



signed main(){



  int n,m; cin >> n >> m;

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

    int L,R,D; cin >> L >> R >> D;

    G[L].push_back({R,D});

    G[R].push_back({L,-D});

  }



  int d[N];

  fill(d,d+N,INF);

  queue<int> que;

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

    if(G[i].empty() || d[i] < INF) continue;

    d[i] = 0; //基準にして考える

    que.push(i);

    while(!que.empty()){

      int from = que.front();

      for(int j = 0; j < G[from].size(); j++){

        int to = G[from][j].to;

        int cost = G[from][j].cost;

        if(d[to] < INF){

          if(d[to] != d[from] + cost){

            cout << "No" << endl;

            return 0;

          }

        }

        else {

          d[to] = d[from] + cost;

          que.push(to);

        }

      }

      que.pop();

    }

  }

  cout << "Yes" << endl;



  return 0;

}


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

using namespace std;

#define int long long



struct UF{

  const int N = 1e5+10;

  vector<int> par;

  vector<int> depth;

  vector<int> diff;



  void init(int n){

    par.resize(n); depth.resize(n); diff.resize(n);

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

      par[i] = i;

      depth[i] = 0;

      diff[i] = 0;

    }

  }



  //木の根を求める

  int find(int x){

    if(par[x] == x){

      return x;

    }

    else {

      int r = find(par[x]);

      diff[x] += diff[par[x]];

      return par[x] = r;

    }

  }



  int weight(int x){

    find(x); //経路圧縮

    return diff[x];

  }



  //xとyの属する集合を併合

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

    w += weight(x) - weight(y);

    x = find(x);

    y = find(y);

    if(x == y) return;



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

    if(depth[x] == depth[y]) depth[x]++;

    par[y] = x;

    diff[y] = w;

  }

}uf;



signed main(){

  cin.tie(0);

  ios::sync_with_stdio(false);



  int n,q; cin >> n >> q;

  uf.init(n);

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

    int l,r,d; cin >> l >> r >> d;

    l--,r--;

    if(uf.find(l) == uf.find(r)){

      if(uf.weight(r)-uf.weight(l) != d){

        cout << "No" << endl;

        return 0;

      }

    }

    else uf.unite(l,r,d);

  }

  cout << "Yes" << endl;



  return 0;

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

using namespace std;

#define int long long



typedef pair<int, int> P;

const int N = 2e5;

const int INF = 1e18;



struct edge{ int to,cost; };

vector< edge > G[N];



signed main(){

  cin.tie(0);

  ios::sync_with_stdio(false);



  int n,m; cin >> n >> m;

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

    int L,R,D; cin >> L >> R >> D;

    G[L].push_back({R,D});

    G[R].push_back({L,-D});

  }



  int d[N];

  fill(d,d+N,INF);

  queue<int> que;

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

    if(G[i].empty() || d[i] < INF) continue;

    d[i] = 0; //基準にして考える

    que.push(i);

    while(!que.empty()){

      int from = que.front();

      for(int j = 0; j < G[from].size(); j++){

        int to = G[from][j].to;

        int cost = G[from][j].cost;

        if(d[to] < INF){

          if(d[to] != d[from] + cost){

            cout << "No" << endl;

            return 0;

          }

        }

        else {

          d[to] = d[from] + cost;

          que.push(to);

        }

      }

      que.pop();

    }

  }

  cout << "Yes" << endl;



  return 0;

}


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

using namespace std;

#define int long long



struct UF{

  const int N = 1e5+10;

  vector<int> par;

  vector<int> depth;

  vector<int> diff;



  void init(int n){

    par.resize(n); depth.resize(n); diff.resize(n);

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

      par[i] = i;

      depth[i] = 0;

      diff[i] = 0;

    }

  }



  //木の根を求める

  int find(int x){

    if(par[x] == x){

      return x;

    }

    else {

      int r = find(par[x]);

      diff[x] += diff[par[x]];

      return par[x] = r;

    }

  }



  int weight(int x){

    find(x); //経路圧縮

    return diff[x];

  }



  //xとyの属する集合を併合

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

    w += weight(x) - weight(y);

    x = find(x);

    y = find(y);

    if(x == y) return;



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

    if(depth[x] == depth[y]) depth[x]++;

    par[y] = x;

    diff[y] = w;

  }

}uf;



signed main(){

  cin.tie(0);

  ios::sync_with_stdio(false);



  int n,q; cin >> n >> q;

  uf.init(n);

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

    int l,r,d; cin >> l >> r >> d;

    l--,r--;

    if(uf.find(l) == uf.find(r)){

      if(uf.weight(r)-uf.weight(l) != d){

        cout << "No" << endl;

        return 0;

      }

    }

    else uf.unite(l,r,d);

  }

  cout << "Yes" << endl;



  return 0;

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

#define rep(i,n) for(int i=0;i<n;i++)

using namespace std;

typedef long long ll;

typedef pair<int,int> P;

const int INF = 1e9;

const int MOD = 1000000007;

const int MAX = 1000000;

int n = 100000;

vector<vector<P>> graph(n,vector<P>());

vector<bool> seen(n,false);

vector<int> dis(n);



bool dfs(int i,int p = -1,int d = 0){

        if(!seen[i]) dis[i] = d;

        else return dis[i] == d;

        seen[i] = true;

        bool res = true;

        for(P child:graph[i]){

                if(child.first == p) continue;

                 res = res && dfs(child.first,i,d+child.second);

        }

        return res;

}





int main(){

        int m;

        cin >> n >> m;

        rep(i,m){

                int l,r,d;

                cin >> l >> r>> d;

                --l;--r;

                graph[l].push_back(P(r,d));

                graph[r].push_back(P(l,-d));

        }



        rep(i,n){

                if(!seen[i]){

                        if(!dfs(i)){

                                cout << "No" << endl;

                                return 0;

                        }

                }

        }



        cout << "Yes" << endl;

        return 0;

}

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

using namespace std;

typedef long long ll;

typedef pair<int,int> pp;

const int INF = 1e9;

const int MOD = 1000000007;

#define rep(i,n) for(int i=0;i<n;i++)



struct potential_Unionfind{

    vector<int> rank;

    vector<int> par;

    vector<int> weights;

    potential_Unionfind(int n){

        rank.resize(n);

        par.resize(n);

        weights.resize(n);

        for(int i=0;i<n;i++) par[i] = i,rank[i] = 0,weights[i] = 0;

    }



    int find(int x){

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

        else{

            int p = find(par[x]);

            weights[x] += weights[par[x]];

            return par[x] = p;

        }

    }



    //weight[y] - weights[x] = wとなるようにuniteする。

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

        w += weight(x);

        w -= weight(y);

        x = find(x);

        y = find(y);

        if(x == y) return false;//もうすでに繋がれている頂点ならfalseを返す

        if(rank[x] < rank[y]) {swap(x,y); w = -w;}

        if(rank[x] == rank[y]) rank[x] ++;

        par[y] = x;

        weights[y] = w;

        return true;

    }



    bool same(int x,int y){

        return find(x) == find(y);

    }



    //weightsは各頂点から根までの距離

    int weight(int x){

        find(x);

        return weights[x];

    }



    int diff(int x,int y){

        return weight(y) - weight(x);

    }





};



int main(){

    int n,m;

    cin >> n >> m;

    potential_Unionfind uf(n);

    rep(i,m){

        int a,b,w;

        cin >> a >> b >> w;

        --a;--b;

        if(!uf.unite(a,b,w)){

            if(uf.diff(a,b) != w){

                cout << "No" << endl;

                return 0;

            }

        }

    }

    

    cout << "Yes" << endl;

    return 0;



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

using namespace std;



using VI = vector<int>;

using VVI = vector<VI>;

using PII = pair<int, int>;

using LL = long long;

using VL = vector<LL>;

using VVL = vector<VL>;

using PLL = pair<LL, LL>;

using VS = vector<string>;



#define ALL(a)  begin((a)),end((a))

#define RALL(a) (a).rbegin(), (a).rend()

#define PB push_back

#define EB emplace_back

#define MP make_pair

#define SZ(a) int((a).size())

#define SORT(c) sort(ALL((c)))

#define RSORT(c) sort(RALL((c)))

#define UNIQ(c) (c).erase(unique(ALL((c))), end((c)))



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

#define REP(i,n)  FOR(i,0,n)



#define FF first

#define SS second



#define DUMP(x) cout<<#x<<":"<<(x)<<endl

template<class S, class T>

istream& operator>>(istream& is, pair<S,T>& p){

  return is >> p.FF >> p.SS;

}

template<class T>

istream& operator>>(istream& is, vector<T>& xs){

  for(auto& x: xs)

	is >> x;

  return is;

}

template<class S, class T>

ostream& operator<<(ostream& os, const pair<S,T>& p){

  return os << p.FF << " " << p.SS;

}

template<class T>

ostream& operator<<(ostream& os, const vector<T>& xs){

  for(unsigned int i=0;i<xs.size();++i)

	os << (i?" ":"") << xs[i];

  return os;

}

template<class T>

void maxi(T& x, T y){

  if(x < y) x = y;

}

template<class T>

void mini(T& x, T y){

  if(x > y) x = y;

}





const double EPS = 1e-10;

const double PI  = acos(-1.0);

const LL MOD = 1e9+7;

const LL INF = 1e18;



bool dfs(vector<vector<PLL>>& G, int u, VL& dist){

  for(auto& e: G[u]){

	if(dist[e.FF] == INF){

	  dist[e.FF] = dist[u] + e.SS;

	  if(!dfs(G, e.FF, dist))

		return false;

	}

	else if(dist[e.FF] != dist[u] + e.SS)

	  return false;

  }

  return true;

}



int main(){

  cin.tie(0);

  ios_base::sync_with_stdio(false);



  int N, M;

  cin >> N >> M;

  vector<vector<PLL>> G(N);

  REP(i,M){

	int l, r, d;

	cin >> l >> r >> d;

	--l;

	--r;

	G[l].EB(r,d);

	G[r].EB(l,-d);

  }



  VL dist(N, INF);

  bool ok = true;

  REP(i,N){

	if(dist[i] != INF) continue;

	dist[i] = 0;

	ok = ok && dfs(G, i, dist);

  }



  cout << (ok? "Yes": "No") << endl;



  return 0;

}

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

#define maxn 200010

using namespace std;

int n,m,fa[maxn],dis[maxn];

int find(int x){

	if(x!=fa[x]){

		int f=fa[x];

		fa[x]=find(fa[x]);

		dis[x]+=dis[f];	

	}

	return fa[x]; 

}

int main(){

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

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

		fa[i]=i;

	int falg=0;

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

		int x,y,z;

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

		int r1=find(x);

		int r2=find(y);

		if(r1==r2){

			if(dis[r2]+dis[y]!=z+dis[x])falg=1;

			else continue;

		}

		else {

			fa[r2]=r1;

			dis[r2]=z+dis[x]-dis[y];

		}

	}

	if(falg)printf("No\n");

	else printf("Yes\n");

	return 0; 

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

#include <iostream>

#include <cstring>

#define maxn 2000005

using namespace std;

int Far[maxn],dis[maxn];

void inti(int n){

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

        Far[i]=i;

        dis[i]=0;

    }

}

int find_F(int x){

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

    int tmp=Far[x];

    Far[x]=find_F(Far[x]);

    dis[x]+=dis[tmp];

    return Far[x];

}

int find_D(int x){

    if(Far[x]==x) return 0;

    else return find_D(Far[x])+dis[x];

}

int main()

{

    int n,m;

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

    inti(n);

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

        int a,b,c;

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

        int Fa=find_F(a);

        int Fb=find_F(b);

        if(Fa==Fb){

            if(dis[b]-dis[a]!=c){

                puts("No");

                return 0;

            }

        }

        else{

            Far[Fb]=Fa;

            dis[Fb]=find_D(a)-find_D(b)+c;

        }

    }

    puts("Yes");

}


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

#define maxn 200010

using namespace std;

int n,m,fa[maxn],dis[maxn];

int find(int x){

	if(x!=fa[x]){

		int f=fa[x];

		fa[x]=find(fa[x]);

		dis[x]+=dis[f];	

	}

	return fa[x]; 

}

int main(){

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

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

		fa[i]=i;

	int falg=0;

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

		int x,y,z;

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

		int r1=find(x);

		int r2=find(y);

		if(r1==r2){

			if(dis[r2]+dis[y]!=z+dis[x])falg=1;

			else continue;

		}

		else {

			fa[r2]=r1;

			dis[r2]=z+dis[x]-dis[y];

		}

	}

	if(falg)printf("No\n");

	else printf("Yes\n");

	return 0; 

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

#include<cstdio>

const int N=1e5+5;

int n,m,par[N],dir[N];

void init() {

    for(int i=1;i<=n;i++) par[i]=i,dir[i]=0;

}

int fd(int x) {

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

    int t=par[x];

    par[x]=fd(par[x]);

    dir[x]+=dir[t];

    return par[x];

}

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

    int a=fd(x),b=fd(y);

    if(a==b) return;

    dir[a]=-dir[x]+c+dir[y];

    par[a]=b;

}

int main() {

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

    int l,r,d;init();

    bool ok=true;

    while(m--) {

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

        if(fd(l)!=fd(r)) unite(l,r,d);

        else if(dir[l]-dir[r]!=d) ok=false;

    }

    printf("%s\n",ok?"Yes":"No");

    return 0;

}


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

#define maxn 200010

using namespace std;

int n,m,fa[maxn],dis[maxn];

int find(int x){

	if(x!=fa[x]){

		int f=fa[x];

		fa[x]=find(fa[x]);

		dis[x]+=dis[f];	

	}

	return fa[x]; 

}

int main(){

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

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

		fa[i]=i;

	int falg=0;

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

		int x,y,z;

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

		int r1=find(x);

		int r2=find(y);

		if(r1==r2){

			if(dis[r2]+dis[y]!=z+dis[x])falg=1;

			else continue;

		}

		else {

			fa[r2]=r1;

			dis[r2]=z+dis[x]-dis[y];

		}

	}

	if(falg)printf("No\n");

	else printf("Yes\n");

	return 0; 

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

    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 <bits/stdc++.h>

using namespace std;



using VI = vector<int>;

using VVI = vector<VI>;

using PII = pair<int, int>;

using LL = long long;

using VL = vector<LL>;

using VVL = vector<VL>;

using PLL = pair<LL, LL>;

using VS = vector<string>;



#define ALL(a)  begin((a)),end((a))

#define RALL(a) (a).rbegin(), (a).rend()

#define PB push_back

#define EB emplace_back

#define MP make_pair

#define SZ(a) int((a).size())

#define SORT(c) sort(ALL((c)))

#define RSORT(c) sort(RALL((c)))

#define UNIQ(c) (c).erase(unique(ALL((c))), end((c)))



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

#define REP(i,n)  FOR(i,0,n)



#define FF first

#define SS second



#define DUMP(x) cout<<#x<<":"<<(x)<<endl

template<class S, class T>

istream& operator>>(istream& is, pair<S,T>& p){

  return is >> p.FF >> p.SS;

}

template<class T>

istream& operator>>(istream& is, vector<T>& xs){

  for(auto& x: xs)

	is >> x;

  return is;

}

template<class S, class T>

ostream& operator<<(ostream& os, const pair<S,T>& p){

  return os << p.FF << " " << p.SS;

}

template<class T>

ostream& operator<<(ostream& os, const vector<T>& xs){

  for(unsigned int i=0;i<xs.size();++i)

	os << (i?" ":"") << xs[i];

  return os;

}

template<class T>

void maxi(T& x, T y){

  if(x < y) x = y;

}

template<class T>

void mini(T& x, T y){

  if(x > y) x = y;

}





const double EPS = 1e-10;

const double PI  = acos(-1.0);

const LL MOD = 1e9+7;

const LL INF = 1e18;



bool dfs(vector<vector<PLL>>& G, int u, VL& dist){

  for(auto& e: G[u]){

	if(dist[e.FF] == INF){

	  dist[e.FF] = dist[u] + e.SS;

	  if(!dfs(G, e.FF, dist))

		return false;

	}

	else if(dist[e.FF] != dist[u] + e.SS)

	  return false;

  }

  return true;

}



int main(){

  cin.tie(0);

  ios_base::sync_with_stdio(false);



  int N, M;

  cin >> N >> M;

  vector<vector<PLL>> G(N);

  REP(i,M){

	int l, r, d;

	cin >> l >> r >> d;

	--l;

	--r;

	G[l].EB(r,d);

	G[r].EB(l,-d);

  }



  VL dist(N, INF);

  bool ok = true;

  REP(i,N){

	if(dist[i] != INF) continue;

	dist[i] = 0;

	ok = ok && dfs(G, i, dist);

  }



  cout << (ok? "Yes": "No") << endl;



  return 0;

}

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

#define MAXN 101000

int N, M;

int f[MAXN], dis[MAXN];

void init()

{

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

	{

		f[i] = i;

	}

}

int find(int x)

{

	if (f[x] == x)

		return x;

	else

	{

		int r = find(f[x]);

		dis[x] = dis[f[x]] + dis[x];

		return f[x] = r;

	}

}

int find_father(int x,int y,int z)

{

	int fx = find(x);

	int fy = find(y);

	if (fx == fy)

	{

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

	}

	f[fy] = fx;

	dis[fy] = dis[x] + z - dis[y];

	return 1;

}

int main()

{

	int a = 1;

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

	init();

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

	{

		int x, y, z;

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

		if (a)

			a = find_father(x, y, z);

	}

	if (a)

		printf("Yes\n");

	else

		printf("No\n");

	return 0;

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

#include <iostream>

#include <cstring>

#define maxn 2000005

using namespace std;

int Far[maxn],dis[maxn];

void inti(int n){

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

        Far[i]=i;

        dis[i]=0;

    }

}

int find_F(int x){

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

    int tmp=Far[x];

    Far[x]=find_F(Far[x]);

    dis[x]+=dis[tmp];

    return Far[x];

}

int find_D(int x){

    if(Far[x]==x) return 0;

    else return find_D(Far[x])+dis[x];

}

int main()

{

    int n,m;

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

    inti(n);

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

        int a,b,c;

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

        int Fa=find_F(a);

        int Fb=find_F(b);

        if(Fa==Fb){

            if(dis[b]-dis[a]!=c){

                puts("No");

                return 0;

            }

        }

        else{

            Far[Fb]=Fa;

            dis[Fb]=find_D(a)-find_D(b)+c;

        }

    }

    puts("Yes");

}


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

#define MAXN 101000

int N, M;

int f[MAXN], dis[MAXN];

void init()

{

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

	{

		f[i] = i;

	}

}

int find(int x)

{

	if (f[x] == x)

		return x;

	else

	{

		int r = find(f[x]);

		dis[x] = dis[f[x]] + dis[x];

		return f[x] = r;

	}

}

int find_father(int x,int y,int z)

{

	int fx = find(x);

	int fy = find(y);

	if (fx == fy)

	{

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

	}

	f[fy] = fx;

	dis[fy] = dis[x] + z - dis[y];

	return 1;

}

int main()

{

	int a = 1;

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

	init();

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

	{

		int x, y, z;

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

		if (a)

			a = find_father(x, y, z);

	}

	if (a)

		printf("Yes\n");

	else

		printf("No\n");

	return 0;

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

#include<cstdio>

const int N=1e5+5;

int n,m,par[N],dir[N];

void init() {

    for(int i=1;i<=n;i++) par[i]=i,dir[i]=0;

}

int fd(int x) {

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

    int t=par[x];

    par[x]=fd(par[x]);

    dir[x]+=dir[t];

    return par[x];

}

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

    int a=fd(x),b=fd(y);

    if(a==b) return;

    dir[a]=-dir[x]+c+dir[y];

    par[a]=b;

}

int main() {

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

    int l,r,d;init();

    bool ok=true;

    while(m--) {

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

        if(fd(l)!=fd(r)) unite(l,r,d);

        else if(dir[l]-dir[r]!=d) ok=false;

    }

    printf("%s\n",ok?"Yes":"No");

    return 0;

}


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

#define MAXN 101000

int N, M;

int f[MAXN], dis[MAXN];

void init()

{

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

	{

		f[i] = i;

	}

}

int find(int x)

{

	if (f[x] == x)

		return x;

	else

	{

		int r = find(f[x]);

		dis[x] = dis[f[x]] + dis[x];

		return f[x] = r;

	}

}

int find_father(int x,int y,int z)

{

	int fx = find(x);

	int fy = find(y);

	if (fx == fy)

	{

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

	}

	f[fy] = fx;

	dis[fy] = dis[x] + z - dis[y];

	return 1;

}

int main()

{

	int a = 1;

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

	init();

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

	{

		int x, y, z;

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

		if (a)

			a = find_father(x, y, z);

	}

	if (a)

		printf("Yes\n");

	else

		printf("No\n");

	return 0;

}