// 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.8294967769283375x):
#include <bits/stdc++.h>

using namespace std;

int main(){

  int N, M;

  cin >> N >> M;

  vector<vector<pair<int, int>>> E(N);

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

    int L, R, D;

    cin >> L >> R >> D;

    L--;

    R--;

    E[L].push_back(make_pair(D, R));

    E[R].push_back(make_pair(-D, L));

  }

  vector<int> d(N);

  vector<int> comp(N, -1);

  bool ok = true;

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

    if (comp[i] == -1){

      comp[i] = i;

      d[i] = 0;

      queue<int> Q;

      Q.push(i);

      while (!Q.empty()){

        int v = Q.front();

        Q.pop();

        for (auto P : E[v]){

          int dist = P.first;

          int w = P.second;

          if (comp[w] != -1){

            if (d[w] != d[v] + dist){

              ok = false;

            }

          } else {

            comp[w] = i;

            d[w] = d[v] + dist;

            Q.push(w);

          }

        }

      }

    }

  }

  if (ok){

    cout << "Yes" << endl;

  } else {

    cout << "No" << endl;

  }

}