#include <bits/stdc++.h>
using namespace std;
const int N = 1e5 + 10;
int n, m;
struct D {
  int x, y, v;
} a[N];
int fa[N];
struct edge {
  int ed, v, ne;
} e[N << 1];
int he[N], en;
int de[N], f[N][20], g[N][20];
bool cmp(D a, D b) { return a.v < b.v; }
int find(int x) { return x == fa[x] ? x : fa[x] = find(fa[x]); }
void ins(int a, int b, int c) {
  e[++en].ed = b;
  e[en].v = c;
  e[en].ne = he[a];
  he[a] = en;
}
void dfs(int u, int fa) {
  int i, v;
  de[u] = de[fa] + 1;
  for (i = 1; i <= 18; ++i) {
    f[u][i] = f[f[u][i - 1]][i - 1];
    g[u][i] = g[f[u][i - 1]][i - 1] + g[u][i - 1];
  }
  for (i = he[u]; i; i = e[i].ne)
    if (e[i].ed != fa) {
      v = e[i].ed;
      f[v][0] = u;
      g[v][0] = e[i].v;
      dfs(v, u);
    }
}
int lca(int x, int y) {
  if (de[x] < de[y]) swap(x, y);
  int t = 0, i;
  for (i = 18; i >= 0; --i)
    if (de[f[x][i]] >= de[y]) t += g[x][i], x = f[x][i];
  if (x == y) return t;
  for (i = 18; i >= 0; --i)
    if (f[x][i] != f[y][i]) {
      t += g[x][i] + g[y][i];
      x = f[x][i];
      y = g[y][i];
    }
  return t;
}
bool solve() {
  int i;
  for (i = 1; i <= n; ++i)
    if (lca(a[i].x, a[i].y) != a[i].v) return 0;
  return 1;
}
int main() {
  int i, x, y;
  scanf("%d%d", &n, &m);
  for (i = 1; i <= m; ++i) scanf("%d%d%d", &a[i].x, &a[i].y, &a[i].v);
  sort(a + 1, a + m + 1, cmp);
  for (i = 1; i <= n; ++i) fa[i] = i;
  for (i = 1; i <= m; ++i) {
    x = find(a[i].x);
    y = find(a[i].y);
    if (x != y) {
      fa[x] = y;
      ins(a[i].x, a[i].y, a[i].v);
      ins(a[i].y, a[i].x, a[i].v);
    }
  }
  for (i = 1; i <= n; ++i)
    if (!de[i]) dfs(i, 0);
  if (solve())
    puts("Yes");
  else
    puts("No");
  return 0;
}
