#include <bits/stdc++.h>
using namespace std;
using lli = long long int;
vector<int> v[100005];
lli dp[100005] = {};
struct ufind {
  vector<int> par;
  vector<int> rank;
  vector<int> count;
  ufind(int n) {
    par.resize(n);
    rank.resize(n);
    count.resize(n);
    for (lli i = 0; i < (n); i++) {
      par[i] = i;
      rank[i] = 0;
      count[i] = 1;
    }
  }
  int find(int x) {
    if (par[x] == x) {
      return x;
    } else {
      return par[x] = find(par[x]);
    }
  }
  void unite(int x, int y) {
    x = find(x);
    y = find(y);
    if (x == y) return;
    if (rank[x] < rank[y]) {
      par[x] = y;
    } else {
      par[y] = x;
      if (rank[x] == rank[y]) rank[x]++;
    }
  }
  bool same(int x, int y) { return find(x) == find(y); }
};
vector<int> e[100005];
class Scc {
 public:
  vector<int> e[100010];
  vector<int> re[100010];
  vector<int> vs;
  bool used[100010];
  int cmp[100010];
  int v;
  Scc(){};
  Scc(int v) : v(v) {}
  void add_edge(int from, int to) {
    e[from].push_back(to);
    re[to].push_back(from);
  }
  void dfs(int v) {
    used[v] = true;
    for (lli i = 0; i < (e[v].size()); i++)
      if (!used[e[v][i]]) dfs(e[v][i]);
    vs.push_back(v);
  }
  void rdfs(int v, int k) {
    used[v] = true;
    cmp[v] = k;
    for (lli i = 0; i < (re[v].size()); i++)
      if (!used[re[v][i]]) rdfs(re[v][i], k);
  }
  int scc() {
    for (lli i = 0; i < (100010); i++) used[i] = false;
    vs.clear();
    for (lli i = 0; i < (v); i++)
      if (!used[i]) dfs(i);
    int k = 0;
    for (lli i = 0; i < (100010); i++) used[i] = false;
    for (lli i = (vs.size()) - 1; i >= 0; i--)
      if (!used[vs[i]]) rdfs(vs[i], k++);
    return k;
  }
};
int main() {
  int n, m;
  cin >> n >> m;
  Scc s(n);
  map<int, map<int, lli>> di;
  int l[100005], r[100005], d[100005];
  for (lli i = 0; i < (m); i++) {
    cin >> l[i] >> r[i] >> d[i];
    l[i]--, r[i]--;
    s.add_edge(l[i], r[i]);
    di[l[i]][r[i]] = d[i];
  }
  int k = s.scc();
  for (lli i = 0; i < (n); i++) {
    v[s.cmp[i]].push_back(i);
    for (auto ss : di[i]) {
      if (s.cmp[i] == s.cmp[ss.first]) {
        if (ss.second != 0) {
          cout << "No" << endl;
          return 0;
        }
      }
    }
  }
  for (lli i = 0; i < (k); i++) {
    for (auto ss : v[i]) {
      for (auto sss : di[ss]) {
        int nxt = s.cmp[sss.first];
        int dist = dp[s.cmp[sss.first]];
        if (dist == 0) {
          dp[s.cmp[sss.first]] = dp[i] + sss.second;
        } else if (dp[s.cmp[sss.first]] != dp[i] + sss.second) {
          cout << "No" << endl;
          return 0;
        }
      }
    }
  }
  cout << "Yes" << endl;
}
