#include <bits/stdc++.h>
using namespace std;
struct edge {
  int to, len;
};
struct graph {
  int n;
  vector<vector<edge>> g;
  vector<bool> used;
  vector<int> pos;
  graph(){};
  graph(int _n) {
    n = _n;
    g.resize(n);
    pos.resize(n, 0);
    used.resize(n, false);
  };
  void add_edge(int a, int b, int c) {
    g[a].push_back(edge({b, c}));
    g[b].push_back(edge({a, -c}));
  }
  void check(int a) {
    used[a] = true;
    for (auto&& w : g[a]) {
      if (used.at(w.to)) {
        if (pos.at(a) + w.len != pos.at(w.to)) {
          cout << "NO" << endl;
          exit(0);
        }
      } else {
        pos.at(w.to) = pos.at(a) + w.len;
        check(w.to);
      }
    }
  }
  void checkAll() {
    for (int i = 0; i < n; i++) {
      if (used[i])
        continue;
      else
        check(i);
    }
    cout << "YES" << endl;
  }
};
int main() {
  int n, m;
  cin >> n >> m;
  graph gr(n);
  for (int i = 0; i < m; i++) {
    int x, y, z;
    cin >> x >> y >> z;
    x--;
    y--;
    gr.add_edge(x, y, z);
  }
  gr.checkAll();
}
