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

#define base 200000

#define inf 0x3f3f3f3f

using namespace std;

int n,m,x,y,w,ans,maxn,minn,dist[100010],vi[100010];

vector<int> g[100010],l[100010];

queue<int> q;

bool flag=false;



bool spfa(int s){

	memset(dist,0x3f,sizeof(dist));

	dist[s]=0,maxn=minn=0,q.push(s),vi[s]=1;

	while(!q.empty()){

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

		for(int i=0;i<g[u].size();i++){

			int v=g[u][i];

			if(!vi[v]){

				dist[v]=dist[u]+l[u][i];

				q.push(v),vi[v]=1;

				maxn=max(maxn,dist[v]),minn=min(minn,dist[v]);

			}

			else if(dist[v]!=dist[u]+l[u][i]) return true;

		}

	}

	return false;

}



int main(){

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

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

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

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

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

		g[x].push_back(y),l[x].push_back(w),g[y].push_back(x),l[y].push_back(-w);

	}

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

		if(!vi[i]){

			flag=spfa(i);

			if(flag){

//				printf("impossible");

				printf("No");

				return 0;

			}

			ans=max(ans,maxn-minn);

		}

	}

//	printf("%d",ans);

	printf("Yes");

}

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

#include <cstdio>

#include <algorithm>

#define N 400005

#define inf 0x7fffffff

using namespace std;



struct E {int next, to, dis;} e[N];

int n, m, num, flag, cnt;

int h[N], a[N], pos[N], obj[N];

bool vis[N];



int read()

{

    int x = 0; char c = getchar();

    while(c < '0' || c > '9') c = getchar();

    while(c >= '0' && c <= '9') {x = x * 10 + c - '0'; c = getchar();}

    return x;

}



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

{

    e[++num].next = h[u];

    e[num].to = v;

    e[num].dis = w;

    h[u] = num;

}



void dfs(int x)

{

    if(flag) return;

    vis[x] = 1;

    for(int i = h[x]; i != 0; i = e[i].next)

    {

        int t = pos[x] + e[i].dis;

        if(pos[e[i].to] == inf) pos[e[i].to] = t, dfs(e[i].to);

        else if(t != pos[e[i].to]) {flag = 1; return;}

    }

}



int main()

{

    cin >> n >> m;

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

    {

        int a = read(), b = read(), c = read();

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

        pos[a] = pos[b] = inf;

        obj[++cnt] = a, obj[++cnt] = b;

    }

    sort(obj + 1, obj + 1 + cnt);

    cnt = unique(obj + 1, obj + 1 + cnt) - obj - 1;

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

        if(!vis[obj[i]])

        {

            flag = 0;

            pos[obj[i]] = 0;

            dfs(obj[i]);

            if(flag) {cout << "No"; return 0;}

        }

    cout << "Yes";

    return 0;

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

#include<cstring>

#include<iostream>

#include<algorithm>

#define int long long

using namespace std;

int n,m,cnt=0;

int head[410000],nxt[410000],to[410000],val[410000];

int ma=0,mi=0;

int q[1000000],dis[100100],f[100100],vis[100100];

void addedge(int x,int y,int z)

{

    cnt++;

    nxt[cnt]=head[x];

    head[x]=cnt;

    to[cnt]=y;

    val[cnt]=z;

}

bool spfa(int x)

{

    int l=0,r=1;

    q[1]=x;vis[x]=1;dis[x]=0;

    while(l<r)

    {

        int u=q[++l];

        for(int i=head[u];i!=-1;i=nxt[i])

        {

            int v=to[i];

            if(dis[v]==12345678987654321)

            {

                dis[v]=dis[u]+val[i];

                ma=max(ma,dis[v]);

                mi=min(mi,dis[v]);

                if(ma-mi>1e9) return 0;

                vis[v]=1;

                if(!f[v]) q[++r]=v,f[v]=1;

            }

            else if(dis[v]!=dis[u]+val[i]) return 0;

        }

        f[u]=0;

    }

    return 1;

}

signed main()

{

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

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

        dis[i]=12345678987654321;

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

    if(!m) {printf("Yes");return 0;}

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

    {

        int x,y,z;

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

        addedge(x,y,z);

        addedge(y,x,-z);

    }

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

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

    printf("Yes");

    return 0;

}

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

#include <cstdio>

#include <algorithm>

#define N 400005

#define inf 0x7fffffff

using namespace std;



struct E {int next, to, dis;} e[N];

int n, m, num, flag, cnt;

int h[N], a[N], pos[N], obj[N];

bool vis[N];



int read()

{

    int x = 0; char c = getchar();

    while(c < '0' || c > '9') c = getchar();

    while(c >= '0' && c <= '9') {x = x * 10 + c - '0'; c = getchar();}

    return x;

}



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

{

    e[++num].next = h[u];

    e[num].to = v;

    e[num].dis = w;

    h[u] = num;

}



void dfs(int x)

{

    if(flag) return;

    vis[x] = 1;

    for(int i = h[x]; i != 0; i = e[i].next)

    {

        int t = pos[x] + e[i].dis;

        if(pos[e[i].to] == inf) pos[e[i].to] = t, dfs(e[i].to);

        else if(t != pos[e[i].to]) {flag = 1; return;}

    }

}



int main()

{

    cin >> n >> m;

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

    {

        int a = read(), b = read(), c = read();

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

        pos[a] = pos[b] = inf;

        obj[++cnt] = a, obj[++cnt] = b;

    }

    sort(obj + 1, obj + 1 + cnt);

    cnt = unique(obj + 1, obj + 1 + cnt) - obj - 1;

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

        if(!vis[obj[i]])

        {

            flag = 0;

            pos[obj[i]] = 0;

            dfs(obj[i]);

            if(flag) {cout << "No"; return 0;}

        }

    cout << "Yes";

    return 0;

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

using namespace std;

inline void fff(){

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

	freopen("line.out","w",stdout);

}

const int N=1e5+10;

const int INF=0x3f3f3f3f;

inline int read(){

	int x=0,m=1;char ch=getchar();

	while(ch!='-'&&(ch<'0'||ch>'9')) ch=getchar();

	if(ch=='-') ch=getchar(),m=-1;

	while(ch<='9'&&ch>='0') 

		x=x*10+ch-'0',ch=getchar();

	return x*m;

}

int n,m;

struct Edge{

	int nxt;

	int to,w;

}edge[N<<2];

int head[N],tot=0;

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

	edge[++tot].nxt=head[u];

	edge[tot].to=v;

	edge[tot].w=w;

	head[u]=tot;

}

bool visited[N];

int dist[N],ans,minn,maxx;

queue<int> q;

inline bool SPFA(int str){

	

	q.push(str);

	if(m) minn=INF,maxx=0;

	dist[str]=0;visited[str]=true;

	while(!q.empty()){

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

		visited[u]=false;

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

			Edge e=edge[i];

			if(dist[e.to]<INF){

				if(dist[e.to]!=e.w+dist[u]){

					return false;

				}

				minn=min(minn,dist[e.to]);

				maxx=max(maxx,dist[e.to]);

			}else{

				dist[e.to]=dist[u]+e.w;

				minn=min(minn,dist[e.to]);

				maxx=max(maxx,dist[e.to]);

				if(!visited[e.to]){

					visited[e.to]=true;

					q.push(e.to);

				}

			}

		}

	}

	ans=min(ans,maxx-minn);

	return true;

}

int main(){

//	fff();

	n=read();

	m=read();

	ans=INF;

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

		int u,v,w;

		u=read(),v=read(),w=read();

		add(u,v,w);

		add(v,u,-w);

	}

	memset(dist,INF,sizeof(dist));

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

		if(dist[i]<INF)  continue;

		if(!SPFA(i)){

			printf("No");

			return 0;

		}

	}

	printf("Yes");

}

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

#include <cstdio>

#include <algorithm>

#define N 400005

#define inf 0x7fffffff

using namespace std;



struct E {int next, to, dis;} e[N];

int n, m, num, flag, cnt;

int h[N], a[N], pos[N], obj[N];

bool vis[N];



int read()

{

    int x = 0; char c = getchar();

    while(c < '0' || c > '9') c = getchar();

    while(c >= '0' && c <= '9') {x = x * 10 + c - '0'; c = getchar();}

    return x;

}



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

{

    e[++num].next = h[u];

    e[num].to = v;

    e[num].dis = w;

    h[u] = num;

}



void dfs(int x)

{

    if(flag) return;

    vis[x] = 1;

    for(int i = h[x]; i != 0; i = e[i].next)

    {

        int t = pos[x] + e[i].dis;

        if(pos[e[i].to] == inf) pos[e[i].to] = t, dfs(e[i].to);

        else if(t != pos[e[i].to]) {flag = 1; return;}

    }

}



int main()

{

    cin >> n >> m;

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

    {

        int a = read(), b = read(), c = read();

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

        pos[a] = pos[b] = inf;

        obj[++cnt] = a, obj[++cnt] = b;

    }

    sort(obj + 1, obj + 1 + cnt);

    cnt = unique(obj + 1, obj + 1 + cnt) - obj - 1;

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

        if(!vis[obj[i]])

        {

            flag = 0;

            pos[obj[i]] = 0;

            dfs(obj[i]);

            if(flag) {cout << "No"; return 0;}

        }

    cout << "Yes";

    return 0;

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

#include<cstring>

#include<iostream>

#include<algorithm>

#define int long long

using namespace std;

const int Top=6666666666666666;

int n,m,cnt=0;

int head[410000],nxt[410000],to[410000],val[410000];

int ma=0,mi=0;

int q[1000000],dis[100100],f[100100],vis[100100];

void addedge(int x,int y,int z)

{

    cnt++;

    nxt[cnt]=head[x];

    head[x]=cnt;

    to[cnt]=y;

    val[cnt]=z;

}

bool spfa(int x)

{

    int l=0,r=1;

    q[1]=x;vis[x]=1;dis[x]=0;

    while(l<r)

    {

        int u=q[++l];

        for(int i=head[u];i!=-1;i=nxt[i])

        {

            int v=to[i];

            if(dis[v]==Top)

            {

                dis[v]=dis[u]+val[i];

                ma=max(ma,dis[v]);

                mi=min(mi,dis[v]);

                if(ma-mi>1e9) return 0;

                vis[v]=1;

                if(!f[v]) q[++r]=v,f[v]=1;

            }

            else if(dis[v]!=dis[u]+val[i]) return 0;

        }

        f[u]=0;

    }

    return 1;

}

signed main()

{

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

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

        dis[i]=Top;

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

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

    {

        int x,y,z;

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

        addedge(x,y,z);

        addedge(y,x,-z);

    }

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

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

    printf("Yes");

    return 0;

}

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

#include <cstdio>

#include <algorithm>

#define N 400005

#define inf 0x7fffffff

using namespace std;



struct E {int next, to, dis;} e[N];

int n, m, num, flag, cnt;

int h[N], a[N], pos[N], obj[N];

bool vis[N];



int read()

{

    int x = 0; char c = getchar();

    while(c < '0' || c > '9') c = getchar();

    while(c >= '0' && c <= '9') {x = x * 10 + c - '0'; c = getchar();}

    return x;

}



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

{

    e[++num].next = h[u];

    e[num].to = v;

    e[num].dis = w;

    h[u] = num;

}



void dfs(int x)

{

    if(flag) return;

    vis[x] = 1;

    for(int i = h[x]; i != 0; i = e[i].next)

    {

        int t = pos[x] + e[i].dis;

        if(pos[e[i].to] == inf) pos[e[i].to] = t, dfs(e[i].to);

        else if(t != pos[e[i].to]) {flag = 1; return;}

    }

}



int main()

{

    cin >> n >> m;

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

    {

        int a = read(), b = read(), c = read();

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

        pos[a] = pos[b] = inf;

        obj[++cnt] = a, obj[++cnt] = b;

    }

    sort(obj + 1, obj + 1 + cnt);

    cnt = unique(obj + 1, obj + 1 + cnt) - obj - 1;

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

        if(!vis[obj[i]])

        {

            flag = 0;

            pos[obj[i]] = 0;

            dfs(obj[i]);

            if(flag) {cout << "No"; return 0;}

        }

    cout << "Yes";

    return 0;

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

const int N=1e6+10;

using namespace std;



inline int read(){

	char ch=getchar();int x=0,f=1;

	while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}

	while(ch>='0'&&ch<='9'){x=x*10+ch-'0';ch=getchar();}

	return x*f;

} 



struct node{

	int v,nxt,w;

}e[N<<1];

int head[N],cnt;

int dis[N],n,m,INF;

bool used[N],vis[N];



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

	e[++cnt].v=v;

	e[cnt].w=w;

	e[cnt].nxt=head[u];

	head[u]=cnt;

}



bool spfa(int s){

	queue<int> q;

	q.push(s);

	vis[s]=true;

	dis[s]=0;

	while(!q.empty()){

		int u=q.front();

		q.pop();vis[u]=false;

		for(int i=head[u];i;i=e[i].nxt){

			int v=e[i].v,w=e[i].w;

			if(dis[v]==INF){

				dis[v]=dis[u]+w;

				used[v]=true;

				if(!vis[v])vis[v]=true,q.push(v);

			}

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

		}

	}

	return true;

}



int main(){

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

	INF=dis[1];

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

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

		int x=read(),y=read(),z=read();

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

	}

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

		if(!used[i]){

			used[i]=true;

			if(!spfa(i)){

				printf("No");

				return 0;

			}

		}

	}

	printf("Yes");

	return 0;

}




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

#include <cstdio>

#include <algorithm>

#define N 400005

#define inf 0x7fffffff

using namespace std;



struct E {int next, to, dis;} e[N];

int n, m, num, flag, cnt;

int h[N], a[N], pos[N], obj[N];

bool vis[N];



int read()

{

    int x = 0; char c = getchar();

    while(c < '0' || c > '9') c = getchar();

    while(c >= '0' && c <= '9') {x = x * 10 + c - '0'; c = getchar();}

    return x;

}



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

{

    e[++num].next = h[u];

    e[num].to = v;

    e[num].dis = w;

    h[u] = num;

}



void dfs(int x)

{

    if(flag) return;

    vis[x] = 1;

    for(int i = h[x]; i != 0; i = e[i].next)

    {

        int t = pos[x] + e[i].dis;

        if(pos[e[i].to] == inf) pos[e[i].to] = t, dfs(e[i].to);

        else if(t != pos[e[i].to]) {flag = 1; return;}

    }

}



int main()

{

    cin >> n >> m;

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

    {

        int a = read(), b = read(), c = read();

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

        pos[a] = pos[b] = inf;

        obj[++cnt] = a, obj[++cnt] = b;

    }

    sort(obj + 1, obj + 1 + cnt);

    cnt = unique(obj + 1, obj + 1 + cnt) - obj - 1;

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

        if(!vis[obj[i]])

        {

            flag = 0;

            pos[obj[i]] = 0;

            dfs(obj[i]);

            if(flag) {cout << "No"; return 0;}

        }

    cout << "Yes";

    return 0;

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

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

#define inf 0x3f3f3f3f

#define N 100010

#define M 200010

using namespace std;



struct edge{

	int to,nxt,w;

}e[M << 2];

int h[N],dis[N],vis[N];

int tot,n,m;



inline int read(){

	int x = 0,f = 1;char c = getchar();

	while(!isdigit(c)){if(c == '-')f = -1;c = getchar();}

	while(isdigit(c)){x = x * 10 + c - '0';c = getchar();}

	return f * x;

}



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

	e[++tot] = (edge){y,h[x],z};

	h[x] = tot;

}



inline int spfa(int s){

	queue<int>q;

	q.push(s);vis[s] = 1;dis[s] = 0;

	while(q.size()){

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

		for(register int i = h[x];i;i = e[i].nxt){

			int p = e[i].to;

			if(dis[p] == inf){

				dis[p] = dis[x] + e[i].w;

				if(!vis[p])vis[p] = 1,q.push(p);

			}

			else if(dis[p] != dis[x] + e[i].w)return 0;

		}

	}

	return 1;

}



int main(){

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

	if(!m){printf("Yes");return 0;}

	fr(i,1,m){

		int x = read(),y = read(),z = read();

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

	}

	memset(dis,inf,sizeof(dis));

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

	fr(i,1,n)

		if(!vis[i]){

			int x = spfa(i);

			if(!x){printf("No");return 0;}

		}

	printf("Yes");

	return 0;

}

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

#include <cstdio>

#include <algorithm>

#define N 400005

#define inf 0x7fffffff

using namespace std;



struct E {int next, to, dis;} e[N];

int n, m, num, flag, cnt;

int h[N], a[N], pos[N], obj[N];

bool vis[N];



int read()

{

    int x = 0; char c = getchar();

    while(c < '0' || c > '9') c = getchar();

    while(c >= '0' && c <= '9') {x = x * 10 + c - '0'; c = getchar();}

    return x;

}



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

{

    e[++num].next = h[u];

    e[num].to = v;

    e[num].dis = w;

    h[u] = num;

}



void dfs(int x)

{

    if(flag) return;

    vis[x] = 1;

    for(int i = h[x]; i != 0; i = e[i].next)

    {

        int t = pos[x] + e[i].dis;

        if(pos[e[i].to] == inf) pos[e[i].to] = t, dfs(e[i].to);

        else if(t != pos[e[i].to]) {flag = 1; return;}

    }

}



int main()

{

    cin >> n >> m;

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

    {

        int a = read(), b = read(), c = read();

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

        pos[a] = pos[b] = inf;

        obj[++cnt] = a, obj[++cnt] = b;

    }

    sort(obj + 1, obj + 1 + cnt);

    cnt = unique(obj + 1, obj + 1 + cnt) - obj - 1;

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

        if(!vis[obj[i]])

        {

            flag = 0;

            pos[obj[i]] = 0;

            dfs(obj[i]);

            if(flag) {cout << "No"; return 0;}

        }

    cout << "Yes";

    return 0;

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

#include<vector>

using namespace std;



int par[100001];

int dist[100001];



void init_union_find() {

    fill(par, par+100001, -1);

    fill(dist, dist+100001, 0);

}



int root(int x) {

    if(par[x] < 0) return x;

    int r = root(par[x]);

    dist[x] += dist[par[x]];

    return par[x] = r;

}



bool same(int x, int y) {

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

}



int weight(int x) {

    root(x);

    return dist[x];

}



int diff(int x, int y) {

    return weight(y) - weight(x);

}



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

    w += weight(x);

    w -= weight(y);

    x = root(x);

    y = root(y);

    if(x == y) return;

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

    par[x] += par[y];

    par[y] = x;

    dist[y] = w;

}



int main() {

    int N, M;

    cin >> N >> M;

    init_union_find();

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

        int l, r, d;

        cin >> l >> r >> d;

        if(same(l, r)) {

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

                cout << "No" << endl;

                return 0;

            }

        } else {

            unite(l, r, d);

        }

    }



    cout << "Yes" << endl;



    return 0;

}


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

#include<vector>

using namespace std;



#include<iostream>

#include<vector>

#include<utility>

#include<algorithm>



template<class T> struct UnionFind{

    std::vector<int> par;

    std::vector<T> diff_weight;



    UnionFind(int size = 1, T SUM_UNITY = 0){

        init(size, SUM_UNITY);

    }



    void init(int size = 1, T SUM_UNITY = 0) {

        par.resize(size);

        diff_weight.resize(size);

        fill(par.begin(), par.end(), -1);

        fill(diff_weight.begin(), diff_weight.end(), SUM_UNITY);

    }



    int root(int x) {

        if(par[x] < 0) return x;

        int r = root(par[x]);

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

        return par[x] = r;

    }



    bool issame(int x, int y) {

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

    }



    int weight(int x) {

        root(x); // 経路圧縮と重み計算

        return diff_weight[x];

    }



    int diff(int x, int y) {

        return weight(y) - weight(x);

    }



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

        w += weight(x);

        w -= weight(y);

        x = root(x);

        y = root(y);

        if(x == y) return false;



        if(par[y] < par[x]) std::swap(x, y), w = -w; // yの方が気が深いなら交換

        par[x] += par[y];

        par[y] = x;

        diff_weight[y] = w;



        return true;

    }



    int size(int x) {

        return -par[root(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)) {

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

                cout << "No" << endl;

                return 0;

            }

        } else {

            uf.unite(l, r, d);

        }

    }



    cout << "Yes" << endl;



    return 0;

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

#include <cstdio>

#include <vector>

using namespace std;

struct Path {

	int to, v;

	Path (int To = 0, int V = 0)

	{

		to = To;

		v = V;

	}

};

void node (int l, int r, int d);

vector <Path> ph[100000 + 9];//记录从 i 点出发的边 

bool vis[100000 + 9], inQ[100000 + 9];

int dis[100000 + 9];

bool dfs(int s);

int main()

{

	int n, m;

	

	cin >> n >> m;

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

	{

		int l, r, d;

		cin >> l >> r >> d;

		node (r, l, d);

		node (l, r, -d);

	}

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

		if (dfs(i) == false)

		{

			cout << "No" << endl;

			return 0;

		}

	cout << "Yes" << endl;

	

}

bool dfs(int s)

{

//	if (vis[s] = true) return true;

	inQ[s] = true;

//	vis[s] = true;

	for (int i = 0; i < ph[s].size(); i++)

	{

		Path e = ph[s][i];

		if (dis[e.to] < dis[s] + e.v)

		{

			if (inQ[e.to])

				return false;

			dis[e.to] = dis[s] + e.v;

			if (dfs(e.to) == false)

				return false;

		}

	}

	inQ[s] = false;

	return true;

}

void node (int x1, int x2, int v)

{

	ph[x1].push_back(Path(x2, v));

}

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

#include <algorithm>

#include <cstdio>

#include <cstring>

#include <cmath>

#include <queue>

using namespace std;

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

typedef long long ll;

const int Size=1<<18;

inline char getch(){

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

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

}

int read(){

    int s=0,f=1;

    char c=getch();

    while(c>'9' || c<'0'){if(c=='-') f=-1; c=getch();}

    while(c<='9' && c>='0'){s=(s<<1)+(s<<3)+c-'0';c=getch();}

    return s*f;

}



const int maxn=100007;

const long long inf=12345678987654321;

struct node

{

    int to,next,val;

}edge[maxn<<2];

int head[maxn],tot,n,m,vis[maxn],visq[maxn];

ll dis[maxn];



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

    edge[++tot].to=y;

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

    head[x]=tot;

    edge[tot].val=w;

}



queue<int> q;

int spfa(int s){

    q.push(s);

    dis[s]=0,vis[s]=1;

    ll maxs=0,mins=0;

    while(!q.empty()){

        int u=q.front();

        q.pop();

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

            int to=edge[i].to;

            if(dis[to]==inf){

                dis[to]=dis[u]+edge[i].val;

                maxs=max(maxs,dis[to]);

                mins=min(mins,dis[to]);

                if(maxs-mins>10000000000) return 0;

                visq[to]=1;

                if(!vis[to])

                    q.push(to);

            }

            else if(dis[to]!=dis[u]+edge[i].val) return 0;

        }

        vis[u]=0;

    }

    return 1;

}

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

{

    fill(dis,dis+maxn-1,inf);

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

    fors(i,1,m){

        int l=read(),r=read(),w=read();

        add(l,r,w);

        add(r,l,-w);

    }

    fors(i,1,n)

        if(!visq[i]){

            visq[i]=1;

            int flag=spfa(i);

            if(!flag){

                printf("No\n");

                return 0;

            }

        }

    printf("Yes\n");

    return 0;

}