#include <bits/stdc++.h>
using namespace std;
vector<pair<long long, pair<long long, long long> > > v[200005];
long long pos[200005], a[200005], f = 1, n;
void Set(long long m) {
  long long i;
  for (i = 0; i <= m + 5; i++) {
    pos[i] = 123456789987;
  }
}
void dfs(long long i) {
  queue<long long> q;
  q.push(i);
  while (!q.empty()) {
    long long x = q.front();
    q.pop();
    long long sz = v[x].size();
    for (i = 0; i < sz; i++) {
      long long fst = v[x][i].first;
      long long y = v[x][i].second.first;
      long long d = v[x][i].second.second;
      if (pos[x] != 123456789987 && pos[y] != 123456789987) {
        if (fst == 1) {
          if (pos[x] + d != pos[y]) {
            f = 0;
          }
        } else {
          if (pos[x] - d != pos[y]) {
            f = 0;
          }
        }
      } else {
        if (fst == 1) {
          pos[y] = pos[x] + d;
        } else {
          pos[y] = pos[x] - d;
        }
        q.push(y);
      }
    }
  }
}
int main() {
  long long i, j, k, m, x, y, z;
  cin >> n >> m;
  Set(m);
  for (i = 0; i < m; i++) {
    cin >> x >> y >> z;
    a[x]++;
    a[y]++;
    v[x].push_back(make_pair(1, make_pair(y, z)));
    v[y].push_back(make_pair(2, make_pair(x, z)));
  }
  for (i = 1; i <= n; i++) {
    if (a[i] > 0 && pos[i] == 123456789987) {
      pos[i] = 1;
      dfs(i);
    }
  }
  if (f == 1) {
    cout << "YES" << endl;
  } else {
    cout << "NO" << endl;
  }
  return 0;
}
