#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using vi = vector<long long>;
using pii = pair<long long, long long>;
const signed INF_ = 1001001001;
const ll INF = 1001001001001001001LL;
const long long DX[9] = {0, 1, 0, -1, 1, 1, -1, -1, 0},
                DY[9] = {-1, 0, 1, 0, -1, 1, 1, -1, 0};
template <class T>
ostream &operator<<(ostream &os, const vector<T> &v) {
  for (auto i = (begin(v)); i != (end(v)); ++i)
    os << *i << (i == end(v) - 1 ? "" : " ");
  return os;
}
template <class T>
istream &operator>>(istream &is, vector<T> &v) {
  for (auto i = (begin(v)); i != (end(v)); ++i) is >> *i;
  return is;
}
template <class T, class U>
istream &operator>>(istream &is, pair<T, U> &p) {
  is >> p.first >> p.second;
  return is;
}
template <class T>
bool chmax(T &a, const T &b) {
  if (a < b) {
    a = b;
    return 1;
  }
  return 0;
}
template <class T>
bool chmin(T &a, const T &b) {
  if (a > b) {
    a = b;
    return 1;
  }
  return 0;
}
template <class T>
using heap = priority_queue<T, vector<T>, greater<T>>;
struct {
  template <class T>
  operator T() {
    T x;
    cin >> x;
    return x;
  }
} IN;
struct before_main_function {
  before_main_function() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout << setprecision(15) << fixed;
  }
} before_main_function;
bool check(long long N, vector<vector<pii>> &g, set<long long> &vs) {
  if (N <= 1) return true;
  vector<long long> deg(((long long)g.size()), 0);
  for (long long i = 0, ilen = (long long)(((long long)g.size())); i < ilen;
       ++i) {
    for (auto &e : g[i]) deg[e.first]++;
  }
  stack<long long> st;
  for (auto &v : vs)
    if (deg[v] == 0) st.push(v);
  vector<long long> tpsort;
  while (!st.empty()) {
    long long v = st.top();
    st.pop();
    tpsort.push_back(v);
    for (auto &e : g[v]) {
      deg[e.first]--;
      if (deg[e.first] == 0) {
        st.push(e.first);
      }
    }
  }
  if (((long long)tpsort.size()) < N) {
    return false;
  }
  bool ng = false;
  vector<long long> dist(N, INF);
  function<void(long long)> dfs = [&](long long v) {
    for (auto &e : g[v]) {
      if (dist[e.first] != INF && dist[v] + e.second != dist[e.first]) {
        ng = 1;
        return;
      }
      dist[e.first] = dist[v] + e.second;
      dfs(e.first);
    }
  };
  dist[tpsort[0]] = 0;
  dfs(tpsort[0]);
  if (ng) return false;
  return true;
}
bool solve() {
  long long N, M;
  cin >> N >> M;
  vector<vector<pii>> g(N);
  vector<vector<long long>> tmp(N);
  for (long long i = 0, ilen = (long long)(M); i < ilen; ++i) {
    long long L, R, D;
    cin >> L >> R >> D;
    L--, R--;
    g[L].push_back({R, D});
    tmp[L].push_back(R);
    tmp[R].push_back(L);
  }
  vector<long long> vis(N, false);
  function<void(long long, set<long long> &)> dfs = [&](long long v,
                                                        set<long long> &vs) {
    vis[v] = 1;
    vs.insert(v);
    for (auto &w : tmp[v]) {
      if (!vis[w]) {
        dfs(w, vs);
      }
    }
  };
  for (long long i = 0, ilen = (long long)(N); i < ilen; ++i) {
    if (!vis[i]) {
      set<long long> vs;
      dfs(i, vs);
      bool res = check(((long long)vs.size()), g, vs);
      if (!res) return false;
    }
  }
  return true;
}
signed main() {
  cout << (solve() ? "Yes" : "No") << "\n";
  return 0;
}
