#include <bits/stdc++.h>
using namespace std;
template <typename T1, typename T2>
using P = pair<T1, T2>;
template <typename T>
using V = vector<T>;
struct edge {
  long long int from, to, cost, rev;
  bool used;
};
bool operator<(const edge& edge1, const edge& edge2) {
  return edge1.cost < edge2.cost;
};
const long long int INF = 1e18;
const long long int MOD = 1e9 + 7;
template <typename T>
ostream& operator<<(ostream& s, const V<T>& v) {
  s << "[";
  for (long long int i = 0; i < v.size(); i++) {
    s << v[i];
    if (i < v.size() - 1) s << " ";
  }
  s << "]";
  return s;
}
template <typename T1, typename T2>
ostream& operator<<(ostream& s, const P<T1, T2>& p) {
  s << "(" << p.first << "," << p.second << ")";
  return s;
}
void add_edge(V<V<edge>>& G, long long int l, long long int r,
              long long int d) {
  G[l].push_back((edge){l, r, d, (long long int)((G[r]).size()), false});
  G[r].push_back((edge){r, l, -d, (long long int)((G[l]).size()) - 1, false});
}
bool dfs(vector<vector<edge>>& G, V<long long int>& d, long long int s) {
  if (d[s] != INF) return true;
  stack<long long int> st;
  st.push(s);
  d[s] = 0;
  while (!st.empty()) {
    long long int i = st.top();
    st.pop();
    for (long long int j = 0; j < G[i].size(); j++) {
      edge e = G[i][j];
      if (e.used) continue;
      e.used = true;
      G[e.to][e.rev].used = true;
      if (d[e.to] == INF) {
        d[e.to] = d[i] + e.cost;
      } else {
        if (d[e.to] != d[i] + e.cost) return false;
      }
      st.push(e.to);
    }
  }
  return true;
}
signed main() {
  long long int N, M;
  cin >> N >> M;
  V<long long int> L(M), R(M), D(M);
  for (long long int i = (0); i < (M); ++i) {
    cin >> L[i] >> R[i] >> D[i];
    L[i]--;
    R[i]--;
  }
  V<V<edge>> G(N);
  for (long long int i = (0); i < (M); ++i) {
    add_edge(G, L[i], R[i], D[i]);
  }
  V<long long int> d(N, INF);
  bool ans = true;
  for (long long int i = (0); i < (N); ++i) {
    if (!dfs(G, d, i)) {
      ans = false;
    }
  }
  cout << (ans ? "YES" : "NO") << endl;
  return 0;
}
