stablegradients/pie-gem5-pairs huggingface dataset:
// 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;

bool f;



void dfs(int from)

{

    vis[from] = v;

    for(auto pa : g[from])

    {

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

        {

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

            dfs(pa.f);

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

        {

            f =1;

        }

    }

}



void dfs1(int from)

{

    vis[from] = v;

    for(auto pa: g[from])

    {

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

        {

            dfs1(pa.f);

        }

    }

}



int main() {

    #   ifdef LOCAL_PROJECT

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

    #   endif

    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;

                }

            }

            dfs(i);

        }

        st.pop();

    }

    if(f) cout << "No";

    else cout << "Yes";

    return 0;

}

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

using namespace std;



#define int long long

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



typedef pair<int,int> ii;

typedef vector<ii> vii;



vector<vii> g;

int n,m,l,r,d;

int val[100001],ok;

bool visited[100001];



void dfs(int v) {

	visited[v]=true;

	rep(i,0,(int)g[v].size()-1) {

		ii p=g[v][i];

		if(visited[p.first]) {

			if(val[p.first]!=val[v]+p.second) {

					ok=false;

		return;

			}

		}

		else {

			val[p.first]=val[v]+p.second;

			dfs(p.first);

		}

		

	} 

}



signed main() {

	cin >> n >> m;

	g.assign(n+1,vii()) ;

	memset(visited,false,sizeof(visited));

	rep(i,1,m) {

		cin >> l >> r >> d;

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

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

	}

	rep(i,1,n) {

		if(!visited[i]) {

			ok=true;

			dfs(i);

			if(ok==false) {

				cout << "No";

				return 0;

			}

		}

	}

	cout << "Yes";

}
// Slower C++ solution:
/*|In The Name Of Allah|*/



#include <bits/stdc++.h>



using namespace std;



typedef pair < int , pair < int , int > > pll;



const int N = 1e5+5;



int n;

int m;

int dist[N];

int indeg[N];

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



int main(){

    memset(dist , -1 , sizeof dist);

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

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

        int l , r , d;

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

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

        indeg[r]++;

    }

    int bad = 0;

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

        if(!indeg[i]){

            queue < int > q;

            q.push(i);

            dist[i] = 0;

            while(!q.empty()){

                int u = q.front();

                q.pop();

                for(auto nw : adj[u]){

                    int v = nw.first;

                    int d = nw.second;

                    if(dist[v] == -1){

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

                        if(dist[v] > 1e9)

                            bad = 1;

                        q.push(v);

                    } else {

                        if(dist[v] != d + dist[u]){

                            bad = 1;

                        }

                    }

                }

            }

        }

    }

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

        if(dist[i] == -1)

            bad = 1;

    }

    puts(bad ? "No" : "Yes");

}


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

using namespace std;



#define int long long

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



typedef pair<int,int> ii;

typedef vector<ii> vii;



vector<vii> g;

int n,m,l,r,d;

int val[100001],ok;

bool visited[100001];



void dfs(int v) {

	visited[v]=true;

	rep(i,0,(int)g[v].size()-1) {

		ii p=g[v][i];

		if(visited[p.first]) {

			if(val[p.first]!=val[v]+p.second) {

					ok=false;

		return;

			}

		}

		else {

			val[p.first]=val[v]+p.second;

			dfs(p.first);

		}

		

	} 

}



signed main() {

	cin >> n >> m;

	g.assign(n+1,vii()) ;

	memset(visited,false,sizeof(visited));

	rep(i,1,m) {

		cin >> l >> r >> d;

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

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

	}

	rep(i,1,n) {

		if(!visited[i]) {

			ok=true;

			dfs(i);

			if(ok==false) {

				cout << "No";

				return 0;

			}

		}

	}

	cout << "Yes";

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

using namespace std;

#define REP(i,a) for(int i = 0; i < (a); i++)

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

typedef long long ll;

typedef pair<int, int> P;

const int INF = 1e9;

const int MOD = 1e9 + 7;



#define MAX_V 100000



struct edge { int to, cost; };



int V;//頂点数

vector<edge> G[MAX_V];//辺の張り方 : G[from].push_back((edge){to, cost});

int dist[MAX_V];

bool used[MAX_V];

bool no;



void DFS(int v, int d){

    if(used[v] == true){

        if(d != dist[v]){

            no = true;

        }

        return;

    }

    dist[v] = d;

    used[v] = true;

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

        DFS(G[v][i].to, d + G[v][i].cost);

    }

    return;

}



signed main(){

    int m;

    cin >> V >> m;

    int l,r,d;

    REP(i,m){

        cin >> l >> r >> d;

        l--;

        r--;

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

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

    }

    REP(i,V){

        if(!used[i]){

            DFS(i, 0);

            if(no){

                cout << "No" << endl;

                return 0;

            }

        }

    }

    cout << "Yes" << endl;

    return 0;

}

// Faster C++ solution for the same problem (measured speedup: 3.489546399788097x):
//ABC-87-B

#include <bits/stdc++.h>

using namespace std;

#define REP(i,a) for(int i = 0; i < (a); i++)

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

typedef long long ll;

typedef pair<int, int> P;

const int INF = 1e9;

const long long LINF = 1e18;

const long long MOD = 1e9 + 7;



template <typename T>

struct WeightedUnionFind{

    vector<int> par,siz;

    vector<T> ws;



    WeightedUnionFind(int n) : par(n), siz(n, 1), ws(n, T(0)){

        iota(par.begin(), par.end(), 0);

    }



    int root(int x){

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

        int t = root(par[x]);

        ws[x] += ws[par[x]];

        return par[x] = t;

    }



    T weight(int x){

        root(x);

        return ws[x];

    }



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

        w += weight(x);

        w -= weight(y);

        x = root(x);

        y = root(y);

        if(x == y) return;

        if(siz[x] < siz[y]){

            swap(x, y);

            w = -w;

        }

        siz[x] += siz[y];

        par[y] = x;

        ws[y] = w;

    }



    bool same(int x, int y){

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

    }



    int size(int x){

        return siz[root(x)];

    }



    T diff(int x, int y){

        return weight(y) - weight(x);

    }

};



signed main(){

    int n,m;

    cin >> n >> m;

    int l[m],r[m],d[m];

    REP(i,m){

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

        l[i]--;

        r[i]--;

    }

    WeightedUnionFind<ll> wuf(n);

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

        if(wuf.same(l[i], r[i]) && wuf.diff(l[i], r[i]) != d[i]){

            cout << "No" << endl;

            return 0;

        }

        wuf.unite(l[i], r[i], d[i]);

    }

    cout << "Yes" << endl;

    return 0;

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

using namespace std;

long long d[100005];

int n,m;

bool vis[100005],use[100005];

vector<int>v[100005];

vector<int>e[100005];

void read(int& x)

{

	char c=getchar();

	x=0;

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

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

	{

		x=x*10+c-'0';

		c=getchar();

	}

}

bool dfs(int fa)

{

	vis[fa]=1;

	use[fa]=1;

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

	{

		int y=v[fa][i];

		int z=e[fa][i];

		if(d[y]>d[fa]+z)

		{

			if(vis[y])return 1;

			d[y]=d[fa]+z;

			if(dfs(y))return 1;

		}

	}

	vis[fa]=0;

	return 0;

}

int main()

{

	read(n);

	read(m);

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

	{

		d[i]=200000000000ll;

	}

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

	{

		int x,y,z;

		read(x);

		read(y);

		read(z);

		v[x].push_back(y);

		e[x].push_back(z);

		v[y].push_back(x);

		e[y].push_back(-z);

	}

	bool ok=0;

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

	{

		if(!use[i])

		{

			d[i]=0;

			if(dfs(i))

			{

				ok=1;

			}

		}

	}

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

	else printf("Yes\n");

	return 0;

}

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

#define maxn 100005

using namespace std;



int fa[maxn], dis[maxn];



int find(int x)

{

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

	int t = fa[x];

	fa[x] = find(fa[x]);

	dis[x] += dis[t];

	return fa[x];

}



int main(int argc, char** argv)

{

	int n, m;

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

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

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

	{

		int l, r, d;

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

		int x = find(--l), y = find(--r);

		if(x == y && dis[l] - dis[r] != d)

		{

			puts("No");

			return 0;

		}

		if(x != y)

			fa[x] = fa[y], dis[x] = d + dis[r] - dis[l] + dis[y];

	}

	puts("Yes");

	return 0;

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

#include <algorithm>

#include <cstdio>

#include <cstdlib>

#include <cstring>

#include <cmath>

#include <iomanip>

#define inf -2147483647

using namespace std;

struct info

{

    int l,r,d;

}s[400005];

int n,m;

int flag = 1;

int dis[100005],visited[100005];

int first[400005],nexti[400005];

void dfs(int t)

{

    if(!flag)return;

    int k = first[t];

    while(k != -1)

    {

        if(!flag)return;

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

        {

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

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

            dfs(s[k].r);

        }

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

        {

            flag = 0;

            return;

        }

        k = nexti[k];

    }

}

int main()

{

    cin>>n>>m;

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

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

    {

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

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

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

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

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

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

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

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

    }

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

    {

        if(!visited[i])

        {

            visited[i] = 1;

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

            dfs(i);

        }

    }

    if(flag)cout<<"Yes";

    else cout<<"No";

}


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

#include <algorithm>

#include <cstdio>

#include <cstdlib>

#include <cstring>

#include <cmath>

#include <iomanip>

#define inf -2147483647

using namespace std;

struct info

{

    int l,r,d;

}s[400005];

int n,m;

int flag = 1;

int dis[100005],visited[100005];

int first[400005],nexti[400005];

void dfs(int t)

{

    if(!flag)return;

    int k = first[t];

    while(k != -1)

    {

        if(!flag)return;

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

        {

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

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

            dfs(s[k].r);

        }

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

        {

            flag = 0;

            return;

        }

        k = nexti[k];

    }

}

int main()

{

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

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

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

    {

        scanf("%d%d%d",&s[i].l,&s[i].r,&s[i].d);

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

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

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

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

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

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

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

    }

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

    {

        if(!visited[i])

        {

            visited[i] = 1;

            memset(dis,0,sizeof(int) * (n + 1));

            dfs(i);

        }

    }

    if(flag)printf("Yes");

    else printf("No");

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

#include <algorithm>

#include <cstdio>

#include <cstdlib>

#include <cstring>

#include <cmath>

#include <iomanip>

#define inf -2147483647

using namespace std;

struct info

{

    int l,r,d;

}s[400005];

int n,m;

int flag = 1;

int dis[100005],visited[100005];

int first[400005],nexti[400005];

void dfs(int t)

{

    if(!flag)return;

    int k = first[t];

    while(k != -1)

    {

        if(!flag)return;

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

        {

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

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

            dfs(s[k].r);

        }

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

        {

            flag = 0;

            return;

        }

        k = nexti[k];

    }

}

int main()

{

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

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

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

    {

        scanf("%d%d%d",&s[i].l,&s[i].r,&s[i].d);

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

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

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

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

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

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

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

    }

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

    {

        if(!visited[i])

        {

            visited[i] = 1;

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

            dfs(i);

        }

    }

    if(flag)printf("Yes");

    else printf("No");

}


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

#include <algorithm>

#include <cstdio>

#include <cstdlib>

#include <cstring>

#include <cmath>

#include <iomanip>

#define inf -2147483647

using namespace std;

struct info

{

    int l,r,d;

}s[400005];

int n,m;

int flag = 1;

int dis[100005],visited[100005];

int first[400005],nexti[400005];

void dfs(int t)

{

    if(!flag)return;

    int k = first[t];

    while(k != -1)

    {

        if(!flag)return;

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

        {

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

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

            dfs(s[k].r);

        }

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

        {

            flag = 0;

            return;

        }

        k = nexti[k];

    }

}

int main()

{

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

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

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

    {

        scanf("%d%d%d",&s[i].l,&s[i].r,&s[i].d);

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

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

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

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

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

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

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

    }

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

    {

        if(!visited[i])

        {

            visited[i] = 1;

            memset(dis,0,sizeof(int) * (n + 1));

            dfs(i);

        }

    }

    if(flag)printf("Yes");

    else printf("No");

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

using namespace std;



#define ll long long



int n,m;

int L,R,D;

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

int dis[100100];

bool vis[100100];

int flag;



void dfs(int u,int pre)

{

    if(!flag) return;

     int sz=mp[u].size();

     pair<int,int>tmp;

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

     {

        tmp=mp[u][i];

        if(vis[tmp.first])

        {

            if(dis[u]+tmp.second!=dis[tmp.first])

            {

                flag=0;return;

            }

        }

        else

        {

            vis[tmp.first]=1;

            dis[tmp.first]=dis[u]+tmp.second;

            dfs(tmp.first,u);

        }

     }

}



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

{

    /* code */

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

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

    {

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

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

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

    }

    flag=1;

    for(int i=1;i<=n;++i) if(!vis[i])

    {

        vis[i]=1;

        dfs(i,-1);

    }

    if(flag) puts("Yes");else puts("No");

    return 0;

}

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

#include <algorithm>

#include <cstdio>

#include <cstdlib>

#include <cstring>

#include <cmath>

#include <iomanip>

#define inf -2147483647

using namespace std;

struct info

{

    int l,r,d;

}s[400005];

int n,m;

int flag = 1;

int dis[100005],visited[100005];

int first[400005],nexti[400005];

void dfs(int t)

{

    if(!flag)return;

    int k = first[t];

    while(k != -1)

    {

        if(!flag)return;

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

        {

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

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

            dfs(s[k].r);

        }

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

        {

            flag = 0;

            return;

        }

        k = nexti[k];

    }

}

int main()

{

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

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

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

    {

        scanf("%d%d%d",&s[i].l,&s[i].r,&s[i].d);

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

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

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

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

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

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

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

    }

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

    {

        if(!visited[i])

        {

            visited[i] = 1;

            memset(dis,0,sizeof(int) * (n + 1));

            dfs(i);

        }

    }

    if(flag)printf("Yes");

    else printf("No");

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

using namespace std;



#define ll long long



int n,m;

int L,R,D;

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

int dis[100100];

bool vis[100100];

int flag;



void dfs(int u,int pre)

{

    if(!flag) return;

     int sz=mp[u].size();

     pair<int,int>tmp;

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

     {

        tmp=mp[u][i];

        if(vis[tmp.first])

        {

            if(dis[u]+tmp.second!=dis[tmp.first])

            {

                flag=0;return;

            }

        }

        else

        {

            vis[tmp.first]=1;

            dis[tmp.first]=dis[u]+tmp.second;

            dfs(tmp.first,u);

        }

     }

}



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

{

    /* code */

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

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

    {

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

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

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

    }

    flag=1;

    for(int i=1;i<=n;++i) if(!vis[i])

    {

        vis[i]=1;

        dfs(i,-1);

    }

    if(flag) puts("Yes");else puts("No");

    return 0;

}

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

#include <algorithm>

#include <cstdio>

#include <cstdlib>

#include <cstring>

#include <cmath>

#include <iomanip>

#define inf -2147483647

using namespace std;

struct info

{

    int l,r,d;

}s[400005];

int n,m;

int flag = 1;

int dis[100005],visited[100005];

int first[400005],nexti[400005];

void dfs(int t)

{

    if(!flag)return;

    int k = first[t];

    while(k != -1)

    {

        if(!flag)return;

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

        {

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

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

            dfs(s[k].r);

        }

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

        {

            flag = 0;

            return;

        }

        k = nexti[k];

    }

}

int main()

{

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

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

    memset(dis,2000000000,sizeof(dis));

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

    {

        scanf("%d%d%d",&s[i].l,&s[i].r,&s[i].d);

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

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

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

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

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

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

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

    }

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

    {

        if(!visited[i])

        {

            visited[i] = 1;

            dfs(i);

        }

    }

    if(flag)printf("Yes");

    else printf("No");

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

#include <algorithm>

#include <cstdio>

#include <cstdlib>

#include <cstring>

#include <cmath>

#include <iomanip>

#define inf -2147483647

using namespace std;

struct info

{

    int l,r,d;

}s[400005];

int n,m;

int flag = 1;

int dis[100005],visited[100005];

int first[400005],nexti[400005];

void dfs(int t)

{

    if(!flag)return;

    int k = first[t];

    while(k != -1)

    {

        if(!flag)return;

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

        {

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

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

            dfs(s[k].r);

        }

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

        {

            flag = 0;

            return;

        }

        k = nexti[k];

    }

}

int main()

{

    cin>>n>>m;

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

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

    {

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

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

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

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

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

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

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

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

    }

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

    {

        if(!visited[i])

        {

            visited[i] = 1;

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

            dfs(i);

        }

    }

    if(flag)cout<<"Yes";

    else cout<<"No";

}


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

#include <algorithm>

#include <cstdio>

#include <cstdlib>

#include <cstring>

#include <cmath>

#include <iomanip>

#define inf -2147483647

using namespace std;

struct info

{

    int l,r,d;

}s[400005];

int n,m;

int flag = 1;

int dis[100005],visited[100005];

int first[400005],nexti[400005];

void dfs(int t)

{

    if(!flag)return;

    int k = first[t];

    while(k != -1)

    {

        if(!flag)return;

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

        {

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

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

            dfs(s[k].r);

        }

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

        {

            flag = 0;

            return;

        }

        k = nexti[k];

    }

}

int main()

{

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

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

    //memset(dis,2000000000,sizeof(dis));

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

    {

        scanf("%d%d%d",&s[i].l,&s[i].r,&s[i].d);

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

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

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

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

        if(s[i].d)s[i + m].d = - s[i].d;

        else s[i].d = 0;

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

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

    }

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

    {

        if(!visited[i])

        {

            visited[i] = 1;

            dfs(i);

        }

    }

    if(flag)printf("Yes");

    else printf("No");

}