#include <bits/stdc++.h>
#define MAXN 100001
#define MAXM 200001
using namespace std;
struct edge{
    int nod, c;
    edge(int nod, int c):nod(nod), c(c) {}
};
vector<vector<edge>> G;
char viz[MAXN];
int n, m;
int bfs(int nod, int caut, int cost) {
    //cout << "vizitez nodul " << nod << "cu costul " << cost << " caut " << caut << endl;
    if(nod == caut) {
        //cout << "am gasit cu costul " << cost << endl;
        return cost;
    }
    for(edge i : G[nod]) {
        if(viz[i.nod] == 0) {
            viz[i.nod] = 1;
            return bfs(i.nod, caut, cost + i.c);
        }
    }
    return 0;
}
int main() {
    cin >> n >> m;
    G.resize(n+1);
    for(int i = 0; i < m; ++i) {
        int l, r, d;
        cin >> l >> r >> d;
        memset(viz, 0, MAXN);
        viz[l] = 1;
        //cout << "bfs pt " << l << endl;
        int dg = bfs(l, r, 0);
        //cout << "dg: " << dg << endl;
        //cout << "viz\n";
        
        if(dg != d && dg != 0) {
            cout << "No\n";
            return 0;
        }
        G[l].push_back(edge(r, d));
        //G[r].push_back(edge(l, d));
    }
    cout << "Yes\n";
}
#include <bits/stdc++.h>
#define MAXN 100001
#define MAXM 200001
using namespace std;
struct edge{
    int nod, c;
    edge(int nod, int c):nod(nod), c(c) {}
};
vector<vector<edge>> G;
char viz[MAXN];
int n, m;
int bfs(int nod, int caut, int cost) {
    //cout << "vizitez nodul " << nod << "cu costul " << cost << " caut " << caut << endl;
    if(nod == caut) {
        //cout << "am gasit cu costul " << cost << endl;
        return cost;
    }
    for(edge i : G[nod]) {
        if(viz[i.nod] == 0) {
            viz[i.nod] = 1;
            return bfs(i.nod, caut, cost + i.c);
        }
    }
    return 0;
}
int main() {
    cin >> n >> m;
    G.resize(n+1);
    for(int i = 0; i < m; ++i) {
        int l, r, d;
        cin >> l >> r >> d;
        memset(viz, 0, MAXN);
        viz[l] = 1;
        //cout << "bfs pt " << l << endl;
        int dg = bfs(l, r, 0);
        //cout << "dg: " << dg << endl;
        //cout << "viz\n";
        
        if(dg != d && dg != 0) {
            cout << "No\n";
            return 0;
        }
        //G[l].push_back(edge(r, d));
        G[r].push_back(edge(l, d));
    }
    cout << "Yes\n";
}
