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

using namespace std;

int n,m,dis[200001],l,r,d;

bool Error,f[200001];

struct edge {

	int to,cost;

	edge(int a=0,int b=0) {

		to=a;

		cost=b;

	}

};

vector<edge> path[200001];

void spfa(int x) {

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

		edge e=path[x][i];

		if(f[e.to])

			if(e.cost+dis[x]!=dis[e.to]) {

				Error=true;

				return;

			} else continue;

		f[e.to]=true;

		dis[e.to]=dis[x]+e.cost;

		spfa(e.to);

		if(Error) return;

	}

}

int main() {

	cin>>n>>m;

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

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

		path[l].push_back(edge(r,d));

		path[r].push_back(edge(l,-d));

	}

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

		if(!f[i]) {

			spfa(i);

			if(Error) break;

		}

	}

	if(!Error) printf("Yes");

	else printf("No");

	return 0;

}

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

using namespace std;



typedef long long lint;

typedef pair<int, int> P;

#define REP(i, x, n) for(lint i = x ; i < n ; i++)

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

#define repr(i, n) for(lint i = n - 1 ; i >= 0 ; i--)

#define SORT(c) sort((c).begin(), (c).end())



const int IINF = 1e9 + 10;

const lint LLINF = (lint)1e18 + 10;

const lint MOD = (lint)1e9 + 7;

const int dx[] = {1, 0, -1, 0}, dy[] = {0, 1, 0, -1};

const int dx8[] = {1, 1, 0, -1, -1, -1, 0, 1}, dy8[] = {0, -1, -1, -1, 0, 1, 1, 1};



struct weightedUnionFind{



    vector<int> par, rank, wei;



    void init(int n){

        par.resize(n);

        rank.resize(n, 0);

        wei.resize(n, 0);

        rep(i, n){

            par[i] = i;

        }

        return;

    }



    int root(int x){

        if(par[x] == x){

            return x;

        }else{

            int r = root(par[x]);

            wei[x] += wei[par[x]];

            return par[x] = r;

        }

    }



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

        w = -w;

        w += weight(x);

        w -= weight(y);

        int rx = root(x);

        int ry = root(y);

        if(rx == ry){

            return false;

        }

        if(rank[rx] < rank[ry]){

            swap(rx, ry);

            w = -w;

        }

        if(rank[rx] == rank[ry]){

            rank[rx]++;

        }

        par[ry] = rx;

        wei[ry] = w;

        return true;

    }



    bool same(int x, int y){

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

    }



    int weight(int x){

        root(x);

        return wei[x];

    }



    int diff(int x, int y){

        return weight(x) - weight(y);

    }



};



int main(){

    int n, m;

    cin >> n >> m;

    weightedUnionFind uf;

    uf.init(n);

    bool flag = true;

    rep(i, m){

        int l, r, d;

        cin >> l >> r >> d;

        l--;

        r--;

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

            if(uf.diff(l, r) != d){

                flag = false;

                break;

            }

        }else{

            uf.unite(l, r, d);

        }

    }

    if(flag){

        cout << "Yes" << endl;

    }else{

        cout << "No" << endl;

    }

    return 0;

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

#include<iostream>

#include<cstring>

using namespace std;

struct node_ {

	int v,c,next;

} node[3000001];

int head[1000001],e;

void addnode(int u,int v,int c) {

	e++;

	node[e].c=c;

	node[e].v=v;

	node[e].next=head[u];

	head[u]=e;

}

int n,m;

bool b[1000001],flag;

int d[1000001];

int L,R,D;

bool dfs(int x) {

	b[x]=1;

	for(int i=head[x]; i!=0; i=node[i].next) {

		int y=node[i].v,c=node[i].c;

		if(d[y]>d[x]+c) {

			if(b[y]) return 1;

			d[y]=d[x]+c;

			if(dfs(y))return 1;

		}

	}

	b[x]=0;

	return 0;

}

int main() {

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

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

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

		addnode(R,L,D);

		addnode(L,R,-D);

	}

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

		addnode(0,i,0);

	}

	memset(b,0,sizeof(b));

	memset(d,1000000,sizeof(d));

	d[0]=0;

	if(dfs(0)) printf("No\n");

	else printf("Yes\n");

	return 0;

}

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

using namespace std;



typedef long long lint;

typedef pair<int, int> P;

#define REP(i, x, n) for(lint i = x ; i < n ; i++)

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

#define repr(i, n) for(lint i = n - 1 ; i >= 0 ; i--)

#define SORT(c) sort((c).begin(), (c).end())



const int IINF = 1e9 + 10;

const lint LLINF = (lint)1e18 + 10;

const lint MOD = (lint)1e9 + 7;

const int dx[] = {1, 0, -1, 0}, dy[] = {0, 1, 0, -1};

const int dx8[] = {1, 1, 0, -1, -1, -1, 0, 1}, dy8[] = {0, -1, -1, -1, 0, 1, 1, 1};



struct weightedUnionFind{



    vector<int> par, rank, wei;



    void init(int n){

        par.resize(n);

        rank.resize(n, 0);

        wei.resize(n, 0);

        rep(i, n){

            par[i] = i;

        }

        return;

    }



    int root(int x){

        if(par[x] == x){

            return x;

        }else{

            int r = root(par[x]);

            wei[x] += wei[par[x]];

            return par[x] = r;

        }

    }



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

        w = -w;

        w += weight(x);

        w -= weight(y);

        int rx = root(x);

        int ry = root(y);

        if(rx == ry){

            return false;

        }

        if(rank[rx] < rank[ry]){

            swap(rx, ry);

            w = -w;

        }

        if(rank[rx] == rank[ry]){

            rank[rx]++;

        }

        par[ry] = rx;

        wei[ry] = w;

        return true;

    }



    bool same(int x, int y){

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

    }



    int weight(int x){

        root(x);

        return wei[x];

    }



    int diff(int x, int y){

        return weight(x) - weight(y);

    }



};



int main(){

    int n, m;

    cin >> n >> m;

    weightedUnionFind uf;

    uf.init(n);

    bool flag = true;

    rep(i, m){

        int l, r, d;

        cin >> l >> r >> d;

        l--;

        r--;

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

            if(uf.diff(l, r) != d){

                flag = false;

                break;

            }

        }else{

            uf.unite(l, r, d);

        }

    }

    if(flag){

        cout << "Yes" << endl;

    }else{

        cout << "No" << endl;

    }

    return 0;

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

# include <cstdio>

# include <iostream>

# include <queue>

# define N 100050

# define M 200050 

# define WQD 0x7f7f7f7f

int n;

int m;

struct Edge{int next,to, w;}  e[M<<1];

int head[N+1]; 

int dis[N+1];

bool vis[N+1];

bool book[ N + 1 ] ;

bool spfa(int s);

using namespace std;

int main()

{

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

	memset(book,0,sizeof(book));

	ios::sync_with_stdio ( false ) ;

	int u,v,w;

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

	cin>>n>>m;

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

	{

		cin>>u>>v>>w;

		e[i]=(Edge){head[u],v,w};head[u]=i;

		e[m+i]=(Edge){head[v],u,-w};head[v]=m+i;

	}

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

		if(!vis[i]) 

		{

			vis[i]=1;

			if(!spfa(i))  {cout<<"No";return 0;}

		}

	cout<<"Yes";

	return 0;

}

bool spfa(int s)

{

 	queue<int>q;

//	memset(book,0,sizeof(book));

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

	dis[s]=0;

	q.push(s);book[s]=1;

	while(q.size()>0)

	{

		int k=q.front();q.pop();

		book[k]=0;

		for(int i=head[k]; i!=-1; i=e[i].next)

		{

			int v=e[i].to;

			if(dis[v]==WQD ) 

			{				

				dis[v]=dis[k]+e[i].w;

				if( ! book[v])	{q.push(v);	book[v]=1;}

				vis[v]=1;

			}

			else if(  (dis[v]!=dis[k]+e[i].w) )	return false;

		}		

    }

	return true;

}

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

#include <cstdio>

#define N 1000001

#define M 2000001

#define inf 2147483647

#define int long long

using namespace std;

int n,m,hd[N],t,x,y,z,vis[N],d[N];

int q[N],fst,lst;

struct edge

{

    int to,nt,w;

}e[M];

void add(int u,int v,int w)

{

    e[++t].to=v,e[t].w=w;

    e[t].nt=hd[u],hd[u]=t;

}

bool spfa(int s)

{

    vis[s]=true,q[lst++]=s;

    if(lst==N)lst=0;

    while(lst!=fst)

    {

        int k=q[fst++];

        if(fst==N)fst=0;

        for(int i=hd[k],kk,w;i;i=e[i].nt)

        {

            kk=e[i].to,w=e[i].w;

            if(vis[kk]){if(d[kk]!=d[k]+w)return 1;}

            else

            {

                vis[kk]=true,d[kk]=d[k]+w;

                q[lst++]=kk;

                if(lst==N)lst=0;

            }

        }

    }

    return 0;

}

signed main()

{

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

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

    {

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

        add(x,y,z),add(y,x,-z);

    }

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

        if(vis[i]==0&&spfa(i)){printf("No");return 0;}

    printf("Yes");

    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: 3.571174191142149x):
#include <iostream>

#include <cstdio>

#define N 1000001

#define M 2000001

#define inf 2147483647

#define int long long

using namespace std;

int n,m,hd[N],t,x,y,z,vis[N],d[N];

int q[N],fst,lst;

struct edge

{

    int to,nt,w;

}e[M];

void add(int u,int v,int w)

{

    e[++t].to=v,e[t].w=w;

    e[t].nt=hd[u],hd[u]=t;

}

bool spfa(int s)

{

    vis[s]=true,q[lst++]=s;

    if(lst==N)lst=0;

    while(lst!=fst)

    {

        int k=q[fst++];

        if(fst==N)fst=0;

        for(int i=hd[k],kk,w;i;i=e[i].nt)

        {

            kk=e[i].to,w=e[i].w;

            if(vis[kk]){if(d[kk]!=d[k]+w)return 1;}

            else

            {

                vis[kk]=true,d[kk]=d[k]+w;

                q[lst++]=kk;

                if(lst==N)lst=0;

            }

        }

    }

    return 0;

}

signed main()

{

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

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

    {

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

        add(x,y,z),add(y,x,-z);

    }

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

        if(vis[i]==0&&spfa(i)){printf("No");return 0;}

    printf("Yes");

    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: 6.4705221508628545x):
#include <iostream>

#include <cstdio>

#define N 1000001

#define M 2000001

#define inf 2147483647

#define int long long

using namespace std;

int n,m,hd[N],t,x,y,z,vis[N],d[N];

int q[N],fst,lst;

struct edge

{

    int to,nt,w;

}e[M];

void add(int u,int v,int w)

{

    e[++t].to=v,e[t].w=w;

    e[t].nt=hd[u],hd[u]=t;

}

bool spfa(int s)

{

    vis[s]=true,q[lst++]=s;

    if(lst==N)lst=0;

    while(lst!=fst)

    {

        int k=q[fst++];

        if(fst==N)fst=0;

        for(int i=hd[k],kk,w;i;i=e[i].nt)

        {

            kk=e[i].to,w=e[i].w;

            if(vis[kk]){if(d[kk]!=d[k]+w)return 1;}

            else

            {

                vis[kk]=true,d[kk]=d[k]+w;

                q[lst++]=kk;

                if(lst==N)lst=0;

            }

        }

    }

    return 0;

}

signed main()

{

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

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

    {

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

        add(x,y,z),add(y,x,-z);

    }

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

        if(vis[i]==0&&spfa(i)){printf("No");return 0;}

    printf("Yes");

    return 0;

}
// Slower C++ solution:
#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;

}

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

#include <cstdio>

#define N 1000001

#define M 2000001

#define inf 2147483647

#define int long long

using namespace std;

int n,m,hd[N],t,x,y,z,vis[N],d[N];

int q[N],fst,lst;

struct edge

{

    int to,nt,w;

}e[M];

void add(int u,int v,int w)

{

    e[++t].to=v,e[t].w=w;

    e[t].nt=hd[u],hd[u]=t;

}

bool spfa(int s)

{

    vis[s]=true,q[lst++]=s;

    if(lst==N)lst=0;

    while(lst!=fst)

    {

        int k=q[fst++];

        if(fst==N)fst=0;

        for(int i=hd[k],kk,w;i;i=e[i].nt)

        {

            kk=e[i].to,w=e[i].w;

            if(vis[kk]){if(d[kk]!=d[k]+w)return 1;}

            else

            {

                vis[kk]=true,d[kk]=d[k]+w;

                q[lst++]=kk;

                if(lst==N)lst=0;

            }

        }

    }

    return 0;

}

signed main()

{

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

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

    {

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

        add(x,y,z),add(y,x,-z);

    }

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

        if(vis[i]==0&&spfa(i)){printf("No");return 0;}

    printf("Yes");

    return 0;

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

using namespace std;

int n,m,dis[200001],l,r,d;

bool Error,f[200001];

struct edge {

	int to,cost;

	edge(int a=0,int b=0) {

		to=a;

		cost=b;

	}

};

vector<edge> path[200001];

void spfa(int x) {

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

		edge e=path[x][i];

		if(f[e.to])

			if(e.cost+dis[x]!=dis[e.to]) {

				Error=true;

				return;

			} else continue;

		f[e.to]=true;

		dis[e.to]=dis[x]+e.cost;

		spfa(e.to);

		if(Error) return;

	}

}

int main() {

	cin>>n>>m;

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

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

		path[l].push_back(edge(r,d));

		path[r].push_back(edge(l,-d));

	}

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

		if(!f[i]) {

			spfa(i);

			if(Error) break;

		}

	}

	if(!Error) printf("Yes");

	else printf("No");

	return 0;

}

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

#include <cstdio>

#define N 1000001

#define M 2000001

#define inf 2147483647

#define int long long

using namespace std;

int n,m,hd[N],t,x,y,z,vis[N],d[N];

int q[N],fst,lst;

struct edge

{

    int to,nt,w;

}e[M];

void add(int u,int v,int w)

{

    e[++t].to=v,e[t].w=w;

    e[t].nt=hd[u],hd[u]=t;

}

bool spfa(int s)

{

    vis[s]=true,q[lst++]=s;

    if(lst==N)lst=0;

    while(lst!=fst)

    {

        int k=q[fst++];

        if(fst==N)fst=0;

        for(int i=hd[k],kk,w;i;i=e[i].nt)

        {

            kk=e[i].to,w=e[i].w;

            if(vis[kk]){if(d[kk]!=d[k]+w)return 1;}

            else

            {

                vis[kk]=true,d[kk]=d[k]+w;

                q[lst++]=kk;

                if(lst==N)lst=0;

            }

        }

    }

    return 0;

}

signed main()

{

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

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

    {

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

        add(x,y,z),add(y,x,-z);

    }

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

        if(vis[i]==0&&spfa(i)){printf("No");return 0;}

    printf("Yes");

    return 0;

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

#include<iostream>

#include<cstring>

using namespace std;

struct node_ {

	int v,c,next;

} node[3000001];

int head[1000001],e;

void addnode(int u,int v,int c) {

	e++;

	node[e].c=c;

	node[e].v=v;

	node[e].next=head[u];

	head[u]=e;

}

int n,m;

bool b[1000001],flag;

int d[1000001];

int L,R,D;

bool dfs(int x) {

	b[x]=1;

	for(int i=head[x]; i!=0; i=node[i].next) {

		int y=node[i].v,c=node[i].c;

		if(d[y]>d[x]+c) {

			if(b[y]) return 1;

			d[y]=d[x]+c;

			if(dfs(y))return 1;

		}

	}

	b[x]=0;

	return 0;

}

int main() {

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

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

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

		addnode(R,L,D);

		addnode(L,R,-D);

	}

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

		addnode(0,i,0);

	}

	memset(b,0,sizeof(b));

	memset(d,1000000,sizeof(d));

	d[0]=0;

	if(dfs(0)) printf("No\n");

	else printf("Yes\n");

	return 0;

}

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

#include <cstdio>

#define N 1000001

#define M 2000001

#define inf 2147483647

#define int long long

using namespace std;

int n,m,hd[N],t,x,y,z,vis[N],d[N];

int q[N],fst,lst;

struct edge

{

    int to,nt,w;

}e[M];

void add(int u,int v,int w)

{

    e[++t].to=v,e[t].w=w;

    e[t].nt=hd[u],hd[u]=t;

}

bool spfa(int s)

{

    vis[s]=true,q[lst++]=s;

    if(lst==N)lst=0;

    while(lst!=fst)

    {

        int k=q[fst++];

        if(fst==N)fst=0;

        for(int i=hd[k],kk,w;i;i=e[i].nt)

        {

            kk=e[i].to,w=e[i].w;

            if(vis[kk]){if(d[kk]!=d[k]+w)return 1;}

            else

            {

                vis[kk]=true,d[kk]=d[k]+w;

                q[lst++]=kk;

                if(lst==N)lst=0;

            }

        }

    }

    return 0;

}

signed main()

{

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

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

    {

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

        add(x,y,z),add(y,x,-z);

    }

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

        if(vis[i]==0&&spfa(i)){printf("No");return 0;}

    printf("Yes");

    return 0;

}
// Slower C++ solution:
#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;

}

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

#include <cstdio>

#define N 1000001

#define M 2000001

#define inf 2147483647

#define int long long

using namespace std;

int n,m,hd[N],t,x,y,z,vis[N],d[N];

int q[N],fst,lst;

struct edge

{

    int to,nt,w;

}e[M];

void add(int u,int v,int w)

{

    e[++t].to=v,e[t].w=w;

    e[t].nt=hd[u],hd[u]=t;

}

bool spfa(int s)

{

    vis[s]=true,q[lst++]=s;

    if(lst==N)lst=0;

    while(lst!=fst)

    {

        int k=q[fst++];

        if(fst==N)fst=0;

        for(int i=hd[k],kk,w;i;i=e[i].nt)

        {

            kk=e[i].to,w=e[i].w;

            if(vis[kk]){if(d[kk]!=d[k]+w)return 1;}

            else

            {

                vis[kk]=true,d[kk]=d[k]+w;

                q[lst++]=kk;

                if(lst==N)lst=0;

            }

        }

    }

    return 0;

}

signed main()

{

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

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

    {

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

        add(x,y,z),add(y,x,-z);

    }

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

        if(vis[i]==0&&spfa(i)){printf("No");return 0;}

    printf("Yes");

    return 0;

}