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



using namespace std;



#define _ << " " <<

#define pb push_back

#define ff first

#define ss second





typedef long long ll;

typedef long double ld;



#define int ll



const int MAXN = 1e5 + 5;



vector<int> used(MAXN);



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



bool bfs(int v) {

    vector<int> q = {v};

    int ind = 0;

    map<int, int> dst;

    dst[v] = 0;

    used[v] = 1;

    while (q.size() > ind) {

        int tmp = q[ind];

        ++ind;

        for (auto to : g[tmp]) {

            if (used[to.ff] == 1) {

                if (dst[to.ff] != dst[tmp] + to.ss) return false;

            } else {

                dst[to.ff] = dst[tmp] + to.ss;

                used[to.ff] = 1;

                q.pb(to.ff);

            }

        }

    }

    return true;

}



void solve() {

    int n, m;

    cin >> n >> m;

    int l, r, d;

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

        cin >> l >> r >> d;

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

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

    }

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

        if (used[i] == 0 && !bfs(i)) {

            cout << "No";

            return;

        }

    }

    cout << "Yes";

}



signed main() {

    ios_base::sync_with_stdio(false);

    cin.tie(nullptr);

    cout.tie(nullptr);

    //freopen("dominoes.in", "r", stdin);

    //freopen("dominoes.out", "w", stdout);

    int test = 1;

    //cin >> test;

    while (test--) {

        solve();

    }

}


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

using namespace std;

#define int long long

#define vi vector<int>

#define fileopen(filename) if (fopen(filename".INP", "r")) {freopen(filename".INP", "r", stdin);freopen(filename".OUT", "w", stdout);}

#define fastio ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);

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

#define eb emplace_back

#define pb push_back

#define memset(a,i) memset(a,i,sizeof(a))

#define upper(v,a) upper_bound(v.begin(), v.end(), a)

#define lower(v,a) lower_bound(v.begin(), v.end(), a)

#define ii pair<int,int>

#define fi first

#define se second

#define endl '\n'

#define gcd __gcd

const int maxn=1e5+1;

const int INF=1e9+1;



bool used[maxn];

vector<ii> adj[maxn];



void dfs(int dis[],int node, int dist)

{

	used[node]=1;

	for (ii i : adj[node])

		if (!used[i.fi])

		{

			dis[i.fi]=dist+i.se;

			dfs(dis,i.fi,dist+i.se);

		}	

		else if (dist+i.se!=dis[i.fi])

		{

			//cout<<node<<' '<<i.fi;

			cout<<"No";exit(0);

			

		}

}



signed main()

{

	fastio;

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

	while (m--)

	{

		int a,b,c;cin>>a>>b>>c;

		adj[a].eb(ii(b,c));

		adj[b].eb(ii(a,-c));

	}

	rep(i,n)if (!used[i])

	{

		int a[n+1];

		a[i]=0;

		dfs(a,i,0);

	}

	cout<<"Yes";

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



#define fi first

#define se second

#define ll long long



const int N = 200200;



using namespace std;



int n, m;

long long a[N];

int res = 1;

long long L, R;

bool used[N];

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



void dfs(int x, long long c)

{

        if(used[x]){

                res &= (a[x] == c);

                return;

        }

        used[x] = 1;

        L = min(L, c);

        R = max(R, c);

        a[x] = c;

        for(auto y: v[x]){

                dfs(y.fi, c + y.se);

        }

}



int main()

{

        ios_base::sync_with_stdio(0);



        //freopen("input.txt", "r", stdin);

        //freopen("output.txt", "w", stdout);



        cin >> n >> m;

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

                int a, b, d;

                cin >> a >> b >> d;

                v[a].push_back({b, d});

                v[b].push_back({a, - d});

        }

        long long inf = 1e9;

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

                if(!used[i]){

                        L = R = 0;

                        dfs(i, 0);

                        res &= (R - L <= inf);

                }

        }

        cout << (res ? "Yes" : "No") << "\n";

}


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

using namespace std;

#define int long long

#define vi vector<int>

#define fileopen(filename) if (fopen(filename".INP", "r")) {freopen(filename".INP", "r", stdin);freopen(filename".OUT", "w", stdout);}

#define fastio ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);

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

#define eb emplace_back

#define pb push_back

#define memset(a,i) memset(a,i,sizeof(a))

#define upper(v,a) upper_bound(v.begin(), v.end(), a)

#define lower(v,a) lower_bound(v.begin(), v.end(), a)

#define ii pair<int,int>

#define fi first

#define se second

#define endl '\n'

#define gcd __gcd

const int maxn=1e5+1;

const int INF=1e9+1;



bool used[maxn];

vector<ii> adj[maxn];



void dfs(int dis[],int node, int dist)

{

	used[node]=1;

	for (ii i : adj[node])

		if (!used[i.fi])

		{

			dis[i.fi]=dist+i.se;

			dfs(dis,i.fi,dist+i.se);

		}	

		else if (dist+i.se!=dis[i.fi])

		{

			//cout<<node<<' '<<i.fi;

			cout<<"No";exit(0);

			

		}

}



signed main()

{

	fastio;

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

	while (m--)

	{

		int a,b,c;cin>>a>>b>>c;

		adj[a].eb(ii(b,c));

		adj[b].eb(ii(a,-c));

	}

	rep(i,n)if (!used[i])

	{

		int a[n+1];

		a[i]=0;

		dfs(a,i,0);

	}

	cout<<"Yes";

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

using namespace std;

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

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

#define ALL(v) (v).begin(),(v).end()

#define fi first

#define se second

template<typename A, typename B> inline bool chmax(A &a, B b) { if (a<b) { a=b; return 1; } return 0; }

template<typename A, typename B> inline bool chmin(A &a, B b) { if (a>b) { a=b; return 1; } return 0; }

typedef long long ll;

typedef pair<int, int> pii;

const ll INF = 1e9+100;

const ll MOD = 1e9+7;

const bool debug = 0;

//-----------------------------------------------//



int N, M;

int dist[112345];

vector<pii> g[112345];



int main() {

	cin >> N >> M;

	REP(i, M) {

		int a, b, d;

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

		a--; b--;

		g[a].push_back(pii(b, d));

		g[b].push_back(pii(a, -d));

	}

	

	fill(dist, dist + N, INF);

	REP(st, N) {

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

		

		queue<int> que;

		que.push(st);

		dist[st] = 0;

		

		while (!que.empty()) {

			int u = que.front(); que.pop();

			

			REP(i, g[u].size()) {

				int v = g[u][i].fi;

				int ncost = dist[u] + g[u][i].se;

				

				if (dist[v] == INF) {

					dist[v] = ncost;

					que.push(v);

				}

				else if (dist[v] != ncost) {

					puts("No");

					return 0;

				}

				

			}

		}

	}

	

	puts("Yes");

	

	return 0;

}


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

using namespace std;

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

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

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

#define fi first

#define se second

template<typename A, typename B> inline bool chmax(A &a, B b) { if (a<b) { a=b; return 1; } return 0; }

template<typename A, typename B> inline bool chmin(A &a, B b) { if (a>b) { a=b; return 1; } return 0; }

using ll = long long;

using pii = pair<int, int>;

constexpr ll INF = 1ll<<30;

constexpr ll longINF = 1ll<<60;

constexpr ll MOD = 1000000007;

constexpr bool debug = 0;

//---------------------------------//



int main() {

	int N, M;

	cin >> N >> M;

	vector<int> L(M), R(M), D(M);

	REP(i, M) scanf("%d %d %d", &L[i], &R[i], &D[i]), --L[i], --R[i];

	

	vector<vector<pii>> g(N);

	REP(i, M) {

		g[L[i]].emplace_back(R[i], D[i]);

		g[R[i]].emplace_back(L[i], -D[i]);

	}

	

	vector<int> x(N, -1), done(N, false);

	

	bool ok = true;

	

	REP(i, N) {

		if (done[i]) continue;

		queue<int> que;

		que.push(i);

		done[i] = true;

		x[i] = 0;

		while (!que.empty()) {

			int u = que.front(); que.pop();

			

			for (pii e : g[u]) {

				int v = e.fi, d = e.se;

				if (chmax(done[v], true)) {

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

					que.push(v);

				}

				else {

					ok &= x[v] == x[u] + d;

				}

			}

		}

	}

	

	puts([&] {

		return ok;

	}() ? "Yes": "No");

	

	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;



const ll INF = 1LL << 60;



vector< vector< pair<int,int> > > to(100005);

vector< ll > pos(100005, INF);

set<int> A;



bool DFS( int v ) {

  bool ok = true;

//  cout << v << " : " << pos[v] << endl;

  for ( auto nv : to[v] ) {

//    cout << " " << nv.first << ", " << nv.second << " : " << pos[nv.first] << endl;

    if ( pos[nv.first] == INF ) {

      pos[nv.first] = pos[v] + nv.second;

      if (pos[nv.first] > 1000000000 && pos[nv.first] != INF) return false;

      ok = DFS( nv.first );

      if (!ok ) return ok;

    } else {

      if ( pos[nv.first] != pos[v] + nv.second ) {

//        cout << " false" << endl;

        return false;

      }

    }

  }

  return ok;

}



int main() {

  int N, M;

  cin >> N >> M;

  REP(i,M) {

    int l,r,d;

    cin >> l >> r >> d;

    to[l].emplace_back( r, d );

    to[r].emplace_back( l, -d );

    A.emplace(r);

    A.emplace(l);

  }

  for ( auto v : A ) {

    if ( pos[v] != INF ) continue;

    pos[v] = 0;

    if ( DFS( v ) == false ) {

      cout << "No" << endl;

      return 0;

    }

  }

  cout << "Yes" << endl;

}




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

#include <vector>

#include <string>

using namespace std;



template<class Abel> struct UnionFind {

    vector<int> par;

    vector<int> rank;

    vector<Abel> diff_weight;



    UnionFind(int n = 1, Abel SUM_UNITY = 0) {

        init(n, SUM_UNITY);

    }



    void init(int n = 1, Abel SUM_UNITY = 0) {

        par.resize(n); rank.resize(n); diff_weight.resize(n);

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

    }



    int root(int x) {

        if (par[x] == x) {

            return x;

        }

        else {

            int r = root(par[x]);

            diff_weight[x] += diff_weight[par[x]];

            return par[x] = r;

        }

    }



    Abel weight(int x) {

        root(x);

        return diff_weight[x];

    }



    bool issame(int x, int y) {

        return root(x) == root(y);

    }



    bool merge(int x, int y, Abel w) {

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

        x = root(x); y = root(y);

        if (x == y) return false;

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

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

        par[y] = x;

        diff_weight[y] = w;

        return true;

    }



    Abel diff(int x, int y) {

        return weight(y) - weight(x);

    }

};



int main() {

    int N, M;

    cin >> N >> M;

    UnionFind<int> uf(N);

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

        int l, r, d;

        cin >> l >> r >> d;

        --l, --r;

        if (uf.issame(l, r)) {

            int diff = uf.diff(l, r);

            if (diff != d) {

                cout << "No" << endl;

                return 0;

            }

        }

        else {

            uf.merge(l, r, d);

        }

    }

    cout << "Yes" << endl;

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



using namespace std;



typedef long long ll;

ll N, M, R, L, D, path[100000], loc[100000];



int main() {

  cin >> N >> M;



  vector<vector<pair<ll, ll> > > vec(N);

  memset(path, 0, sizeof(path));

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

    cin >> L >> R >> D;

    L--;

    R--;

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

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

  }



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

    if (!path[i]) {

      path[i]++;

      queue<ll> que;

      que.push(i);



      while(!que.empty()) {

        ll q = que.front();

        que.pop();



        for (auto x : vec[q]) {

          if (!path[x.first]) {

            loc[x.first] = loc[q] + x.second;

            path[x.first]++;

            que.push(x.first);

          } else {

            if (loc[x.first] != loc[q] + x.second) {

              cout << "No" << endl;

              return 0;

            }

          }

        }

      }

    }

  }

  cout << "Yes" << endl;

  return 0;

}

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

#include <set>

#include <map>

#include <vector>

#include <algorithm>

#include <iomanip>

#include <climits>

#include <numeric>

#include <cmath>

#include <queue>

#include <sstream>

#include <string.h>

#include <bitset>

#include <stack>



using namespace std;

typedef long long ll;



template<class Abel> struct UnionFind {

  vector<int> par;

  vector<int> rank;

  vector<Abel> diff_weight;

  

  UnionFind(int n = 1, Abel SUM_UNITY = 0) {

    init(n, SUM_UNITY);

  }

  

  void init(int n = 1, Abel SUM_UNITY = 0) {

    par.resize(n); rank.resize(n); diff_weight.resize(n);

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

  }

  

  int root(int x) {

    if (par[x] == x) {

      return x;

    }

    else {

      int r = root(par[x]);

      diff_weight[x] += diff_weight[par[x]];

      return par[x] = r;

    }

  }

  

  Abel weight(int x) {

    root(x);

    return diff_weight[x];

  }

  

  bool issame(int x, int y) {

    return root(x) == root(y);

  }

  

  bool merge(int x, int y, Abel w) {

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

    x = root(x); y = root(y);

    if (x == y) return false;

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

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

    par[y] = x;

    diff_weight[y] = w;

    return true;

  }

  

  Abel diff(int x, int y) {

    return weight(y) - weight(x);

  }

};



int main() {

  int N, M;

  cin >> N >> M;

  UnionFind<int> uf(N);

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

    int l, r, d;

    cin >> l >> r >> d;

    --l, --r;

    if (uf.issame(l, r)) {

      int diff = uf.diff(l, r);

      if (diff != d) {

        cout << "No" << endl;

        return 0;

      }

    }

    else {

      uf.merge(l, r, d);

    }

  }

  cout << "Yes" << endl;

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

using namespace std;

typedef long long ll;

#define INF 1LL<<62

#define inf 1000000007



vector<vector<ll>>a(100010);

vector<vector<ll>>c(100010);

ll p[100010];

bool ans=true;

void dep(ll now,ll oya,ll co){

	if(p[now]!=INF){

		if(p[now]!=co){

			ans=false;

		}

		return ;

	}

	p[now]=co;

	if(a[now].size()==1&&a[now][0]==oya){

		return;

	}

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

		ll next=a[now][i];

		dep(next,now,co+c[now][i]);

	}

}

int main() {

	ll n,m;

	cin>>n>>m;

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

		p[i]=INF;

	}

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

		ll x,y,z;

		cin>>x>>y>>z;

		x--,y--;

		a[x].push_back(y);

		c[x].push_back(z);

		a[y].push_back(x);

		c[y].push_back(-1*z);

	}

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

		if(p[i]!=INF){

			continue;

		}

		dep(i,-1,0);

	}

	cout << (ans?"Yes":"No");

	// your code goes here

	return 0;

}

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

using namespace std;

typedef long long ll;

#define INF 1LL<<62

#define inf 1000000007



bool ans=true;

vector<pair<ll,ll>>a[100010];

ll co[100010];

void dep(ll now,ll cos){

	for(ll i=0;i<a[now].size();i++){

		ll next=a[now][i].first;

		ll val=a[now][i].second;

		if(co[next]!=INF){

			ll ch=co[now]+val;

			if(ch!=co[next]){

				ans=false;

			}

			continue;

		}

		co[next]=co[now]+val;

		dep(next,co[next]);

	}

}

int main() {

	ll n,m;

	cin>>n>>m;

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

		ll x,y,z;

		cin>>x>>y>>z;

		x--;y--;

		a[x].push_back(make_pair(y,z));

		a[y].push_back(make_pair(x,-1*z));

	}

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

		co[i]=INF;

	}

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

		if(co[i]!=INF){

			continue;

		}

		co[i]=0;

		dep(i,co[i]);

	}

	cout << (ans?"Yes":"No");

	// your code goes here

	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: 1.9590879904228111x):
#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<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: 3.5496230536617976x):
#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<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.814180854879663x):
#include<bits/stdc++.h>

using namespace std;

const int MAXN=100007;

typedef long long ll;

struct node {

    int v,w;

    node(int x=0,int y=0) {

        v=x,w=y;

    }

};

int deg[MAXN],X,n,m,x1,x2,y,tot[MAXN];

ll pos[MAXN];

bool vis[MAXN];

char c;

vector<node> edge[MAXN];

inline char nc(){

	static char buf[100000],*p1=buf,*p2=buf;

	return p2==p1&&(p2=(p1=buf)+fread(buf,1,100000,stdin),p1==p2)?EOF:*p1++;

}

int read() {

    X=0,c=nc();

    while(!isdigit(c))c=nc();

    while(isdigit(c))X=(X<<1)+(X<<3)+c-'0',c=nc();

    return X;

}

bool ok;

bool check(int &u) {

    vis[u]=true;

    for(int i=0; i<tot[u]; i++) {

        if(vis[edge[u][i].v]) {

            if(pos[edge[u][i].v]-edge[u][i].w!=pos[u])return false;

        } else {

            pos[edge[u][i].v]=pos[u]+edge[u][i].w;

            if(!check(edge[u][i].v))return false;

            else continue;

        }

    }

    return true;

}

int main() {

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

        if(!m){

            puts("Yes");

            return 0;

        }

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

            x1=read(),x2=read(),y=read();

            tot[x1]++;

            deg[x2]++;

            edge[x1].push_back(node(x2,y));

        }

        for(int i=0; i<n; i++)if(!deg[i]&&tot[i]) {

                ok=1;

                if(!check(i)) {

                    puts("No");

                    return 0;

                }

            };

        if(!ok) {

            puts("No");

            return 0;

        }

        puts("Yes");

        return 0;

}