#include <bits/stdc++.h>
using namespace std;
long long n, m, x[200005], ob[200005];
vector<pair<long long, long long>> adj[200005];
void dfs(long long a) {
  ob[a] = 1;
  for (auto u : adj[a]) {
    if (!ob[u.first]) {
      x[u.first] = x[a] + u.second;
      dfs(u.first);
    }
  }
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  cin >> n >> m;
  for (long long i = 1; i <= m; i++) {
    long long x, y, w;
    cin >> x >> y >> w;
    adj[x].push_back({y, w});
    adj[y].push_back({x, -w});
  }
  for (long long i = 1; i <= n; i++)
    if (!ob[i]) {
      x[i] = 0;
      dfs(i);
    }
  long long ind = 0;
  for (long long i = 1; i <= n; i++)
    for (auto u : adj[i])
      if (x[u.first] - x[i] != u.second) {
        ind = 1;
        break;
      }
  if (!ind)
    cout << "YES" << endl;
  else
    cout << "NO" << endl;
  return 0;
}
