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

#define int long long

#define x first

#define y second





using namespace std;



vector<int> color(1e5 + 1);



int get_color(int x){

    //cout << x << endl;

    if(x == color[x]){

        return x;

    }

    return color[x] =  get_color(color[x]);

}



void update(int x, int y){

    if(get_color(x) != get_color(y)){

        //cout << x << ' ' << y << endl;

        color[get_color(x)] = get_color(y);

    }

}



bool comp(vector<int> x, vector<int> y){

    return min(x[0], x[1]) < min(y[0], y[1]);

}



void check(vector<int> sv, vector<vector<int> > og){

    int n = sv.size();

    int mi = 0, ma = 0;

    if(og.size() == 0){

        return;

    }

    map<int, int> c;

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

        c[sv[i]] =i;

    }

    vector<int> used(n,  0), x(n, 0);

    used[0] = 1;

    vector<vector<vector<int> > > dop(n);

    for(auto it : og){

        dop[c[it[0]]].push_back(it);

        dop[c[it[1]]].push_back(it);

    }

    queue<vector<int> > d;

    for(auto it : dop[0]){

        d.push(it);

    }

    while(!d.empty()){

        auto it = d.front();

        d.pop();

        int t = c[it[0]], t1 = c[it[1]];

        if(used[t] == 0){

            swap(t, t1);

            it[2] = -it[2];

        }

        if(used[t1] == 0){

            for(auto it1 : dop[t1]){

                if(it1 != it)

                d.push(it1);

            }

        }

        if(used[t1] == 1 && x[t1] != x[t] + it[2]){

            cout << "No";

            exit(0);

        }

        if(used[t] == 0){

            exit(-1);

        }

        used[t1] = 1;

        x[t1] = x[t] + it[2];

    }

    for(auto it : x){

        mi = min(it, mi);

        ma = max(it, ma);

    }

    if(ma - mi > 1e9){

        cout << "No";

        exit(0);

    }

}



void solve(){

    int n, q;

    cin >> n >> q;

    vector<vector<int> > e(q);

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

        color[i] = i;

    }

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

        int l, r, d;

        cin >> l >> r >> d;

        e[i] = {--l, --r, d};

        update(l, r);

        //cout << color[0] << ' ' << color[1] <<' ' << color[2] << endl;

    }

    vector<vector<int> > sv(n);

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

        sv[get_color(i)].push_back(i);

    }

   vector<vector<vector<int> > > og(n);

   for(auto it : e){

        og[get_color(it[0])].push_back(it);

   }

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

    sort(og[i].begin(), og[i].end(), comp);

    //out << "rhgingk" <<  endl;

    check(sv[i], og[i]);

   }

   cout << "Yes";

}





signed main() {

    ios::sync_with_stdio(0);

    cin.tie(0);

    int test = 1;

    //freopen("output.txt", "w", stdout);

    //freopen("input.txt", "r", stdin);

    //

    //cin >> test;

    while(test--){

        solve();

    }

}


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



using namespace std;



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

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

#define _GLIBCXX_DEBUG



using ll = long long;

using vi = vector<int>;

using vll = vector<ll>;

using vd = vector<double>;

using vvi = vector<vi>;

using vvll = vector<vll>;

using vvd = vector<vd>;

using vvvi = vector<vvi>;

using vvvll = vector<vvll>;

using vvvd = vector<vvd>;



const double pi=3.141592653589793;

const ll MOD=1e9+7;



template<class Abel> struct UnionFind {

    vector<int> par;

    vector<int> rank;

    vector<Abel> diff_weight;



    UnionFind(int n = 1, Abel SUM_UNITY = 0) {

        init(n, SUM_UNITY);

    }



    void init(int n = 1, Abel SUM_UNITY = 0) {

        par.resize(n); rank.resize(n); diff_weight.resize(n);

        for (int i = 0; i < n; ++i) par[i] = i, rank[i] = 0, diff_weight[i] = SUM_UNITY;

    }



    int root(int x) {

        if (par[x] == x) {

            return x;

        }

        else {

            int r = root(par[x]);

            diff_weight[x] += diff_weight[par[x]];

            return par[x] = r;

        }

    }



    Abel weight(int x) {

        root(x);

        return diff_weight[x];

    }



    bool issame(int x, int y) {

        return root(x) == root(y);

    }



    bool merge(int x, int y, Abel w) {

        w += weight(x); w -= weight(y);

        x = root(x); y = root(y);

        if (x == y) return false;

        if (rank[x] < rank[y]) swap(x, y), w = -w;

        if (rank[x] == rank[y]) ++rank[x];

        par[y] = x;

        diff_weight[y] = w;

        return true;

    }



    Abel diff(int x, int y) {

        return weight(y) - weight(x);

    }

};





int main() {

    ll n,m;

    cin>>n>>m;

    UnionFind<int> uf(n+1);

    rep(i,m){

        ll l,r,d;

        cin>>l>>r>>d;

        if (uf.root(r)!=uf.root(l)){

            uf.merge(l,r,d);

        }

        else{

            if (uf.diff(l,r)!=d){

                cout<<"No"<<endl;

                return 0;

            }

        }

    }

    cout<<"Yes"<<endl;



    return 0;

}

//...