stablegradients/pie-gem5-pairs huggingface dataset:
// 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: 1.2263638058831023x):
#include <bits/stdc++.h>

#define x first

#define y second

using namespace std;

typedef long long ll;

const int N = 1e5 + 10;

const int mod = 1e9 + 7;

#define int long long

int n, m;

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



bool used[N];

int pos[N];



void dfs(int u)

{

    used[u] = 1;

    for (auto t : gr[u])

    {

        int v = t.x;

        int d = t.y;

        if (!used[v])

        {

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

            dfs(v);

        } else

        {

            if (pos[v] != pos[u] + d)

            {

                cout << "No";

                exit(0);

            }

        }

    }

}



main()

{

    ios_base::sync_with_stdio(0);

    cin.tie(0);



    cin >> n >> m;

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

    {

        int l, r;

        int d;

        cin >> l >> r >> d;

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

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

    }

    int ma = -1e18, mi = 1e18;

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

    {

        if (!used[i])

        {

            pos[i] = 0;

            dfs(i);

        }

        ma = max(ma, pos[i]);

        mi = min(mi, pos[i]);

    }



    if (ma - mi > 1e9)

    {

        cout << "Noe";

    } else cout << "Yes";





    return 0;

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

using namespace std;



int n,m;

vector <pair<int,int> > a[200002];

bool vis[100001];

int d[100001];



bool dfs(int x,int y) {

	if (vis[x]) return d[x]!=y;

	vis[x]=true;

	d[x]=y;

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

		if (dfs(a[x][i].first,d[x]+a[x][i].second)) return true;

	}

	return false;

}



int main(){

	memset(vis,false,sizeof(vis));

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

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

		int x,y,z;

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

		x--;y--; 

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

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

	}

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

		if (!vis[i]&&dfs(i,0)) {

			cout<<"No"<<endl;

			return 0;

		}

	}

	cout<<"Yes"<<endl;

	return 0;

}

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

#define x first

#define y second

using namespace std;

typedef long long ll;

const int N = 1e5 + 10;

const int mod = 1e9 + 7;

#define int long long

int n, m;

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



bool used[N];

int pos[N];



void dfs(int u)

{

    used[u] = 1;

    for (auto t : gr[u])

    {

        int v = t.x;

        int d = t.y;

        if (!used[v])

        {

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

            dfs(v);

        } else

        {

            if (pos[v] != pos[u] + d)

            {

                cout << "No";

                exit(0);

            }

        }

    }

}



main()

{

    ios_base::sync_with_stdio(0);

    cin.tie(0);



    cin >> n >> m;

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

    {

        int l, r;

        int d;

        cin >> l >> r >> d;

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

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

    }

    int ma = -1e18, mi = 1e18;

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

    {

        if (!used[i])

        {

            pos[i] = 0;

            dfs(i);

        }

        ma = max(ma, pos[i]);

        mi = min(mi, pos[i]);

    }



    if (ma - mi > 1e9)

    {

        cout << "Noe";

    } else cout << "Yes";





    return 0;

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

#include <algorithm>

#include <cstdio>

#include <cstdlib>

#include <cstring>

#include <cmath>

#include <iomanip>

#define inf -2147483647

using namespace std;

struct info

{

    int l,r,d;

}s[400005];

int n,m;

int flag = 1;

int dis[100005],visited[100005];

int first[400005],nexti[400005];

void dfs(int t)

{

    if(!flag)return;

    int k = first[t];

    while(k != -1)

    {

        if(!flag)return;

        if(!visited[s[k].r])

        {

            dis[s[k].r] = dis[s[k].l] + s[k].d;

            visited[s[k].r] = 1;

            dfs(s[k].r);

        }

        else if(s[k].d != dis[s[k].r] - dis[s[k].l])

        {

            flag = 0;

            return;

        }

        k = nexti[k];

    }

}

int main()

{

    cin>>n>>m;

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

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

    {

        cin>>s[i].l>>s[i].r>>s[i].d;

        nexti[i] = first[s[i].l];

        first[s[i].l] = i;

        s[i + m].r = s[i].l;

        s[i + m].l = s[i].r;

        s[i + m].d = -s[i].d;

        nexti[i + m] = first[s[i + m].l];

        first[s[i + m].l] = i + m;

    }

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

    {

        if(!visited[i])

        {

            visited[i] = 1;

            memset(dis,0,sizeof(dis));

            dfs(i);

        }

    }

    if(flag)cout<<"Yes";

    else cout<<"No";

}


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

#include <iostream>

#include<cstdio>

#include <stack>

#include <vector>

using namespace std;

#define INF 0x7ffffff

typedef long long ll;

const int maxn=1e5+10;

int pre[maxn];

int dis[maxn];

int findset(int x)

{

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

    int root=findset(pre[x]);

    dis[x]=dis[pre[x]]+dis[x];

    return pre[x]=root;

}

bool unionset(int x,int y,int w)

{

    int fx=findset(x),fy=findset(y);

    if(fx==fy)

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

    pre[fy]=fx;

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

    return true;

}

int n,m;

int main()

{

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

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

    pre[i]=i;

   bool lose=true;

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

   {

       int x,y,w;

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

        if(lose)

       lose=unionset(x,y,w);

   }

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

   else     printf("No\n");

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

#include <algorithm>

#include <string.h>

#include <stdio.h>

using namespace std;

#define ll long long

const int pmax = 100005;

const int emax = 400005;

struct node { int to; int w; int next; } edge[emax];

int head[pmax], id = 0, vis[pmax];

int dis[pmax];

inline void add(int x, int y, int w) {

    edge[id].to = y;

    edge[id].w = w;

    edge[id].next = head[x];

    head[x] = id++;

}



bool dfs(int u) {

    vis[u] = 1;

    for (int i = head[u]; ~i; i = edge[i].next) {

        int v = edge[i].to;

        if (!vis[v]) {

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

            if (!dfs(v)) return false;

        } else if (dis[u]+edge[i].w != dis[v]) return false;

    }

    return true;

}

int main(int argc, char const *argv[])

{

    int n, m;

    int a, b, c;

    memset(head, -1, sizeof head);

    memset(vis, 0, sizeof vis);

    memset(dis, 0, sizeof dis);

    cin >> n >> m;

    while (m--) {

        cin >> a >> b >> c;

        add(a, b, c); add(b, a, -c);

    }

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

        if (!vis[i]) {

            if (!dfs(i)) return 0*printf("No\n");

        }

    printf("Yes\n");

    return 0;

}


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

#include <iostream>

#include<cstdio>

#include <stack>

#include <vector>

using namespace std;

#define INF 0x7ffffff

typedef long long ll;

const int maxn=1e5+10;

int pre[maxn];

int dis[maxn];

int findset(int x)

{

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

    int root=findset(pre[x]);

    dis[x]=dis[pre[x]]+dis[x];

    return pre[x]=root;

}

bool unionset(int x,int y,int w)

{

    int fx=findset(x),fy=findset(y);

    if(fx==fy)

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

    pre[fy]=fx;

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

    return true;

}

int n,m;

int main()

{

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

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

    pre[i]=i;

   bool lose=true;

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

   {

       int x,y,w;

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

        if(lose)

       lose=unionset(x,y,w);

   }

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

   else     printf("No\n");

}
// 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.42475308694457x):
#include<string.h>

#include <iostream>

#include<cstdio>

#include <stack>

#include <vector>

using namespace std;

#define INF 0x7ffffff

typedef long long ll;

const int maxn=1e5+10;

int pre[maxn];

int dis[maxn];

int findset(int x)

{

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

    int root=findset(pre[x]);

    dis[x]=dis[pre[x]]+dis[x];

    return pre[x]=root;

}

bool unionset(int x,int y,int w)

{

    int fx=findset(x),fy=findset(y);

    if(fx==fy)

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

    pre[fy]=fx;

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

    return true;

}

int n,m;

int main()

{

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

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

    pre[i]=i;

   bool lose=true;

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

   {

       int x,y,w;

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

        if(lose)

       lose=unionset(x,y,w);

   }

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

   else     printf("No\n");

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

using namespace std;



int n,m;

vector <pair<int,int> > a[200002];

bool vis[100001];

int d[100001];



bool dfs(int x,int y) {

	if (vis[x]) return d[x]!=y;

	vis[x]=true;

	d[x]=y;

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

		if (dfs(a[x][i].first,d[x]+a[x][i].second)) return true;

	}

	return false;

}



int main(){

	memset(vis,false,sizeof(vis));

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

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

		int x,y,z;

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

		x--;y--; 

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

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

	}

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

		if (!vis[i]&&dfs(i,0)) {

			cout<<"No"<<endl;

			return 0;

		}

	}

	cout<<"Yes"<<endl;

	return 0;

}

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

#include <iostream>

#include<cstdio>

#include <stack>

#include <vector>

using namespace std;

#define INF 0x7ffffff

typedef long long ll;

const int maxn=1e5+10;

int pre[maxn];

int dis[maxn];

int findset(int x)

{

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

    int root=findset(pre[x]);

    dis[x]=dis[pre[x]]+dis[x];

    return pre[x]=root;

}

bool unionset(int x,int y,int w)

{

    int fx=findset(x),fy=findset(y);

    if(fx==fy)

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

    pre[fy]=fx;

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

    return true;

}

int n,m;

int main()

{

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

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

    pre[i]=i;

   bool lose=true;

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

   {

       int x,y,w;

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

        if(lose)

       lose=unionset(x,y,w);

   }

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

   else     printf("No\n");

}
// Slower C++ solution:
/**********************************************************************/

/********                                                      ********/

/********                     Writer:孙~~                      ********/

/********                       Lang:C++                       ********/

/********                     Status:Unknow                    ********/

/********                                                      ********/

/**********************************************************************/

#include <iostream>

#include <string>

#include <cstdio>

#include <vector>

#include <queue>

#include <list>

#include <cstdlib>

#include <algorithm>

#include <set>

#include <map>

#include <deque>

#include <cstring>

#include <cmath>

//#include<bits/stdc++.h>

using namespace std;



const int INF=0x3f3f3f3f;

const int SIZE=100005;



int n,m;

vector<pair<int,int> > mp[SIZE];

bool vis[SIZE];

long long val[SIZE];



bool bfs(int i){

	queue<int> que;

	que.push(i);

	val[i]=0;

	while(!que.empty()){

		int v=que.front();

		que.pop();

		for(int i=0;i<mp[v].size();i++){

			pair<int,int> u=mp[v][i];

			int to=u.first;

			if(val[to]==INF){

				val[to]=val[v]+u.second;

				que.push(to);

			}

			else if(val[to]!=val[v]+u.second){

				return false;

			}

		}

	}

	return true;

}



int main(){

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

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

		int l,r,d;

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

		l--;

		r--;

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

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

	}

	for(int i=0;i<n;i++) val[i]=INF;

	for(int i=0;i<n;i++) if(val[i]==INF) if(!bfs(i)){

		puts("No");

		return 0;

	}

	puts("Yes");

	return 0;

}






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

#include <iostream>

#include<cstdio>

#include <stack>

#include <vector>

using namespace std;

#define INF 0x7ffffff

typedef long long ll;

const int maxn=1e5+10;

int pre[maxn];

int dis[maxn];

int findset(int x)

{

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

    int root=findset(pre[x]);

    dis[x]=dis[pre[x]]+dis[x];

    return pre[x]=root;

}

bool unionset(int x,int y,int w)

{

    int fx=findset(x),fy=findset(y);

    if(fx==fy)

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

    pre[fy]=fx;

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

    return true;

}

int n,m;

int main()

{

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

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

    pre[i]=i;

   bool lose=true;

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

   {

       int x,y,w;

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

        if(lose)

       lose=unionset(x,y,w);

   }

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

   else     printf("No\n");

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

#define x first

#define y second

using namespace std;

typedef long long ll;

const int N = 1e5 + 10;

const int mod = 1e9 + 7;

#define int long long

int n, m;

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



bool used[N];

int pos[N];



void dfs(int u)

{

    used[u] = 1;

    for (auto t : gr[u])

    {

        int v = t.x;

        int d = t.y;

        if (!used[v])

        {

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

            dfs(v);

        } else

        {

            if (pos[v] != pos[u] + d)

            {

                cout << "No";

                exit(0);

            }

        }

    }

}



main()

{

    ios_base::sync_with_stdio(0);

    cin.tie(0);



    cin >> n >> m;

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

    {

        int l, r;

        int d;

        cin >> l >> r >> d;

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

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

    }

    int ma = -1e18, mi = 1e18;

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

    {

        if (!used[i])

        {

            pos[i] = 0;

            dfs(i);

        }

        ma = max(ma, pos[i]);

        mi = min(mi, pos[i]);

    }



    if (ma - mi > 1e9)

    {

        cout << "Noe";

    } else cout << "Yes";





    return 0;

}


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

#include <iostream>

#include<cstdio>

#include <stack>

#include <vector>

using namespace std;

#define INF 0x7ffffff

typedef long long ll;

const int maxn=1e5+10;

int pre[maxn];

int dis[maxn];

int findset(int x)

{

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

    int root=findset(pre[x]);

    dis[x]=dis[pre[x]]+dis[x];

    return pre[x]=root;

}

bool unionset(int x,int y,int w)

{

    int fx=findset(x),fy=findset(y);

    if(fx==fy)

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

    pre[fy]=fx;

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

    return true;

}

int n,m;

int main()

{

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

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

    pre[i]=i;

   bool lose=true;

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

   {

       int x,y,w;

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

        if(lose)

       lose=unionset(x,y,w);

   }

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

   else     printf("No\n");

}
// 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: 1.234128696761824x):
#include <bits/stdc++.h>

#define all(x) begin(x), end(x)

#define _ << ' ' <<

using namespace std;

using ll = long long;



int dest[100005];

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

int vis[100005];

vector<int> sol;



void dfs(int x)

{

    if (vis[x])

        return;



    vis[x] = 1;

    for (auto p : adj[x])

        dfs(p.first);

    sol.push_back(x);

}



int main()

{

    int n, m;

    cin >> n >> m;

    vector<tuple<int, int, int>> v;

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

    {

        int l, r, d;

        cin >> l >> r >> d;

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

    }

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

        dfs(i);



    reverse(all(sol));

    for (int x : sol)

    {

        for (auto p : adj[x])

        {

            int y, d;

            tie(y, d) = p;

            if (!dest[x]) dest[x] = 1;

            if (!dest[y]) dest[y] = dest[x] + d;

            if (dest[y] != dest[x] + d)

                return cout << "No", 0;

        }

    }

    cout << "Yes";

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

using namespace std;



int n,m;

vector <pair<int,int> > a[200002];

bool vis[100001];

int d[100001];



bool dfs(int x,int y) {

	if (vis[x]) return d[x]!=y;

	vis[x]=true;

	d[x]=y;

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

		if (dfs(a[x][i].first,d[x]+a[x][i].second)) return true;

	}

	return false;

}



int main(){

	memset(vis,false,sizeof(vis));

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

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

		int x,y,z;

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

		x--;y--; 

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

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

	}

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

		if (!vis[i]&&dfs(i,0)) {

			cout<<"No"<<endl;

			return 0;

		}

	}

	cout<<"Yes"<<endl;

	return 0;

}

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

#define all(x) begin(x), end(x)

#define _ << ' ' <<

using namespace std;

using ll = long long;



int dest[100005];

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

int vis[100005];

vector<int> sol;



void dfs(int x)

{

    if (vis[x])

        return;



    vis[x] = 1;

    for (auto p : adj[x])

        dfs(p.first);

    sol.push_back(x);

}



int main()

{

    int n, m;

    cin >> n >> m;

    vector<tuple<int, int, int>> v;

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

    {

        int l, r, d;

        cin >> l >> r >> d;

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

    }

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

        dfs(i);



    reverse(all(sol));

    for (int x : sol)

    {

        for (auto p : adj[x])

        {

            int y, d;

            tie(y, d) = p;

            if (!dest[x]) dest[x] = 1;

            if (!dest[y]) dest[y] = dest[x] + d;

            if (dest[y] != dest[x] + d)

                return cout << "No", 0;

        }

    }

    cout << "Yes";

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

#include <cstdio>

#include <string>

#include <algorithm>

#include <utility>

#include <cmath>

#include <vector>

#include <queue>

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

using namespace std;

typedef long long ll;

const ll mod = 1000000007;



struct edge {

    int to;

    int weight;

};



vector<edge> G[200010];

bool visit[100010];

int d[100010];



bool dfs(int v, int dist) {



    if(visit[v]) {

        if(d[v] != dist) {

            return true;

        }

        else {

            return false;

        }

    }



    visit[v] = true;

    d[v] = dist;

    rep(i, G[v].size()) {

        if(dfs(G[v][i].to, d[v] + G[v][i].weight)) {

            return true;

        }

    }



    return false;

}



int main() {

    int n, m;

    cin >> n >> m;



    rep(i, m) {

        int L, R, D;

        cin >> L >> R >> D;

        L--;  R--;

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

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

    }



    rep(i, n) {

        if(!visit[i] && dfs(i, 0)) {

            cout << "No" << endl;

            return 0;

        }

    }

    

    cout << "Yes" << endl;

    return 0;

}

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

#include <cstdio>

#include <string>

#include <algorithm>

#include <utility>

#include <cmath>

#include <vector>

#include <queue>

#include <set>

#include <map>

using namespace std;

typedef long long ll;

typedef vector<ll> vl;

typedef vector<vector<ll>> vvl;

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

#define exrep(i, a, b) for(ll i = a; i <= b; i++)

#define out(x) cout << x << endl

#define exout(x) printf("%.10f\n", x)

#define chmax(x, y) x = max(x, y)

#define chmin(x, y) x = min(x, y)

#define all(a) a.begin(), a.end()

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

#define pb push_back

#define re0 return 0

const ll mod = 1000000007;

const ll INF = 1e16;

const ll MAX_N = 100010;



vector<vector<pair<ll, ll>>> G;

vl visited;

vl d(MAX_N);

bool ok = true;



void dfs(ll v, ll dist) {

    if(visited[v]) {

        if(d[v] != dist) {

            ok = false;

            return;

        }

        return;

    }

    visited[v] = 1;

    d[v] = dist;

    for(auto p : G[v]) {

        ll u = p.first;

        ll cost = p.second;

        dfs(u, d[v] + cost);

    }

    return;

}



int main() {

    ll n, m;

    cin >> n >> m;    



    G.resize(n);

    rep(i, m) {

        ll L, R, D;

        cin >> L >> R >> D;

        L--;  R--;

        G[L].pb(make_pair(R, D));

        G[R].pb(make_pair(L, -D));

    }



    visited.resize(n);

    rep(v, n) {

        if(!visited[v]) {

            dfs(v, 0);

        }

    }



    if(ok) {

        out("Yes");

    }

    else {

        out("No");

    }

    

    re0;

}