#include <bits/stdc++.h>
int dx[] = {0, 0, -1, 1};
int dy[] = {1, -1, 0, 0};
using namespace std;
int main() {
  int n, m;
  scanf("%d %d", &n, &m);
  vector<pair<int, pair<int, int>>> v;
  for (int i = 0; i < m; ++i) {
    int a, b, c;
    scanf("%d %d %d", &a, &b, &c);
    a--;
    b--;
    v.push_back(make_pair(a, make_pair(b, c)));
  }
  sort(v.begin(), v.end());
  bool used[200000] = {};
  int dis[200000] = {};
  used[0] = true;
  vector<int> notused;
  for (int i = 0; i < m; ++i) {
    int a = v[i].first, b = v[i].second.first, c = v[i].second.second;
    if (used[a]) {
      dis[b] = dis[a] + c;
      used[b] = true;
    } else if (used[b]) {
      dis[a] = dis[b] - c;
      used[a] = true;
    } else {
      notused.push_back(i);
    }
  }
  for (int i = 0; i < (int)notused.size(); ++i) {
    int a = v[notused[i]].first, b = v[notused[i]].second.first,
        c = v[notused[i]].second.second;
    if (used[a]) {
      dis[b] = dis[a] + c;
      used[b] = true;
    } else if (used[b]) {
      dis[a] = dis[b] - c;
      used[a] = true;
    } else {
      dis[b] = dis[a] + c;
      used[a] = true;
      used[b] = true;
    }
  }
  for (int i = 0; i < m; ++i) {
    int a = v[i].first, b = v[i].second.first, c = v[i].second.second;
    if (dis[a] + c != dis[b]) {
      printf("NO\n");
      return 0;
    }
  }
  printf("YES\n");
  return 0;
}
