#include <bits/stdc++.h>
using namespace std;
const int N = 1e5 + 1;
const int M = 1e9 + 7;
const double eps = 1e-6;
int p[N], w[N];
void find(int x) {
  if (p[x] == x) return;
  find(p[x]);
  w[x] += w[p[x]];
  p[x] = p[p[x]];
}
int main() {
  ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
  int n, m;
  cin >> n >> m;
  for (int i = (1); i <= (n); i++) p[i] = i;
  for (int i = 0; i < (m); i++) {
    int l, r, d;
    cin >> l >> r >> d;
    find(l);
    find(r);
    if (p[l] == p[r]) {
      if (w[l] + d != w[r]) {
        cout << "NO\n";
        return 0;
      }
    } else {
      w[p[r]] = w[l] + d - w[r];
      p[p[r]] = p[l];
    }
  }
  cout << "YES\n";
}
