//const int N = 1e5+5;
//vi adj[N],cost[N];
//string _(){
//    int n,m;
//    cin >> n >> m;
//    DGraph g(n);
//    rep(i,1,m){
//        int u,v,w;
//        cin >> u >> v >> w;
//        g.add_edge(u,v);
//        adj[u].pb(v);
//        cost[u].pb(w);
//    }
//    if(sz(g.scc()) != n)
//        return "No";
//    vi order = g.topsort();
//    reverse(all(order));
//    vi x(n+1);
//    for(int u : order){
//        if(x[u] == 0)
//            x[u] = 1;
//        rep(i,0,sz(adj[u])-1){
//            int v = adj[u][i];
//            int w = cost[u][i];
//            if(x[v] == 0)
//                x[v] = x[u]+w;
//            if(x[v] != x[u]+w){
//                return "No";
//            }
//        }
//    }
//    return "Yes";
//}
//
#include <iomanip>
#include <algorithm>
#include <vector>
#include <utility>
#include <iostream>
#include <string>
#define pb push_back
#define REP_INT(i,l,r) for(int i = l; i <= r; ++i)
#define GET_REP_MACRO(_1,_2,_3,_4,NAME,...) NAME
#define rep(...) GET_REP_MACRO(__VA_ARGS__,REP_ANY,REP_INT)(__VA_ARGS__)
#define all(v) (v).begin(), (v).end()
#define sz(v) ll(v.size())
#define T1 template<typename T> static
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef pair<int, int> pii;
typedef vector<pii> vpii;
T1 ostream& operator<<(ostream& stream, const vector<T>& t);
T1 istream& read(T, T, istream& = cin);
struct DGraph{
    int n, m;
    vector<vector<int>> conn;
    vpii edges;
    DGraph(){
        m = -1;
    }
    DGraph(int nsize):DGraph(){
        n = nsize;
        conn.resize(n + 1);
    }
    DGraph(int nsize, int _m):DGraph(nsize){
        m = _m;
    }
    void add_edge(int u, int v){
        conn[u].push_back(v);
        edges.pb({u, v});
    }
    void _topsort_dfs(int pos, vector<int>& result, vector<bool>& explr, vector<vector<int>>& revconn){
        if(explr[pos])
            return;
        explr[pos] = true;
        for(auto next : revconn[pos])
            _topsort_dfs(next, result, explr, revconn);
        result.push_back(pos);
    }
    vector<int> topsort(){
        vector<vector<int>> revconn(n + 1);
        for(int u = 1; u <= n; u++)
            for(auto v : conn[u])
                revconn[v].push_back(u);
        vector<int> result;
        vector<bool> explr(n + 1, false);
        for(int i = 1; i <= n; i++)
            _topsort_dfs(i, result, explr, revconn);
        reverse(result.begin(), result.end());
        return result;
    }
    void dfs(int pos, vector<int>& result, vector<bool>& explr){
        if(explr[pos])
            return;
        explr[pos] = true;
        for(auto next : conn[pos])
            dfs(next, result, explr);
        result.push_back(pos);
    }
    vector<vector<int>> scc(){
        vector<int> order = topsort();
        reverse(order.begin(), order.end());
        vector<bool> explr(n + 1, false);
        vector<vector<int>> results;
        for(auto it = order.rbegin(); it != order.rend(); ++it){
            vector<int> component;
            _topsort_dfs(*it, component, explr, conn);
            sort(component.begin(), component.end());
            if(!component.empty())
                results.push_back(component);
        }
        sort(results.begin(), results.end());
        return results;
    }
};
istream& operator>>(istream& stream, DGraph& g){
    if(g.m == -1){
        stream >> g.n >> g.m;
        g = DGraph(g.n, g.m);
    }
    for(int i = 0; i < g.m; ++i){
        int u, v;
        stream >> u >> v;
        g.add_edge(u, v);
    }
    return stream;
}
ostream& operator<<(ostream& stream, const DGraph &g){
    stream << g.n << ' ' << g.m << '\n';
    for(auto cur : g.edges)
        stream << cur.first << " " << cur.second << '\n';
    return stream;
}
const int N = 1e5+5;
vi adj[N],cost[N];
string _(){
    int n,m;
    cin >> n >> m;
    DGraph g(n);
    rep(i,1,m){
        int u,v,w;
        cin >> u >> v >> w;
        g.add_edge(u,v);
        adj[u].pb(v);
        cost[u].pb(w);
    }
    if(sz(g.scc()) != n)
        return "No";
    vi order = g.topsort();
    reverse(all(order));
    vi x(n+1);
    for(int u : order){
        if(x[u] == 0)
            x[u] = 1;
        rep(i,0,sz(adj[u])-1){
            int v = adj[u][i];
            int w = cost[u][i];
            if(x[v] == 0)
                x[v] = x[u]+w;
            if(x[v] != x[u]+w){
                return "No";
            }
        }
    }
    return "Yes";
}
int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    cout << fixed << setprecision(15);
        cout << _() << '\n';
}


Measured memory_bytes: 25972