#include <bits/stdc++.h>
using namespace std;
const int maxn = 1e5 + 10, inf = 1e9;
vector<pair<int, int>> G[maxn], g[maxn];
int v[maxn], p[maxn], d[maxn];
struct djset {
  int p[maxn];
  void init() {
    for (int i = 0; i < maxn; ++i) p[i] = i;
  }
  int find(int n) { return p[n] == n ? n : p[n] = find(p[n]); }
  void merge(int n, int m) { p[find(n)] = find(m); }
} djs;
bool dfs(int now, int fa) {
  v[now] = 1;
  p[now] = fa;
  bool ret = false;
  for (auto u : g[now]) {
    if (v[u.first] == -1)
      ret |= dfs(u.first, now);
    else if (v[u.first] == 1)
      ret = true;
    else
      p[u.first] = now;
  }
  v[now] = 0;
  return ret;
}
int dfs2(int now, int dist) {
  v[now] = 1;
  d[now] = dist;
  int ret = dist;
  for (auto u : g[now]) {
    if (v[u.first] == -1)
      ret = max(ret, dfs2(u.first, dist + u.second));
    else if (v[u.first] == 0 && d[u.first] != dist + u.second) {
      cout << "No" << endl;
      exit(0);
    }
  }
  v[now] = 0;
  return ret;
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  int n, m;
  cin >> n >> m;
  djs.init();
  while (m--) {
    int l, r, d;
    cin >> l >> r >> d;
    if (d == 0) djs.merge(l, r);
    G[l].emplace_back(r, d);
  }
  fill(v, v + maxn, -1);
  for (int i = 1; i <= n; ++i) {
    for (auto j : G[i])
      g[djs.find(i)].emplace_back(djs.find(j.first), j.second);
  }
  for (int i = 1; i <= n; ++i) {
  }
  for (int i = 1; i <= n; ++i)
    if (v[i] == -1) {
      if (dfs(i, -1)) return cout << "No" << endl, 0;
    }
  fill(v, v + maxn, -1);
  for (int i = 1; i <= n; ++i)
    if (v[i] == -1 && p[i] == -1) {
      if (dfs2(i, 0) > inf) return cout << "No" << endl, 0;
    }
  cout << "Yes" << endl;
  return 0;
}
