#include <bits/stdc++.h>
using namespace std;
const int N = 1e5 + 5;
vector<pair<int, int> > adj[N];
int sum[N];
bool ok = true, mark[N];
void dfs(int u) {
  mark[u] = 1;
  for (int i = 0; i < adj[u].size(); ++i) {
    pair<int, int> v = adj[u][i];
    if (!mark[v.first]) {
      sum[v.first] = sum[u] + v.second;
      dfs(v.first);
    } else if (sum[v.first] != sum[u] + v.second) {
      ok = 0;
    }
  }
}
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  clock_t begin = clock();
  memset(mark, 0, sizeof(mark));
  memset(sum, 0, sizeof(sum));
  int n, m;
  cin >> n >> m;
  while (m--) {
    int u, v, d;
    cin >> u >> v >> d;
    adj[u].push_back(pair<int, int>(v, d));
    adj[v].push_back(pair<int, int>(u, -d));
  }
  for (int i = 1; i <= n; ++i) {
    if (!mark[i]) dfs(i);
  }
  if (ok)
    cout << "YES" << endl;
  else
    cout << "NO" << endl;
  clock_t end = clock();
  return 0;
}
