#include <bits/stdc++.h>
using namespace std;
struct kraw {
  int a, c;
};
int main() {
  ios_base::sync_with_stdio(0);
  int n, m;
  cin >> n >> m;
  vector<vector<kraw> > G(n);
  for (int i = 0; i < m; ++i) {
    int a, b, c;
    cin >> a >> b >> c;
    --a;
    --b;
    G[a].push_back({b, c});
    G[b].push_back({a, c});
  }
  vector<bool> odw(n, false);
  stack<int> S;
  vector<int> odl(n, 0);
  for (int i = 0; i < n; ++i) {
    if (!odw[i]) {
      odw[i] = true;
      S.push(i);
      vector<int> wie;
      while (!S.empty()) {
        int akt = S.top();
        S.pop();
        wie.push_back(akt);
        for (int j = 0; j < G[akt].size(); ++j) {
          if (!odw[G[akt][j].a]) {
            odw[G[akt][j].a] = true;
            odl[G[akt][j].a] = odl[akt] + G[akt][j].c;
            S.push(G[akt][j].a);
          }
        }
      }
      for (int j = 0; j < wie.size(); ++j) {
        int a = wie[j];
        for (int k = 0; k < G[a].size(); ++k) {
          int b = G[a][k].a, c = G[a][k].c;
          if (odl[b] > odl[a]) {
            if (odl[b] - odl[a] != c) {
              cout << "No";
              return 0;
            }
          } else {
            if (odl[a] - odl[b] != c) {
              cout << "No";
              return 0;
            }
          }
        }
      }
      wie.clear();
    }
  }
  cout << "Yes";
  return 0;
}
