stablegradients/pie-gem5-pairs huggingface dataset:
// Slower C++ solution:
#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;

}

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

}
// Slower C++ solution:
#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;

}

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

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

    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);  // 辺の重みがすべて0以上のグラフ

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

        }

    }

    

    if(ok) {

        out("Yes");

    }

    else {

        out("No");

    }



    re0;

}
// Slower C++ solution:
#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;

}

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

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

    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);  // 辺の重みがすべて0以上のグラフ

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

        }

    }

    

    if(ok) {

        out("Yes");

    }

    else {

        out("No");

    }



    re0;

}
// Slower C++ solution:
#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;

}

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

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

    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);  // 辺の重みがすべて0以上のグラフ

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

        }

    }

    

    if(ok) {

        out("Yes");

    }

    else {

        out("No");

    }



    re0;

}
// Slower C++ solution:
#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;

}

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

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

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

        }

    }

    

    if(ok) {

        out("Yes");

    }

    else {

        out("No");

    }



    re0;

}
// Slower C++ solution:
#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;

}

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

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

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

        }

    }

    

    if(ok) {

        out("Yes");

    }

    else {

        out("No");

    }



    re0;

}
// Slower C++ solution:
#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;

}

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

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

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

        }

    }

    

    if(ok) {

        out("Yes");

    }

    else {

        out("No");

    }



    re0;

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

#include <vector>

using namespace std;

 

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

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

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

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

 

inline void dfs(int x) //DFS

{

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

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

	{

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

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

		{

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

		}

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

		{

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

			dfs(cur.first);

		}

	}

}

 

int main()

{

	cin>>n>>m; //input

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

	{

		int l,r,d;

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

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

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

	}

	

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

	

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

	

	return 0; //END

}

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

using namespace std;

const int maxn=1e5+10;

struct data{int to,next,wi;}e[maxn*2];

int head[maxn];

int cnt=0;

int du[maxn];

queue<int> q;

bool vis[maxn];

void ins(int u,int v,int ww)

{

	e[++cnt].to=v;

	e[cnt].next=head[u];

	e[cnt].wi=ww;

	head[u]=cnt;

}

int n,m;

int dis[maxn];

int main()

{

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

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

	{

		int x,y,z;

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

		ins(x,y,z);

		du[y]++;

	}

	for(int i=1;i<=n;i++)dis[i]=1e9+10;

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

	{

		if(du[s]==0)

		{

			dis[s]=0;

			vis[s]=1;

			q.push(s);

			while(!q.empty())

			{

				int x=q.front();

				q.pop();

				for(int i=head[x];i;i=e[i].next)

				{

					int u=e[i].to;

					if(vis[u]==1&&dis[u]!=dis[x]+e[i].wi&&du[x]!=0)

					{

						puts("No");

						return 0;

					}

					if(vis[u]==0)

					{

						vis[u]=1;

						dis[u]=min(dis[u],dis[x]+e[i].wi);

						q.push(u);

					}

				}

			}

		}

	}

	for(int i=1;i<=n;i++)if(vis[i]==0){puts("No");return 0;}

	puts("Yes");

	return 0;

}