#include <bits/stdc++.h>
const int N = 400005;
struct edge {
  int y, w, next;
} e[N];
int fa[N][21], acs[N], dep[N], d[N], h[N];
int ls[N], size[N], edCnt;
int read() {
  int x = 0, v = 1;
  char ch = getchar();
  for (; ch < '0' || ch > '9'; v = (ch == '-') ? (-1) : (v), ch = getchar())
    ;
  for (; ch <= '9' && ch >= '0'; x = x * 10 + ch - '0', ch = getchar())
    ;
  return x * v;
}
void add_edge(int x, int y, int w) {
  e[++edCnt] = (edge){y, w, ls[x]};
  ls[x] = edCnt;
  e[++edCnt] = (edge){x, w, ls[y]};
  ls[y] = edCnt;
}
int get_lca(int x, int y) {
  if (dep[x] < dep[y]) std::swap(x, y);
  for (int i = 20; i >= 0; --i)
    if (dep[fa[x][i]] >= dep[y]) x = fa[x][i];
  if (x == y) return x;
  for (int i = 20; i >= 0; --i)
    if (fa[x][i] != fa[y][i]) x = fa[x][i], y = fa[y][i];
  return fa[x][0];
}
int get_dis(int x, int y) { return d[x] + d[y] - d[get_lca(x, y)] * 2; }
int find(int x) { return !acs[x] ? (x) : (acs[x] = find(acs[x])); }
void dfs(int x) {
  for (int i = 1; i <= 20; ++i) fa[x][i] = fa[fa[x][i - 1]][i - 1];
  for (int i = ls[x]; i; i = e[i].next) {
    if (e[i].y == fa[x][0]) continue;
    fa[e[i].y][0] = x;
    dep[e[i].y] = dep[x] + 1;
    d[e[i].y] = d[x] + e[i].w;
    dfs(e[i].y);
  }
}
int main(void) {
  int n = read(), m = read();
  for (int i = 1; i <= n; ++i) size[i] = dep[i] = 1;
  for (; m--;) {
    int x = read(), y = read(), k = read();
    int fx = find(x), fy = find(y);
    if (fx == fy && get_dis(x, y) != k) return 0 & puts("No");
    if (size[fx] > size[fy]) {
      std::swap(x, y);
      std::swap(fx, fy);
    }
    fa[x][0] = y;
    dep[x] = dep[y] + 1;
    d[x] = d[y] + k;
    dfs(x);
    acs[fx] = fy;
    size[fy] += size[fx];
    add_edge(y, x, k);
  }
  return 0 & puts("Yes");
}
