stablegradients/pie-gem5-pairs huggingface dataset:
// Slower C++ solution:
/*

Problem:People on a Line

Algorithm:"linear" DFS

Status:

*/



#include <iostream>

#include <cstdio>

#include <cmath>

#include <algorithm>

#include <string>

#include <vector>

#include <map>

#include <queue>

#include <deque>

#include <set>

#include <sstream>

#include <utility>

#include <list>

#include <ctime>

#include <memory.h>

#include <stack>

#include <stdio.h>

#include <string.h>



using namespace std;



const int INF=1e9+7;



vector<pair<int,int> > nei[100005];

int pos[100005];

int n,m;

bool used[100005];

bool exist[100005];



void dfs(int x,int cur){

	pos[x]=cur;

	used[x]=true;

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

		if(used[nei[x][i].first]){

			if(pos[nei[x][i].first]-cur!=nei[x][i].second){

				cout<<"No"<<endl;

				exit(0);

			}

		}

		else{

			dfs(nei[x][i].first,cur+nei[x][i].second);

		}

	}

}



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--;

		exist[l]=true;exist[r]=true;

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

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

	}

	

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

		if(!exist[i])continue;

		if(!used[i]){

			dfs(i,0);

		}

	}

	cout<<"Yes"<<endl;

	

	return 0;

}


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

using namespace std;

typedef long long ll;

const int N = 2e5+10;

int f[N], d[N];

int Find(int x) {

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

    int root = Find(f[x]);

    d[x] = d[ f[x] ] + d[x];

    return f[x] = root;

}



int join(int x, int y, int z) {

    int fx = Find(x);

    int fy = Find(y);

    if(fx == fy) return z == d[y] - d[x];

    f[fy] = fx;

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

    return 1;

}



int main() {

    int n, m;

    int ok = 1;

    cin >> n >> m;

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

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

        int x, y, z; cin >> x >> y >> z;

        if(ok) ok = join(x, y, z);

    }

    printf(ok ? "Yes\n" : "No\n");

    return 0;

}
// 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]] = cnt[x] + z - cnt[y];

                fa[fa[y]] = fa[x];

            }

        }

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

    }

}


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

using namespace std;

typedef long long ll;

const int N = 2e5+10;

int f[N], d[N];

int Find(int x) {

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

    int root = Find(f[x]);

    d[x] = d[ f[x] ] + d[x];

    return f[x] = root;

}



int join(int x, int y, int z) {

    int fx = Find(x);

    int fy = Find(y);

    if(fx == fy) return z == d[y] - d[x];

    f[fy] = fx;

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

    return 1;

}



int main() {

    int n, m;

    int ok = 1;

    cin >> n >> m;

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

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

        int x, y, z; cin >> x >> y >> z;

        if(ok) ok = join(x, y, z);

    }

    printf(ok ? "Yes\n" : "No\n");

    return 0;

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

#include <cstdio>

#include <cstring>

#include <vector>

using namespace std;

const int N = 1e5+10;

int n,m;

int dis[N];

bool vis[N];

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

bool dfs(int u){

    vis[u] = 1;

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

    for(it = E[u].begin(); it != E[u].end(); it++){

        int v = (*it).first;

        int d = (*it).second;

        if(!vis[v]){

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

            if(!dfs(v))

                return false;

        }

        else if(dis[u]+d!=dis[v])

            return false;

    }

    return true;

}

int main(){

    cin >> n >> m;

    int u,v,w;

    int i;

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

        cin >> u >> v >> w;

        E[u].push_back(make_pair(v,w));

        E[v].push_back(make_pair(u,-w));

    }

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

        if(!vis[i]){

            if(!dfs(i)){

                cout << "No" << endl;

                return 0;

            }

        }

    }

    cout << "Yes" << endl;

    return 0;

}


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

#include <iostream>

#include <set>

#include <map>

#include <algorithm>

#include <string>

#include <cstring>

//purvikaurraina

using namespace std;

const int maxn = 2e5 + 100;

int f[maxn];

int d[maxn];

int ff(int x){

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

    int a = f[x];

    int b = ff(f[x]);

    d[x] += d[a]; 

    f[x] = b;

    return b;

}

//purvikaurraina

int unit(int x,int y,int z){

    int fx = ff(x);

    int fy = ff(y);

    if (fx == fy){

        return (d[y] - d[x]) == z;

    }

    f[fy] = fx;

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

    return 1;

}

int main(){

    int n,m;

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

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

    int flag = 0;

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

        int x,y,d;

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

        if (!unit(x,y,d))

        {

            flag = 1;

        }

    }

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

    else printf("Yes\n");

}
// Slower C++ solution:
/*

Problem:People on a Line

Algorithm:"linear" DFS

Status:

*/



#include <iostream>

#include <cstdio>

#include <cmath>

#include <algorithm>

#include <string>

#include <vector>

#include <map>

#include <queue>

#include <deque>

#include <set>

#include <sstream>

#include <utility>

#include <list>

#include <ctime>

#include <memory.h>

#include <stack>

#include <stdio.h>

#include <string.h>



using namespace std;



const int INF=1e9+7;



vector<pair<int,int> > nei[100005];

int pos[100005];

int n,m;

bool used[100005];

bool exist[100005];



void dfs(int x,int cur){

	pos[x]=cur;

	used[x]=true;

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

		if(used[nei[x][i].first]){

			if(pos[nei[x][i].first]-cur!=nei[x][i].second){

				cout<<"No"<<endl;

				exit(0);

			}

		}

		else{

			dfs(nei[x][i].first,cur+nei[x][i].second);

		}

	}

}



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--;

		exist[l]=true;exist[r]=true;

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

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

	}

	

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

		if(!exist[i])continue;

		if(!used[i]){

			dfs(i,0);

		}

	}

	cout<<"Yes"<<endl;

	

	return 0;

}


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

#include <iostream>

#include <set>

#include <map>

#include <algorithm>

#include <string>

#include <cstring>

//purvikaurraina

using namespace std;

const int maxn = 2e5 + 100;

int f[maxn];

int d[maxn];

int ff(int x){

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

    int a = f[x];

    int b = ff(f[x]);

    d[x] += d[a]; 

    f[x] = b;

    return b;

}

//purvikaurraina

int unit(int x,int y,int z){

    int fx = ff(x);

    int fy = ff(y);

    if (fx == fy){

        return (d[y] - d[x]) == z;

    }

    f[fy] = fx;

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

    return 1;

}

int main(){

    int n,m;

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

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

    int flag = 0;

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

        int x,y,d;

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

        if (!unit(x,y,d))

        {

            flag = 1;

        }

    }

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

    else printf("Yes\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]] = cnt[x] + z - cnt[y];

                fa[fa[y]] = fa[x];

            }

        }

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

    }

}


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

#include <iostream>

#include <set>

#include <map>

#include <algorithm>

#include <string>

#include <cstring>

//purvikaurraina

using namespace std;

const int maxn = 2e5 + 100;

int f[maxn];

int d[maxn];

int ff(int x){

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

    int a = f[x];

    int b = ff(f[x]);

    d[x] += d[a]; 

    f[x] = b;

    return b;

}

//purvikaurraina

int unit(int x,int y,int z){

    int fx = ff(x);

    int fy = ff(y);

    if (fx == fy){

        return (d[y] - d[x]) == z;

    }

    f[fy] = fx;

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

    return 1;

}

int main(){

    int n,m;

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

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

    int flag = 0;

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

        int x,y,d;

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

        if (!unit(x,y,d))

        {

            flag = 1;

        }

    }

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

    else printf("Yes\n");

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

#define X first

#define Y second

#define pb push_back

#define sz(a) (int)a.size()

#define int long long



using namespace std;



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



vector <vector <int>> v;



int a[100010];

int used[100010];



void dfs(int vv) {

    used[vv] = 1;

    for (auto u : g[vv]) {

        if (used[u.X] == 1)

            continue;

        a[u.X] = a[vv] + u.Y;

        dfs(u.X);

    }

}



signed main() {

    ios_base::sync_with_stdio(0);

    cin.tie(0);

    int n, m;

    cin >> n >> m;

    int l, r, d;

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

        cin >> l >> r >> d;

        l--;

        r--;

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

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

        v.pb({l, r, d});

    }

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

        if (used[i] == 0) {

            dfs(i);

        }

    }

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

        if (a[v[i][1]] - a[v[i][0]] != v[i][2]) {

            cout << "No" << endl;

            exit(0);

        }

    }

    cout << "Yes";

    return 0;

}


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

#include <iostream>

#include <set>

#include <map>

#include <algorithm>

#include <string>

#include <cstring>

//purvikaurraina

using namespace std;

const int maxn = 2e5 + 100;

int f[maxn];

int d[maxn];

int ff(int x){

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

    int a = f[x];

    int b = ff(f[x]);

    d[x] += d[a]; 

    f[x] = b;

    return b;

}

//purvikaurraina

int unit(int x,int y,int z){

    int fx = ff(x);

    int fy = ff(y);

    if (fx == fy){

        return (d[y] - d[x]) == z;

    }

    f[fy] = fx;

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

    return 1;

}

int main(){

    int n,m;

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

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

    int flag = 0;

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

        int x,y,d;

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

        if (!unit(x,y,d))

        {

            flag = 1;

        }

    }

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

    else printf("Yes\n");

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

#include <cstdio>

#include <cstring>

#include <vector>

using namespace std;

const int N = 1e5+10;

int n,m;

int dis[N];

bool vis[N];

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

bool dfs(int u){

    vis[u] = 1;

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

    for(it = E[u].begin(); it != E[u].end(); it++){

        int v = (*it).first;

        int d = (*it).second;

        if(!vis[v]){

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

            if(!dfs(v))

                return false;

        }

        else if(dis[u]+d!=dis[v])

            return false;

    }

    return true;

}

int main(){

    cin >> n >> m;

    int u,v,w;

    int i;

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

        cin >> u >> v >> w;

        E[u].push_back(make_pair(v,w));

        E[v].push_back(make_pair(u,-w));

    }

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

        if(!vis[i]){

            if(!dfs(i)){

                cout << "No" << endl;

                return 0;

            }

        }

    }

    cout << "Yes" << endl;

    return 0;

}


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

#include <cstdio>

#include <algorithm>

#define N 400005

#define inf 0x7fffffff

using namespace std;

 

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

int n, m, num, flag, cnt;

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

bool vis[N];

 

int read()

{

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

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

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

    return x;

}

 

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

{

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

    e[num].to = v;

    e[num].dis = w;

    h[u] = num;

}

 

void dfs(int x)

{

    if(flag) return;

    vis[x] = 1;

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

    {

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

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

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

    }

}

 

int main()

{

    cin >> n >> m;

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

    {

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

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

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

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

    }

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

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

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

        if(!vis[obj[i]])

        {

            flag = 0;

            pos[obj[i]] = 0;

            dfs(obj[i]);

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

        }

    cout << "Yes";

    return 0;

}
// Slower C++ solution:
/*

Problem:People on a Line

Algorithm:"linear" DFS

Status:

*/



#include <iostream>

#include <cstdio>

#include <cmath>

#include <algorithm>

#include <string>

#include <vector>

#include <map>

#include <queue>

#include <deque>

#include <set>

#include <sstream>

#include <utility>

#include <list>

#include <ctime>

#include <memory.h>

#include <stack>

#include <stdio.h>

#include <string.h>



using namespace std;



const int INF=1e9+7;



vector<pair<int,int> > nei[100005];

int pos[100005];

int n,m;

bool used[100005];

bool exist[100005];



void dfs(int x,int cur){

	pos[x]=cur;

	used[x]=true;

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

		if(used[nei[x][i].first]){

			if(pos[nei[x][i].first]-cur!=nei[x][i].second){

				cout<<"No"<<endl;

				exit(0);

			}

		}

		else{

			dfs(nei[x][i].first,cur+nei[x][i].second);

		}

	}

}



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--;

		exist[l]=true;exist[r]=true;

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

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

	}

	

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

		if(!exist[i])continue;

		if(!used[i]){

			dfs(i,0);

		}

	}

	cout<<"Yes"<<endl;

	

	return 0;

}


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

#include <cstdio>

#include <algorithm>

#define N 400005

#define inf 0x7fffffff

using namespace std;

 

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

int n, m, num, flag, cnt;

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

bool vis[N];

 

int read()

{

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

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

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

    return x;

}

 

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

{

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

    e[num].to = v;

    e[num].dis = w;

    h[u] = num;

}

 

void dfs(int x)

{

    if(flag) return;

    vis[x] = 1;

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

    {

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

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

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

    }

}

 

int main()

{

    cin >> n >> m;

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

    {

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

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

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

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

    }

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

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

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

        if(!vis[obj[i]])

        {

            flag = 0;

            pos[obj[i]] = 0;

            dfs(obj[i]);

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

        }

    cout << "Yes";

    return 0;

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

#include <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]] = cnt[x] + z - cnt[y];

                fa[fa[y]] = fa[x];

            }

        }

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

    }

}


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

#include <cstdio>

#include <algorithm>

#define N 400005

#define inf 0x7fffffff

using namespace std;

 

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

int n, m, num, flag, cnt;

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

bool vis[N];

 

int read()

{

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

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

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

    return x;

}

 

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

{

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

    e[num].to = v;

    e[num].dis = w;

    h[u] = num;

}

 

void dfs(int x)

{

    if(flag) return;

    vis[x] = 1;

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

    {

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

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

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

    }

}

 

int main()

{

    cin >> n >> m;

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

    {

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

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

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

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

    }

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

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

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

        if(!vis[obj[i]])

        {

            flag = 0;

            pos[obj[i]] = 0;

            dfs(obj[i]);

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

        }

    cout << "Yes";

    return 0;

}