#include <bits/stdc++.h>
using namespace std;
const int maxn = 1e5 + 10, inf = 1e9;
vector<pair<int, int>> G[maxn];
int v[maxn], p[maxn], d[maxn];
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;
  while (m--) {
    int l, r, d;
    cin >> l >> r >> d;
    G[l].emplace_back(r, d);
    G[r].emplace_back(l, d);
  }
  fill_n(v, n + 1, -1);
  for (int i = 1; i <= n; ++i)
    if (v[i] == -1) {
      if (!dfs(i, -1)) return cout << "No" << endl, 0;
    }
  fill_n(v, n + 1, -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;
}
