stablegradients/pie-gem5-bysrc huggingface dataset:
// Original C++ solution (slower):
/**********************************************************************/

/********                                                      ********/

/********                     Writer:孙~~                      ********/

/********                       Lang:C++                       ********/

/********                     Status:Unknow                    ********/

/********                                                      ********/

/**********************************************************************/

#include <iostream>

#include <string>

#include <cstdio>

#include <vector>

#include <queue>

#include <list>

#include <cstdlib>

#include <algorithm>

#include <set>

#include <map>

#include <deque>

#include <cstring>

#include <cmath>

//#include<bits/stdc++.h>

using namespace std;



const int INF=0x3f3f3f3f;

const int SIZE=100005;



int n,m;

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

bool vis[SIZE];

long long val[SIZE];



bool bfs(int i){

	queue<int> que;

	que.push(i);

	val[i]=0;

	while(!que.empty()){

		int v=que.front();

		que.pop();

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

			pair<int,int> u=mp[v][i];

			int to=u.first;

			if(val[to]==INF){

				val[to]=val[v]+u.second;

				que.push(to);

			}

			else if(val[to]!=val[v]+u.second){

				return false;

			}

		}

	}

	return true;

}



int main(){

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

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

		int l,r,d;

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

		l--;

		r--;

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

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

	}

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

	for(int i=0;i<n;i++) if(val[i]==INF) if(!bfs(i)){

		puts("No");

		return 0;

	}

	puts("Yes");

	return 0;

}






// Optimized solution to the same problem (faster):
#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");

}

// Fastest known solution for this problem:
// Original C++ solution (slower):
#include <bits/stdc++.h>

#define x first

#define y second

using namespace std;

typedef long long ll;

const int N = 1e5 + 10;

const int mod = 1e9 + 7;

#define int long long

int n, m;

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



bool used[N];

int pos[N];



void dfs(int u)

{

    used[u] = 1;

    for (auto t : gr[u])

    {

        int v = t.x;

        int d = t.y;

        if (!used[v])

        {

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

            dfs(v);

        } else

        {

            if (pos[v] != pos[u] + d)

            {

                cout << "No";

                exit(0);

            }

        }

    }

}



main()

{

    ios_base::sync_with_stdio(0);

    cin.tie(0);



    cin >> n >> m;

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

    {

        int l, r;

        int d;

        cin >> l >> r >> d;

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

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

    }

    int ma = -1e18, mi = 1e18;

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

    {

        if (!used[i])

        {

            pos[i] = 0;

            dfs(i);

        }

        ma = max(ma, pos[i]);

        mi = min(mi, pos[i]);

    }



    if (ma - mi > 1e9)

    {

        cout << "Noe";

    } else cout << "Yes";





    return 0;

}


// Optimized solution to the same problem (faster):
#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");

}

// Fastest known solution for this problem:
// Original C++ solution (slower):
#include <iostream>

#include <cstdio>

#include <string>

#include <algorithm>

#include <utility>

#include <cmath>

#include <vector>

#include <queue>

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

using namespace std;

typedef long long ll;

const ll mod = 1000000007;



struct edge {

    int to;

    int weight;

};



vector<edge> G[200010];

bool visit[100010];

int d[100010];



bool dfs(int v, int dist) {



    if(visit[v]) {

        if(d[v] != dist) {

            return true;

        }

        else {

            return false;

        }

    }



    visit[v] = true;

    d[v] = dist;

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

        if(dfs(G[v][i].to, d[v] + G[v][i].weight)) {

            return true;

        }

    }



    return false;

}



int main() {

    int n, m;

    cin >> n >> m;



    rep(i, m) {

        int L, R, D;

        cin >> L >> R >> D;

        L--;  R--;

        G[L].push_back({R,D});

        G[R].push_back({L,-D});

    }



    rep(i, n) {

        if(!visit[i] && dfs(i, 0)) {

            cout << "No" << endl;

            return 0;

        }

    }

    

    cout << "Yes" << endl;

    return 0;

}

// Optimized solution to the same problem (faster):
#include <iostream>

#include <cstdio>

#include <string>

#include <algorithm>

#include <utility>

#include <cmath>

#include <vector>

#include <queue>

#include <set>

#include <map>

#include <tuple>

#include <numeric>

#include <functional>

using namespace std;

typedef long long ll;

typedef vector<ll> vl;

typedef vector<vector<ll>> vvl;

typedef pair<ll, ll> P;

#define rep(i, n) for(ll i = 0; i < n; i++)

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

#define out(x) cout << x << endl

#define exout(x) printf("%.10f\n", x)

#define chmax(x, y) x = max(x, y)

#define chmin(x, y) x = min(x, y)

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

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

#define pb push_back

#define re0 return 0

const ll mod = 1000000007;

const ll INF = 1e16;

const ll MAX_N = 100010;



vector<vector<P>> G;

vl height;

bool ok = true;



void dfs(ll v, ll h) {

    // 行きの処理はこのへんに書く

    if(ok == false) {

        return;

    }

    if(height[v] == -INF) {

        height[v] = h;

    }

    else {

        if(height[v] != h) {

            ok = false;

        }

        return;

    }

    for(auto p : G[v]) { 

        ll u = p.first;

        ll cost = p.second;

        dfs(u, h + cost);

        // 帰りの処理はこのへんに書く

    }

}



int main() {

    ll n, m;

    cin >> n >> m;    

    

    G.resize(n);

    rep(i, m) {

        ll a, b, c;

        cin >> a >> b >> c;

        a--;  b--;

        G[a].pb(make_pair(b, c));

        G[b].pb(make_pair(a, -c));

    }



    height.assign(n, -INF);

    rep(v, n) {

        if(height[v] == -INF) {

            dfs(v, 0);

        }

    }



    if(ok) {

        out("Yes");

    }

    else {

        out("No");

    }



    re0;

}

// Fastest known solution for this problem:
// Original C++ solution (slower):
#include <iostream>

#include <cstdio>

#include <string>

#include <algorithm>

#include <utility>

#include <cmath>

#include <vector>

#include <queue>

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

using namespace std;

typedef long long ll;

const ll mod = 1000000007;



struct edge {

    int to;

    int weight;

};



vector<edge> G[200010];

bool visit[100010];

int d[100010];



int dfs(int v, int dist) {



    if(visit[v]) {

        if(d[v] != dist) {

            return 1;

        }

        else {

            return 0;

        }

    }



    visit[v] = true;

    d[v] = dist;

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

        if(dfs(G[v][i].to, d[v] + G[v][i].weight)) {

            return 1;

        }

    }



    return 0;

}



int main() {

    int n, m;

    cin >> n >> m;



    rep(i, m) {

        int L, R, D;

        cin >> L >> R >> D;

        L--;  R--;

        G[L].push_back({R,D});

        G[R].push_back({L,-D});

    }



    rep(i, n) {

        if(!visit[i] && dfs(i, 0)) {

            cout << "No" << endl;

            return 0;

        }

    }

    

    cout << "Yes" << endl;

    return 0;

}

// Optimized solution to the same problem (faster):
#include <iostream>

#include <cstdio>

#include <string>

#include <algorithm>

#include <utility>

#include <cmath>

#include <vector>

#include <queue>

#include <set>

#include <map>

#include <tuple>

#include <numeric>

#include <functional>

using namespace std;

typedef long long ll;

typedef vector<ll> vl;

typedef vector<vector<ll>> vvl;

typedef pair<ll, ll> P;

#define rep(i, n) for(ll i = 0; i < n; i++)

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

#define out(x) cout << x << endl

#define exout(x) printf("%.10f\n", x)

#define chmax(x, y) x = max(x, y)

#define chmin(x, y) x = min(x, y)

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

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

#define pb push_back

#define re0 return 0

const ll mod = 1000000007;

const ll INF = 1e16;

const ll MAX_N = 100010;



vector<vector<P>> G;

vl height;

bool ok = true;



void dfs(ll v, ll h) {

    // 行きの処理はこのへんに書く

    if(ok == false) {

        return;

    }

    if(height[v] == -INF) {

        height[v] = h;

    }

    else {

        if(height[v] != h) {

            ok = false;

        }

        return;

    }

    for(auto p : G[v]) { 

        ll u = p.first;

        ll cost = p.second;

        dfs(u, h + cost);

        // 帰りの処理はこのへんに書く

    }

}



int main() {

    ll n, m;

    cin >> n >> m;    

    

    G.resize(n);

    rep(i, m) {

        ll a, b, c;

        cin >> a >> b >> c;

        a--;  b--;

        G[a].pb(make_pair(b, c));

        G[b].pb(make_pair(a, -c));

    }



    height.assign(n, -INF);

    rep(v, n) {

        if(height[v] == -INF) {

            dfs(v, 0);

        }

    }



    if(ok) {

        out("Yes");

    }

    else {

        out("No");

    }



    re0;

}

// Fastest known solution for this problem:
// Original C++ solution (slower):
#include <iostream>

#include <cstdio>

#include <string>

#include <algorithm>

#include <utility>

#include <cmath>

#include <vector>

#include <queue>

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

using namespace std;

using Graph = vector<vector<int>>;

typedef long long ll;

const ll mod = 1000000007;

const int MAX_N = 100010;



Graph to(MAX_N), cost(MAX_N);

vector<int> visit(MAX_N), d(MAX_N);



bool dfs(int v, int dist) {

 

    if(visit[v]) {



        if(d[v] != dist) {

            return false;

        }

        

        return true;

    }



    visit[v] = 1;

    d[v] = dist;

    rep(u, to[v].size()) {

        if( !dfs(to[v][u], d[v] + cost[v][u]) ) {

            return false;

        }

    }

 

    return true;

}



int main() {

    int n, m;

    cin >> n >> m;



    rep(i, m) {

        int L, R, w;

        cin >> L >> R >> w;

        L--;  R--;

        to[L].push_back(R);

        to[R].push_back(L);

        cost[L].push_back(w);

        cost[R].push_back(-w);

    }



    rep(i, n) {

        if(!visit[i] && !dfs(i, 0)) {

            cout << "No" << endl;

            return 0;

        }

    }

    

    cout << "Yes" << endl;

    return 0;

}

// Optimized solution to the same problem (faster):
#include <iostream>

#include <cstdio>

#include <string>

#include <algorithm>

#include <utility>

#include <cmath>

#include <vector>

#include <queue>

#include <set>

#include <map>

#include <tuple>

#include <numeric>

#include <functional>

using namespace std;

typedef long long ll;

typedef vector<ll> vl;

typedef vector<vector<ll>> vvl;

typedef pair<ll, ll> P;

#define rep(i, n) for(ll i = 0; i < n; i++)

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

#define out(x) cout << x << endl

#define exout(x) printf("%.10f\n", x)

#define chmax(x, y) x = max(x, y)

#define chmin(x, y) x = min(x, y)

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

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

#define pb push_back

#define re0 return 0

const ll mod = 1000000007;

const ll INF = 1e16;

const ll MAX_N = 100010;



vector<vector<P>> G;

vl height;

bool ok = true;



void dfs(ll v, ll h) {

    // 行きの処理はこのへんに書く

    if(ok == false) {

        return;

    }

    if(height[v] == -INF) {

        height[v] = h;

    }

    else {

        if(height[v] != h) {

            ok = false;

        }

        return;

    }

    for(auto p : G[v]) { 

        ll u = p.first;

        ll cost = p.second;

        dfs(u, h + cost);

        // 帰りの処理はこのへんに書く

    }

}



int main() {

    ll n, m;

    cin >> n >> m;    

    

    G.resize(n);

    rep(i, m) {

        ll a, b, c;

        cin >> a >> b >> c;

        a--;  b--;

        G[a].pb(make_pair(b, c));

        G[b].pb(make_pair(a, -c));

    }



    height.assign(n, -INF);

    rep(v, n) {

        if(height[v] == -INF) {

            dfs(v, 0);

        }

    }



    if(ok) {

        out("Yes");

    }

    else {

        out("No");

    }



    re0;

}

// Fastest known solution for this problem:
// Original C++ solution (slower):
#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

}

// Optimized solution to the same problem (faster):
#include <stdio.h>

#include <string.h>

#include <stdlib.h>

#include <math.h>

#include <time.h>

#include <iostream>

#include <algorithm>

#include <string>

#include <set>

#include <map>

#include <queue>

#include <stack>

#include <bitset>

#include <vector>

using namespace std;



#define bll long long

#define dou double

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

#define Rof(i,a,b) for (int i=(a),_##i=(b); i>=_##i; --i)

#define Mem(a,b) memset(a,b,sizeof(a))

#define Cpy(a,b) memcpy(a,b,sizeof(b))



const int maxn=1e5+100;

int N,M,u[maxn],link[maxn];

int dlt[maxn];



int get_u(int x,int &ret)

{

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

    u[x]=get_u(u[x],ret);

    ret+=dlt[x];

    dlt[x]=ret;

    return u[x];

}



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

{

    int rx=0,ry=0;

    int a=get_u(x,rx),b=get_u(y,ry);

    if (a==b) return (dlt[y]-dlt[x]==d);

    if (link[a]<link[b]) swap(a,b),swap(x,y),d=-d;

    u[b]=a;

    link[a]+=(link[a]==link[b]);

    dlt[b]=dlt[x]-dlt[y]+d;

    return 1;

}



int main()

{

    for (; scanf("%d%d",&N,&M)!=EOF; )

    {

        bool flag=1;

        For(i,1,N) u[i]=i,link[i]=0,dlt[i]=0;

        For(i,1,M)

        {

            int x,y,d;

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

            if (flag) flag=check(x,y,d);

        }

        if (flag)

            printf("Yes\n");

        else

            printf("No\n");

    }

    return 0;

}


// Fastest known solution for this problem:
// Original C++ solution (slower):
#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;

}


// Optimized solution to the same problem (faster):
#include <stdio.h>

#include <string.h>

#include <stdlib.h>

#include <math.h>

#include <time.h>

#include <iostream>

#include <algorithm>

#include <string>

#include <set>

#include <map>

#include <queue>

#include <stack>

#include <bitset>

#include <vector>

using namespace std;



#define bll long long

#define dou double

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

#define Rof(i,a,b) for (int i=(a),_##i=(b); i>=_##i; --i)

#define Mem(a,b) memset(a,b,sizeof(a))

#define Cpy(a,b) memcpy(a,b,sizeof(b))



const int maxn=1e5+100;

int N,M,u[maxn],link[maxn];

int dlt[maxn];



int get_u(int x,int &ret)

{

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

    u[x]=get_u(u[x],ret);

    ret+=dlt[x];

    dlt[x]=ret;

    return u[x];

}



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

{

    int rx=0,ry=0;

    int a=get_u(x,rx),b=get_u(y,ry);

    if (a==b) return (dlt[y]-dlt[x]==d);

    if (link[a]<link[b]) swap(a,b),swap(x,y),d=-d;

    u[b]=a;

    link[a]+=(link[a]==link[b]);

    dlt[b]=dlt[x]-dlt[y]+d;

    return 1;

}



int main()

{

    for (; scanf("%d%d",&N,&M)!=EOF; )

    {

        bool flag=1;

        For(i,1,N) u[i]=i,link[i]=0,dlt[i]=0;

        For(i,1,M)

        {

            int x,y,d;

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

            if (flag) flag=check(x,y,d);

        }

        if (flag)

            printf("Yes\n");

        else

            printf("No\n");

    }

    return 0;

}


// Fastest known solution for this problem:
// Original C++ solution (slower):
#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;

}

// Optimized solution to the same problem (faster):
#include <stdio.h>

#include <string.h>

#include <stdlib.h>

#include <math.h>

#include <time.h>

#include <iostream>

#include <algorithm>

#include <string>

#include <set>

#include <map>

#include <queue>

#include <stack>

#include <bitset>

#include <vector>

using namespace std;



#define bll long long

#define dou double

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

#define Rof(i,a,b) for (int i=(a),_##i=(b); i>=_##i; --i)

#define Mem(a,b) memset(a,b,sizeof(a))

#define Cpy(a,b) memcpy(a,b,sizeof(b))



const int maxn=1e5+100;

int N,M,u[maxn],link[maxn];

int dlt[maxn];



int get_u(int x,int &ret)

{

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

    u[x]=get_u(u[x],ret);

    ret+=dlt[x];

    dlt[x]=ret;

    return u[x];

}



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

{

    int rx=0,ry=0;

    int a=get_u(x,rx),b=get_u(y,ry);

    if (a==b) return (dlt[y]-dlt[x]==d);

    if (link[a]<link[b]) swap(a,b),swap(x,y),d=-d;

    u[b]=a;

    link[a]+=(link[a]==link[b]);

    dlt[b]=dlt[x]-dlt[y]+d;

    return 1;

}



int main()

{

    for (; scanf("%d%d",&N,&M)!=EOF; )

    {

        bool flag=1;

        For(i,1,N) u[i]=i,link[i]=0,dlt[i]=0;

        For(i,1,M)

        {

            int x,y,d;

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

            if (flag) flag=check(x,y,d);

        }

        if (flag)

            printf("Yes\n");

        else

            printf("No\n");

    }

    return 0;

}


// Fastest known solution for this problem:
// Original C++ solution (slower):
#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;

}

// Optimized solution to the same problem (faster):
#include <stdio.h>

#include <string.h>

#include <stdlib.h>

#include <math.h>

#include <time.h>

#include <iostream>

#include <algorithm>

#include <string>

#include <set>

#include <map>

#include <queue>

#include <stack>

#include <bitset>

#include <vector>

using namespace std;



#define bll long long

#define dou double

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

#define Rof(i,a,b) for (int i=(a),_##i=(b); i>=_##i; --i)

#define Mem(a,b) memset(a,b,sizeof(a))

#define Cpy(a,b) memcpy(a,b,sizeof(b))



const int maxn=1e5+100;

int N,M,u[maxn],link[maxn];

int dlt[maxn];



int get_u(int x,int &ret)

{

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

    u[x]=get_u(u[x],ret);

    ret+=dlt[x];

    dlt[x]=ret;

    return u[x];

}



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

{

    int rx=0,ry=0;

    int a=get_u(x,rx),b=get_u(y,ry);

    if (a==b) return (dlt[y]-dlt[x]==d);

    if (link[a]<link[b]) swap(a,b),swap(x,y),d=-d;

    u[b]=a;

    link[a]+=(link[a]==link[b]);

    dlt[b]=dlt[x]-dlt[y]+d;

    return 1;

}



int main()

{

    for (; scanf("%d%d",&N,&M)!=EOF; )

    {

        bool flag=1;

        For(i,1,N) u[i]=i,link[i]=0,dlt[i]=0;

        For(i,1,M)

        {

            int x,y,d;

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

            if (flag) flag=check(x,y,d);

        }

        if (flag)

            printf("Yes\n");

        else

            printf("No\n");

    }

    return 0;

}


// Fastest known solution for this problem: