#include <bits/stdc++.h>
using namespace std;
const int M = 400100, N = 200100;
int to[M], c[M], fi[N], ne[M], la[N], f[19][N], g[19][N], x[M], y[M], z[M],
    fa[N];
int n, m, tot, dep[N];
void Add(int x, int y, int z) {
  to[++tot] = y;
  c[tot] = z;
  !fi[x] ? fi[x] = tot : ne[la[x]] = tot;
  la[x] = tot;
}
int Ask(int x) { return x == fa[x] ? x : fa[x] = Ask(fa[x]); }
void Dfs(int x, int ac) {
  dep[x] = dep[ac] + 1;
  for (int i = 1; i < 19; i++)
    f[i][x] = f[i - 1][f[i - 1][x]],
    g[i][x] = g[i - 1][f[i - 1][x]] + g[i - 1][x];
  for (int i = fi[x]; i; i = ne[i]) {
    int v = to[i];
    if (v == ac) continue;
    f[0][v] = x;
    g[0][v] = c[i];
    Dfs(v, x);
  }
}
int Dis(int x, int y) {
  if (dep[x] < dep[y]) swap(x, y);
  int ans = 0;
  for (int i = 18; i >= 0; i--)
    if (dep[f[i][x]] >= dep[y]) ans += g[i][x], x = f[i][x];
  if (x == y) return ans;
  for (int i = 18; i >= 0; i--)
    if (f[i][x] != f[i][y]) ans += g[i][x] + g[i][y], x = f[i][x], y = f[i][y];
  return ans + g[0][x] + g[0][y];
}
int main(void) {
  scanf("%d%d", &n, &m);
  for (int i = 1; i <= n; i++) fa[i] = i;
  int root = n + 1;
  for (int i = 1; i <= m; i++) {
    scanf("%d%d%d", &x[i], &y[i], &z[i]);
    root = min(root, min(x[i], y[i]));
    int fx = Ask(x[i]), fy = Ask(y[i]);
    if (fx != fy) {
      fa[fx] = fy;
      Add(x[i], y[i], z[i]);
      Add(y[i], x[i], z[i]);
    }
  }
  Dfs(root, 0);
  for (int i = 1; i <= m; i++) {
    if (Dis(x[i], y[i]) != z[i]) {
      puts("No");
      return 0;
    }
  }
  puts("Yes");
}
