stablegradients/pie-gem5-pairs huggingface dataset:
// Slower C++ solution:
#include<iostream>

#include<cstdio>

#include<algorithm>

#include<vector>

#define Max 100010

using namespace std;

struct node

{

    int n,d;

}push;

vector<node>  e[Max];

bool vis[Max];

int flag=0;

int dis[Max];

void dfs(int x)

{

    vis[x]=true;

    if(flag)

    return;

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

    {

        node tmp;

        tmp=e[x][i];

        if(vis[tmp.n])

        {

            if(dis[tmp.n]!=dis[x]+tmp.d)

            {

                flag=1;

                break;

            }

        }

        else

        {

            dis[tmp.n]=dis[x]+tmp.d;

            dfs(tmp.n);

        }

    }

}

int main()

{

    int N,M;

    int l,r,d;

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

    int i;

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

    {

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

        push.n=r;

        push.d=d;

        e[l].push_back(push);

        push.n=l;

        push.d=-1*d;

        e[r].push_back(push);

    }

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

    {

        if(vis[i]==false)

        {

            dfs(i);

        }

        if(flag)

            break;

    }

    if(flag)

        printf("No\n");

    else printf("Yes\n");

    return 0;

}


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

#pragma GCC optimize("Ofast")

#pragma GCC optimize("no-stack-protector")

#pragma GCC optimize("O3")

#pragma GCC optimize("fast-math")



using namespace std;



#define int long long



vector<vector<pair<int, int>>> g;

vector<int> used;

const int INF = 1e18;



void dfs(int v, int t) {

    used[v] = t;

    for (auto it: g[v]) {

        if (used[it.first] == INF) dfs(it.first, t + it.second);

        else if (used[it.first] != t + it.second) {

            cout << "No";

            exit(0);

        }

    }

}



signed main()

{

    ios_base::sync_with_stdio(false);

    cin.tie(0);

    cout.tie(0);

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

    g.resize(n);

    used.assign(n, INF);

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

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

        l--; r--;

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

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

    }

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

        for (int j = 0; j < g[i].size(); ++j) cout << g[i][j].first << " " << g[i][j].second << "   ";

        cout << endl;

    }*/

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

        if (used[i] == INF) {

            used[i] = 0;

            dfs(i, 0);

        }

    }

    cout << "Yes";

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

#include <cstring>

#include <cstdio>

#include <vector>



using namespace std;



#define MAXN 100005



int N,M;

bool mark[MAXN];



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

int len[MAXN];



bool DFS(int t)

{

	vector<pair<int,int>>::iterator it;

	for(it = v[t].begin() ; it!=v[t].end() ; it++)

	{

		int p = (*it).first;

		int val = (*it).second;

		if(!mark[p])

		{

			mark[p] = true;

			len[p] = len[t]+val;

			if(!DFS(p))return false;

		}

		else if(len[p] != len[t]+val)return false;

	}

	return true;

}



int main()

{

	cin>>N>>M;

	int L,R,D;

	while(M--)

	{

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

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

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

	}

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

	{

		if(!mark[i])

		{

			mark[i] = true;

			if(!DFS(i))

			{

				printf("No\n");

				return 0;

			}

		}

	}

	printf("Yes\n");

	return 0;

}

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

#pragma GCC optimize("Ofast")

#pragma GCC optimize("no-stack-protector")

#pragma GCC optimize("O3")

#pragma GCC optimize("fast-math")



using namespace std;



#define int long long



vector<vector<pair<int, int>>> g;

vector<int> used;

const int INF = 1e18;



void dfs(int v, int t) {

    used[v] = t;

    for (auto it: g[v]) {

        if (used[it.first] == INF) dfs(it.first, t + it.second);

        else if (used[it.first] != t + it.second) {

            cout << "No";

            exit(0);

        }

    }

}



signed main()

{

    ios_base::sync_with_stdio(false);

    cin.tie(0);

    cout.tie(0);

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

    g.resize(n);

    used.assign(n, INF);

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

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

        l--; r--;

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

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

    }

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

        for (int j = 0; j < g[i].size(); ++j) cout << g[i][j].first << " " << g[i][j].second << "   ";

        cout << endl;

    }*/

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

        if (used[i] == INF) {

            used[i] = 0;

            dfs(i, 0);

        }

    }

    cout << "Yes";

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

#pragma GCC optimize("Ofast")

#pragma GCC optimize("no-stack-protector")

#pragma GCC optimize("O3")

#pragma GCC optimize("fast-math")



using namespace std;



#define int long long



vector<vector<pair<int, int>>> g;

vector<int> used;

const int INF = 1e18;



void dfs(int v, int t) {

    used[v] = t;

    for (auto it: g[v]) {

        if (used[it.first] == INF) dfs(it.first, t + it.second);

        else if (used[it.first] != t + it.second) {

            cout << "No";

            exit(0);

        }

    }

}



signed main()

{

    ios_base::sync_with_stdio(false);

    cin.tie(0);

    cout.tie(0);

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

    g.resize(n);

    used.assign(n, INF);

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

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

        l--; r--;

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

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

    }

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

        for (int j = 0; j < g[i].size(); ++j) cout << g[i][j].first << " " << g[i][j].second << "   ";

        cout << endl;

    }*/

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

        if (used[i] == INF) {

            used[i] = 0;

            dfs(i, 0);

        }

    }

    cout << "Yes";

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

#include <cstdio>

#include <map>

#include <algorithm>

#include <cstring>

#include <string>

#include <cmath>



using namespace std;



const int N = 1e5+5;

int n,m;

int fa[N],r[N];



void init()

{

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

    {

        fa[i] = i;

    }

    memset(r,0,sizeof(r));

}



int Find(int x)

{

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

    int root = Find(fa[x]);

    r[x] += r[fa[x]];

    return fa[x] = root;

}



bool Merge(int x, int y, int d)

{

    int fx = Find(x);

    int fy = Find(y);

    if(fx==fy)

    {

        return d == r[y]-r[x];

    }

    fa[fy] = fx;

    r[fy] = r[x] + d - r[y];

    return 1;

}



int main()

{

    while(scanf("%d%d",&n,&m) != EOF)

    {

        int ok = 1;

        int L,R,D;

        init();

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

        {

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

            if(ok && !Merge(L,R,D))

            {

                ok = 0;

            }

        }

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

        else printf("No\n");

    }

    return 0;

}


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

#pragma GCC optimize("Ofast")

#pragma GCC optimize("no-stack-protector")

#pragma GCC optimize("O3")

#pragma GCC optimize("fast-math")



using namespace std;



#define int long long



vector<vector<pair<int, int>>> g;

vector<int> used;

const int INF = 1e18;



void dfs(int v, int t) {

    used[v] = t;

    for (auto it: g[v]) {

        if (used[it.first] == INF) dfs(it.first, t + it.second);

        else if (used[it.first] != t + it.second) {

            cout << "No";

            exit(0);

        }

    }

}



signed main()

{

    ios_base::sync_with_stdio(false);

    cin.tie(0);

    cout.tie(0);

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

    g.resize(n);

    used.assign(n, INF);

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

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

        l--; r--;

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

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

    }

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

        for (int j = 0; j < g[i].size(); ++j) cout << g[i][j].first << " " << g[i][j].second << "   ";

        cout << endl;

    }*/

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

        if (used[i] == INF) {

            used[i] = 0;

            dfs(i, 0);

        }

    }

    cout << "Yes";

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

#include <stdio.h>

#include <stdlib.h>

#include <unistd.h>

#include <string.h>

#include <algorithm>

#include <limits.h>

#include <vector>

#include <map>

#include <stack>

#include <queue>

#include <math.h>

#define ll long long

#define MSET(x) memset((x), 0, sizeof((x)))

#define MMSET(x) memset((x), -1, sizeof((x)))

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

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

#define repD(i, a, b) for ( ll (i) = a; (i) >= (b) ; (i) -- )

#define fi first

#define se second

#define pb push_back

#define mfind(m, item) ((m).find((item)) != (m).end())

#define mp(a,b) make_pair((a),(b))

#define mt(a,b,c) make_pair(make_pair((a),(b)), (c))

#define tfi first.first

#define tse first.second

#define tth second

#define prll cout << endl

#define tri pair<pair<ll, ll>, ll>

using namespace std;



int n,m;

int cnt[100002], ans[100002];



void find(int x){

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

    find(ans[x]);

    cnt[x] += cnt[ans[x]], ans[x] = ans[ans[x]];

}



bool has = false;



int main(){

    while ( cin >> n >> m ) {

        MSET(cnt); MSET(ans); has = false;

        for ( int i = 1 ; i <= n ; ++ i ) ans[i] = i;

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

            int l, r, d;

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

            find(l); find(r);

            if ( ans[l] == ans[r] ){

                if ( cnt[l] + d != cnt[r] ) {

                    has = true;

                }

            }

            else {

                cnt[ans[r]] = cnt[l] + d - cnt[r];

                ans[ans[r]] = ans[l];

            }

        }

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

    }

}


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

#pragma GCC optimize("Ofast")

#pragma GCC optimize("no-stack-protector")

#pragma GCC optimize("O3")

#pragma GCC optimize("fast-math")



using namespace std;



#define int long long



vector<vector<pair<int, int>>> g;

vector<int> used;

const int INF = 1e18;



void dfs(int v, int t) {

    used[v] = t;

    for (auto it: g[v]) {

        if (used[it.first] == INF) dfs(it.first, t + it.second);

        else if (used[it.first] != t + it.second) {

            cout << "No";

            exit(0);

        }

    }

}



signed main()

{

    ios_base::sync_with_stdio(false);

    cin.tie(0);

    cout.tie(0);

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

    g.resize(n);

    used.assign(n, INF);

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

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

        l--; r--;

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

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

    }

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

        for (int j = 0; j < g[i].size(); ++j) cout << g[i][j].first << " " << g[i][j].second << "   ";

        cout << endl;

    }*/

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

        if (used[i] == INF) {

            used[i] = 0;

            dfs(i, 0);

        }

    }

    cout << "Yes";

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

#include <vector>

using namespace std;

 

int n,m; //input intergers:n,m

vector<pair<int,int> > e[100010]; //the vector array of DFS

long long pos[100010]; //the positions of each person 

bool vis[100010]; //the bool array of DFS to know each person has visited or not

 

inline void dfs(int x) //DFS

{

	vis[x]=1; //visited this person(x)

	for(int i=0;i<e[x].size();i++) //visit the person who has relation of this person(x)

	{

		pair<int,int> cur=e[x][i];

		if(vis[cur.first]) //if(this person(e[x][i])'s position has known)

		{

			if(pos[cur.first]-pos[x]!=cur.second) {cout<<"No";exit(0);} //if this person(e[x][i]) is wrongful then exit

		}

		else //if this person(e[x][i])'s position hasn't known then take notes and DFS

		{

			pos[cur.first]=pos[x]+cur.second;

			dfs(cur.first);

		}

	}

}

 

int main()

{

	cin>>n>>m; //input

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

	{

		int l,r,d;

		cin>>l>>r>>d; //input

		e[l].push_back({r,d}); //take notes

		e[r].push_back({l,-d}); //take notes

	}

	

	for(int i=0;i<n;i++) if(!vis[i]) dfs(i); //DFS

	

	cout<<"Yes"; //if every one isn't wrongful then print 'Yes'

	

	return 0; //END

}

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

#include <vector>

#include <algorithm>

#include <map>

#include <set>

#include <unordered_map>

#include <unordered_set>

#include <tuple>

#include <iomanip>

//#include <cmath>

#include <queue>

#include <deque>

#include <stack>

//#pragma GCC optimize("Ofast")

//#pragma GCC target("avx,avx2")

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

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

typedef long double ld;

typedef long long ll;

typedef double db;

#define endl '\n'

#define pb push_back

#define pii pair<ll, ll>

#define ff first

#define ss second

#define sz(x) (ll)(x).size()

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

#pragma warning(disable:4996)



using namespace std;



const ll MX = 2e5 + 10, INF = 1e9 + 1;

ll n, m, t, d[MX], l[MX], r[MX], a[MX];

bool used[MX];

vector<vector<int>> g;



bool dfs(int v) {

	used[v] = true;

	bool f = true;

	for (auto c : g[v]) {

		int tmp = a[v], pos = l[c] + r[c] - v;

		if (l[c] == v)

			tmp += d[c];

		else

			tmp -= d[c];

		if (used[pos])

			f = f && (a[pos] == tmp);

		else {

			a[pos] = tmp;

			f = f && dfs(pos);

		}

	}

	return f;

}



signed main() {

	optimize1();

	cin >> n >> m;

	g.resize(n + 1);

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

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

		g[l[i]].pb(i);

		g[r[i]].pb(i);

	}

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

		if (used[i])

			continue;

		a[i] = 0;

		if (!dfs(i)) {

			cout << "No" << endl;

			return 0;

		}

	}

	cout << "Yes" << endl;

	return 0;

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

#include<cstdio>

#include<algorithm>

#include<vector>

#define Max 100010

using namespace std;

struct node

{

    int n,d;

}push;

vector<node>  e[Max];

bool vis[Max];

int flag=0;

int dis[Max];

void dfs(int x)

{

    vis[x]=true;

    if(flag)

    return;

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

    {

        node tmp;

        tmp=e[x][i];

        if(vis[tmp.n])

        {

            if(dis[tmp.n]!=dis[x]+tmp.d)

            {

                flag=1;

                break;

            }

        }

        else

        {

            dis[tmp.n]=dis[x]+tmp.d;

            dfs(tmp.n);

        }

    }

}

int main()

{

    int N,M;

    int l,r,d;

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

    int i;

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

    {

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

        push.n=r;

        push.d=d;

        e[l].push_back(push);

        push.n=l;

        push.d=-1*d;

        e[r].push_back(push);

    }

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

    {

        if(vis[i]==false)

        {

            dfs(i);

        }

        if(flag)

            break;

    }

    if(flag)

        printf("No\n");

    else printf("Yes\n");

    return 0;

}


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

#include <vector>

#include <algorithm>

#include <map>

#include <set>

#include <unordered_map>

#include <unordered_set>

#include <tuple>

#include <iomanip>

//#include <cmath>

#include <queue>

#include <deque>

#include <stack>

//#pragma GCC optimize("Ofast")

//#pragma GCC target("avx,avx2")

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

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

typedef long double ld;

typedef long long ll;

typedef double db;

#define endl '\n'

#define pb push_back

#define pii pair<ll, ll>

#define ff first

#define ss second

#define sz(x) (ll)(x).size()

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

#pragma warning(disable:4996)



using namespace std;



const ll MX = 2e5 + 10, INF = 1e9 + 1;

ll n, m, t, d[MX], l[MX], r[MX], a[MX];

bool used[MX];

vector<vector<int>> g;



bool dfs(int v) {

	used[v] = true;

	bool f = true;

	for (auto c : g[v]) {

		int tmp = a[v], pos = l[c] + r[c] - v;

		if (l[c] == v)

			tmp += d[c];

		else

			tmp -= d[c];

		if (used[pos])

			f = f && (a[pos] == tmp);

		else {

			a[pos] = tmp;

			f = f && dfs(pos);

		}

	}

	return f;

}



signed main() {

	optimize1();

	cin >> n >> m;

	g.resize(n + 1);

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

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

		g[l[i]].pb(i);

		g[r[i]].pb(i);

	}

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

		if (used[i])

			continue;

		a[i] = 0;

		if (!dfs(i)) {

			cout << "No" << endl;

			return 0;

		}

	}

	cout << "Yes" << endl;

	return 0;

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

#include <cstring>

#include <cstdio>

#include <vector>



using namespace std;



#define MAXN 100005



int N,M;

bool mark[MAXN];



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

int len[MAXN];



bool DFS(int t)

{

	vector<pair<int,int>>::iterator it;

	for(it = v[t].begin() ; it!=v[t].end() ; it++)

	{

		int p = (*it).first;

		int val = (*it).second;

		if(!mark[p])

		{

			mark[p] = true;

			len[p] = len[t]+val;

			if(!DFS(p))return false;

		}

		else if(len[p] != len[t]+val)return false;

	}

	return true;

}



int main()

{

	cin>>N>>M;

	int L,R,D;

	while(M--)

	{

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

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

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

	}

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

	{

		if(!mark[i])

		{

			mark[i] = true;

			if(!DFS(i))

			{

				printf("No\n");

				return 0;

			}

		}

	}

	printf("Yes\n");

	return 0;

}

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

#include <vector>

#include <algorithm>

#include <map>

#include <set>

#include <unordered_map>

#include <unordered_set>

#include <tuple>

#include <iomanip>

//#include <cmath>

#include <queue>

#include <deque>

#include <stack>

//#pragma GCC optimize("Ofast")

//#pragma GCC target("avx,avx2")

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

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

typedef long double ld;

typedef long long ll;

typedef double db;

#define endl '\n'

#define pb push_back

#define pii pair<ll, ll>

#define ff first

#define ss second

#define sz(x) (ll)(x).size()

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

#pragma warning(disable:4996)



using namespace std;



const ll MX = 2e5 + 10, INF = 1e9 + 1;

ll n, m, t, d[MX], l[MX], r[MX], a[MX];

bool used[MX];

vector<vector<int>> g;



bool dfs(int v) {

	used[v] = true;

	bool f = true;

	for (auto c : g[v]) {

		int tmp = a[v], pos = l[c] + r[c] - v;

		if (l[c] == v)

			tmp += d[c];

		else

			tmp -= d[c];

		if (used[pos])

			f = f && (a[pos] == tmp);

		else {

			a[pos] = tmp;

			f = f && dfs(pos);

		}

	}

	return f;

}



signed main() {

	optimize1();

	cin >> n >> m;

	g.resize(n + 1);

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

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

		g[l[i]].pb(i);

		g[r[i]].pb(i);

	}

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

		if (used[i])

			continue;

		a[i] = 0;

		if (!dfs(i)) {

			cout << "No" << endl;

			return 0;

		}

	}

	cout << "Yes" << endl;

	return 0;

}
// 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.307611809102763x):
#include <iostream>

#include <vector>

#include <algorithm>

#include <map>

#include <set>

#include <unordered_map>

#include <unordered_set>

#include <tuple>

#include <iomanip>

//#include <cmath>

#include <queue>

#include <deque>

#include <stack>

//#pragma GCC optimize("Ofast")

//#pragma GCC target("avx,avx2")

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

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

typedef long double ld;

typedef long long ll;

typedef double db;

#define endl '\n'

#define pb push_back

#define pii pair<ll, ll>

#define ff first

#define ss second

#define sz(x) (ll)(x).size()

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

#pragma warning(disable:4996)



using namespace std;



const ll MX = 2e5 + 10, INF = 1e9 + 1;

ll n, m, t, d[MX], l[MX], r[MX], a[MX];

bool used[MX];

vector<vector<int>> g;



bool dfs(int v) {

	used[v] = true;

	bool f = true;

	for (auto c : g[v]) {

		int tmp = a[v], pos = l[c] + r[c] - v;

		if (l[c] == v)

			tmp += d[c];

		else

			tmp -= d[c];

		if (used[pos])

			f = f && (a[pos] == tmp);

		else {

			a[pos] = tmp;

			f = f && dfs(pos);

		}

	}

	return f;

}



signed main() {

	optimize1();

	cin >> n >> m;

	g.resize(n + 1);

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

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

		g[l[i]].pb(i);

		g[r[i]].pb(i);

	}

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

		if (used[i])

			continue;

		a[i] = 0;

		if (!dfs(i)) {

			cout << "No" << endl;

			return 0;

		}

	}

	cout << "Yes" << endl;

	return 0;

}