#include <bits/stdc++.h>
using namespace std;
int n, m;
vector<pair<int, int> > G[100010];
vector<int> ord;
int vis[100010];
void dfs(int x, int co) {
  ord.push_back(x);
  vis[x] = co;
  for (pair<int, int> i : G[x]) {
    if (!vis[i.first])
      dfs(i.first, co + i.second);
    else {
      if (vis[i.first] != co + i.second) {
        cout << "NO\n";
        exit(0);
      }
    }
  }
}
int main() {
  cin >> n >> m;
  if (m == 0) {
    cout << "YES\n";
    return 0;
  }
  int fx;
  for (int i = 1; i <= m; i++) {
    int l, r, d;
    cin >> l >> r >> d;
    fx = l;
    G[l].push_back(make_pair(r, d));
    G[r].push_back(make_pair(l, -d));
  }
  dfs(fx, 0);
  cout << "YES\n";
  return 0;
}
