stablegradients/pie-gem5-pairs huggingface dataset:
// 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 ( int (i) = a; (i) < (b) ; (i) ++ )

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

#define repD(i, a, b) for ( int (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 print cout << endl

#define tri pair<pair<int, int>, int>

using namespace std;



int n,m;

int fa[100005], cnt[100005];

void find(int x){

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

    find(fa[x]);

    cnt[x] += cnt[fa[x]]; fa[x] = fa[fa[x]];

}



int main(){

    while ( cin >> n >> m ) {

        bool has = false;

        MSET(fa); MSET(cnt);

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

        for ( int i = 0, x, y, z ; i < m ; ++ i ) {

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

            find(x); find(y);

            if ( fa[x] == fa[y] ) {

                if ( cnt[y] != cnt[x] + z ) has = true;

            }

            else {

                cnt[fa[y]] = z - cnt[y];

                fa[fa[y]] = x;

            }

        }

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

    }

}


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



using namespace std;



#define int long long





vector<int> x;

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



vector<int> used;

void dfs(int v) {

    used[v] = 1;

    for (auto l: g[v]) {

        int to = l.first;

        int w = l.second;

        if (x[to] != -1) {

            if (x[v] + w != x[to]) {

                cout << "No";

                exit(0);

            }

        }

        else {

            x[to] = x[v] + w;

            if (!used[to]) dfs(to);

        }

    }

}



void solve() {

    int n;

    cin >> n;

    x.assign(n, -1);

    g.resize(n);

    used.resize(n);

    int m;

    cin >> m;

    set<int> st;

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

        int l, r, d;

        cin >> l >> r >> d;

        l--;

        r--;

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

        st.insert(r);

    }

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

        if (st.count(i)) continue;

        if (!used[i]) dfs(i);

    }

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

        if (!used[i]) {

            cout << "No";

            return;

        }

    }

    cout << "Yes";





}



signed main() {

    //freopen

    ios_base::sync_with_stdio(0);

    cin.tie(0);

    cout.tie(0);

    solve();

}

/*

5 5

4 5 1

5 1 1

1 2 1

2 3 1

4 3 4



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

using namespace std;

const int N = 1e5 + 25, M = 1e6 + 25, oo = 1e9+7, mxmsk = 1 << 16;

const long long OO = 1e18+25;

    

#define f first

#define s second

    

int n,m,l,r,d, dis[N], vis[N], v=1;

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

stack <int> st;

int dfs(int from)

{

    vis[from] = v;

    for(auto pa : g[from])

    {

        if(vis[pa.f] != v)

        {

            dis[pa.f] = dis[from] + pa.s;

            if(dfs(pa.f) == -1)

            {

                return -1;

            }

        }else if(dis[pa.f] != dis[from] + pa.s)

        {

            return -1;

        }

    }

    return 1;

}



void dfs1(int from)

{

    vis[from] = v;

    for(auto pa: g[from])

    {

        if(vis[pa.f] != v)

        {

            dfs1(pa.f);

        }

    }

}



int main() {

    cin >> n >> m;

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

    {

        cin >> l >> r >> d;

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

    }

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

    {

        if(vis[i] != v) 

        {

            st.push(i);

            dfs1(i);

        }

    }

    v++;

    while(!st.empty())

    {

        int i = st.top();

        if(vis[i] != v)

        {

            for(auto pa : g[i])

            {

                if(vis[pa.f] == v)

                {

                    dis[i] = dis[pa.f] - pa.s;

                    break;

                }

            }

            if(dfs(i) == -1)

            {

               cout << "No";

                return 0;

            }

        }

        st.pop();

    }

    cout << "Yes";

    return 0;

}

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



using namespace std;



#define int long long





vector<int> x;

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



vector<int> used;

void dfs(int v) {

    used[v] = 1;

    for (auto l: g[v]) {

        int to = l.first;

        int w = l.second;

        if (x[to] != -1) {

            if (x[v] + w != x[to]) {

                cout << "No";

                exit(0);

            }

        }

        else {

            x[to] = x[v] + w;

            if (!used[to]) dfs(to);

        }

    }

}



void solve() {

    int n;

    cin >> n;

    x.assign(n, -1);

    g.resize(n);

    used.resize(n);

    int m;

    cin >> m;

    set<int> st;

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

        int l, r, d;

        cin >> l >> r >> d;

        l--;

        r--;

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

        st.insert(r);

    }

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

        if (st.count(i)) continue;

        if (!used[i]) dfs(i);

    }

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

        if (!used[i]) {

            cout << "No";

            return;

        }

    }

    cout << "Yes";





}



signed main() {

    //freopen

    ios_base::sync_with_stdio(0);

    cin.tie(0);

    cout.tie(0);

    solve();

}

/*

5 5

4 5 1

5 1 1

1 2 1

2 3 1

4 3 4



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



using namespace std;



#define _ << " " <<

#define pb push_back

#define ff first

#define ss second





typedef long long ll;

typedef long double ld;



#define int ll



const int MAXN = 1e5 + 5;



vector<int> used(MAXN);



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



bool bfs(int v) {

    vector<int> q = {v};

    int ind = 0;

    map<int, int> dst;

    dst[v] = 0;

    used[v] = 1;

    while (q.size() > ind) {

        int tmp = q[ind];

        ++ind;

        for (auto to : g[tmp]) {

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

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

            } else {

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

                used[to.ff] = 1;

                q.pb(to.ff);

            }

        }

    }

    return true;

}



void solve() {

    int n, m;

    cin >> n >> m;

    int l, r, d;

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

        cin >> l >> r >> d;

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

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

    }

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

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

            cout << "No";

            return;

        }

    }

    cout << "Yes";

}



signed main() {

    ios_base::sync_with_stdio(false);

    cin.tie(nullptr);

    cout.tie(nullptr);

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

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

    int test = 1;

    //cin >> test;

    while (test--) {

        solve();

    }

}


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



using namespace std;



#define int long long





vector<int> x;

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



vector<int> used;

void dfs(int v) {

    used[v] = 1;

    for (auto l: g[v]) {

        int to = l.first;

        int w = l.second;

        if (x[to] != -1) {

            if (x[v] + w != x[to]) {

                cout << "No";

                exit(0);

            }

        }

        else {

            x[to] = x[v] + w;

            if (!used[to]) dfs(to);

        }

    }

}



void solve() {

    int n;

    cin >> n;

    x.assign(n, -1);

    g.resize(n);

    used.resize(n);

    int m;

    cin >> m;

    set<int> st;

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

        int l, r, d;

        cin >> l >> r >> d;

        l--;

        r--;

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

        st.insert(r);

    }

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

        if (st.count(i)) continue;

        if (!used[i]) dfs(i);

    }

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

        if (!used[i]) {

            cout << "No";

            return;

        }

    }

    cout << "Yes";





}



signed main() {

    //freopen

    ios_base::sync_with_stdio(0);

    cin.tie(0);

    cout.tie(0);

    solve();

}

/*

5 5

4 5 1

5 1 1

1 2 1

2 3 1

4 3 4



 */
// Slower C++ solution:
#include<stdio.h>

#include<string.h>

#include<iostream>

#include<malloc.h>

#include<math.h>

#include<algorithm>



using namespace std;



const int maxn = 1e5+100;

int n,m,tag,f[maxn],dis[maxn];



int getfa(int x)

{

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

    int fx = getfa(f[x]);

    dis[x] += dis[f[x]];

    f[x] = fx;

    return f[x];

}



int main()

{

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

    tag = 1;

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

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

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

    {

        int x,y,d;

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

        int fx = getfa(x);

        int fy = getfa(y);

        if (fx == fy)

        {

            if (dis[y] != dis[x]+d) tag = 0;

        }

        else

        {

            f[fy] = fx;

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

        }

    }

    if (tag) printf("Yes");

    else

        printf("No");

    return 0;

}


// Faster C++ solution for the same problem (measured speedup: 1.4066409338627262x):
#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 <stdio.h>

#include <fstream>

#include <algorithm>

#include <ctime>

#include <cstdlib>

#include <cstring>

#include <vector>

#include <set>

#include <string>

#include <queue>

#include <map>

#include <iomanip>

#include <cassert>

#include <complex>

#include <functional>

#include <list>

using namespace std;

typedef pair<int,int> pii;

const int INF=1e9+7;

int dp[100005];

int n,m;

vector<pii> nei[100005];

int main(){

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

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

		int a,b,c;

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

		a--;

		b--;

		nei[a].push_back(make_pair(b,c));

		nei[b].push_back(make_pair(a,-c));

	}

	fill(dp,dp+100005,INF);

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

		if(dp[i]==INF){

			//f/or(int i=0;i<n;i++){

				//c/out<<dp[i]<<" ";

			//}

			//cout<<endl;

			queue<int> q;

			q.push(i);

			dp[i]=0;

			for(;q.size();){

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

				for(int j=0;j<nei[t].size();j++){

					pii p=nei[t][j];

					int pp=p.first,c=p.second;

					if(dp[pp]==INF){

						dp[pp]=dp[t]+c;

						q.push(pp);

					}

					else if(dp[pp]!=dp[t]+c){

						puts("No");

						return 0;

					}

				}

			}

		}

	}

	puts("Yes");

	return 0;

}

// Faster C++ solution for the same problem (measured speedup: 3.9875691852506825x):
#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 <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 ( int (i) = a; (i) < (b) ; (i) ++ )

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

#define repD(i, a, b) for ( int (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 print cout << endl

#define tri pair<pair<int, int>, int>

using namespace std;



int n,m;

int fa[100005], cnt[100005];

void find(int x){

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

    find(fa[x]);

    cnt[x] += cnt[fa[x]]; fa[x] = fa[fa[x]];

}



int main(){

    while ( cin >> n >> m ) {

        bool has = false;

        MSET(fa); MSET(cnt);

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

        for ( int i = 0, x, y, z ; i < m ; ++ i ) {

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

            find(x); find(y);

            if ( fa[x] == fa[y] ) {

                if ( cnt[y] != cnt[x] + z ) has = true;

            }

            else {

                cnt[fa[y]] = z - cnt[y];

                fa[fa[y]] = x;

            }

        }

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

    }

}


// Faster C++ solution for the same problem (measured speedup: 1.8306036156289942x):
#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;

const int N = 1e5 + 25, M = 1e6 + 25, oo = 1e9+7, mxmsk = 1 << 16;

const long long OO = 1e18+25;

    

#define f first

#define s second

    

int n,m,l,r,d, dis[N], vis[N], v=1;

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

stack <int> st;

int dfs(int from)

{

    vis[from] = v;

    for(auto pa : g[from])

    {

        if(vis[pa.f] != v)

        {

            dis[pa.f] = dis[from] + pa.s;

            if(dfs(pa.f) == -1)

            {

                return -1;

            }

        }else if(dis[pa.f] != dis[from] + pa.s)

        {

            return -1;

        }

    }

    return 1;

}



void dfs1(int from)

{

    vis[from] = v;

    for(auto pa: g[from])

    {

        if(vis[pa.f] != v)

        {

            dfs1(pa.f);

        }

    }

}



int main() {

    cin >> n >> m;

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

    {

        cin >> l >> r >> d;

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

    }

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

    {

        if(vis[i] != v) 

        {

            st.push(i);

            dfs1(i);

        }

    }

    v++;

    while(!st.empty())

    {

        int i = st.top();

        if(vis[i] != v)

        {

            for(auto pa : g[i])

            {

                if(vis[pa.f] == v)

                {

                    dis[i] = dis[pa.f] - pa.s;

                    break;

                }

            }

            if(dfs(i) == -1)

            {

               cout << "No";

                return 0;

            }

        }

        st.pop();

    }

    cout << "Yes";

    return 0;

}

// Faster C++ solution for the same problem (measured speedup: 3.5915648548845565x):
#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;



#define _ << " " <<

#define pb push_back

#define ff first

#define ss second





typedef long long ll;

typedef long double ld;



#define int ll



const int MAXN = 1e5 + 5;



vector<int> used(MAXN);



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



bool bfs(int v) {

    vector<int> q = {v};

    int ind = 0;

    map<int, int> dst;

    dst[v] = 0;

    used[v] = 1;

    while (q.size() > ind) {

        int tmp = q[ind];

        ++ind;

        for (auto to : g[tmp]) {

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

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

            } else {

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

                used[to.ff] = 1;

                q.pb(to.ff);

            }

        }

    }

    return true;

}



void solve() {

    int n, m;

    cin >> n >> m;

    int l, r, d;

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

        cin >> l >> r >> d;

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

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

    }

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

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

            cout << "No";

            return;

        }

    }

    cout << "Yes";

}



signed main() {

    ios_base::sync_with_stdio(false);

    cin.tie(nullptr);

    cout.tie(nullptr);

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

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

    int test = 1;

    //cin >> test;

    while (test--) {

        solve();

    }

}


// Faster C++ solution for the same problem (measured speedup: 4.454426297338582x):
#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 <stdio.h>

#include <fstream>

#include <algorithm>

#include <ctime>

#include <cstdlib>

#include <cstring>

#include <vector>

#include <set>

#include <string>

#include <queue>

#include <map>

#include <iomanip>

#include <cassert>

#include <complex>

#include <functional>

#include <list>

using namespace std;

typedef pair<int,int> pii;

const int INF=1e9+7;

int dp[100005];

int n,m;

vector<pii> nei[100005];

int main(){

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

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

		int a,b,c;

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

		a--;

		b--;

		nei[a].push_back(make_pair(b,c));

		nei[b].push_back(make_pair(a,-c));

	}

	fill(dp,dp+100005,INF);

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

		if(dp[i]==INF){

			//f/or(int i=0;i<n;i++){

				//c/out<<dp[i]<<" ";

			//}

			//cout<<endl;

			queue<int> q;

			q.push(i);

			dp[i]=0;

			for(;q.size();){

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

				for(int j=0;j<nei[t].size();j++){

					pii p=nei[t][j];

					int pp=p.first,c=p.second;

					if(dp[pp]==INF){

						dp[pp]=dp[t]+c;

						q.push(pp);

					}

					else if(dp[pp]!=dp[t]+c){

						puts("No");

						return 0;

					}

				}

			}

		}

	}

	puts("Yes");

	return 0;

}

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

using namespace std;

#define int long long

#define vi vector<int>

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

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

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

#define eb emplace_back

#define pb push_back

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

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

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

#define ii pair<int,int>

#define fi first

#define se second

#define endl '\n'

#define gcd __gcd

const int maxn=1e5+1;

const int INF=1e9+1;



bool used[maxn];

vector<ii> adj[maxn];



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

{

	used[node]=1;

	for (ii i : adj[node])

		if (!used[i.fi])

		{

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

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

		}	

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

		{

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

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

			

		}

}



signed main()

{

	fastio;

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

	while (m--)

	{

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

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

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

	}

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

	{

		int a[n+1];

		a[i]=0;

		dfs(a,i,0);

	}

	cout<<"Yes";

}