#include <bits/stdc++.h>
using namespace std;
const long long MOD = 1e9 + 7;
const long double PI = 3.141592653589793238462643383279502884197;
priority_queue<int, vector<int>, greater<int> > pq;
vector<pair<int, int> > v[100000];
int dist[100000];
void go(int o, int val) {
  if (dist[o] != -1) {
    if (dist[o] != val) {
      printf("NO\n");
      exit(0);
    } else
      return;
  } else
    dist[o] = val;
  for (int i = 0; i < (int)(v[o]).size(); i++)
    go(v[o][i].second, val + v[o][i].first);
}
int main() {
  memset(dist, -1, sizeof(dist));
  int n, m;
  scanf("%d %d", &n, &m);
  int a, b, c;
  while (m--) {
    scanf("%d %d %d", &a, &b, &c);
    a--;
    b--;
    v[a].push_back({c, b});
    v[b].push_back({-c, a});
  }
  for (int i = 0; i < n; i++)
    if (dist[i] == -1) go(i, 1000000000);
  printf("YES");
}
