#include <bits/stdc++.h>
using namespace std;
const int N = 2e5 + 10, inf = 1e9;
struct node {
  int x, y, v;
} e[N];
int f[N], d[N];
int nt[N], to[N], w[N], head[N], top = 0, cnt = 0;
void add(int x, int y, int z) {
  d[y]++;
  to[++cnt] = y;
  w[cnt] = z;
  nt[cnt] = head[x];
  head[x] = cnt;
}
int find(int k) { return f[k] == k ? f[k] : f[k] = find(f[k]); }
long long dp[N];
int flg = 0;
int pr[N], dfn[N], low[N], vs[N], st[N], res = 0;
void dfs(int u) {
  vs[u] = 1;
  dfn[u] = low[u] = ++res;
  st[++top] = u;
  for (int i = head[u]; i; i = nt[i]) {
    if (dfn[to[i]]) {
      if (vs[to[i]]) low[u] = min(low[u], dfn[to[i]]);
    } else {
      dfs(to[i]);
      low[u] = min(low[u], low[to[i]]);
    }
  }
  if (low[u] == dfn[u]) {
    int res = 0;
    for (; st[top] != u;) {
      ++res;
      vs[st[top]] = 0;
      top--;
    }
    vs[st[top--]] = 0;
    if (res) flg = 1;
  }
}
void fail() {
  puts("No");
  exit(0);
}
void go(int x) {
  for (int i = head[x]; i; i = nt[i]) {
    if (!pr[to[i]]) {
      pr[to[i]] = pr[x];
      dp[to[i]] = dp[x] + w[i];
      if (dp[to[i]] > inf) dp[to[i]] = inf, flg = 1;
    } else {
      if (pr[to[i]] == pr[x]) {
        if (dp[to[i]] != dp[x] + w[i]) flg = 1;
      } else {
        if (dp[to[i]] < dp[x] + w[i]) {
          pr[to[i]] = pr[x];
          dp[to[i]] = dp[x] + w[i];
        }
      }
    }
    d[to[i]]--;
    if (!d[to[i]]) go(to[i]);
  }
}
int main() {
  int n, m;
  scanf("%d%d", &n, &m);
  for (int i = 1; i <= n; ++i) f[i] = i;
  for (int i = 1; i <= m; ++i) {
    scanf("%d%d%d", &e[i].x, &e[i].y, &e[i].v);
    if (!e[i].v) {
      int fx = find(e[i].x), fy = find(e[i].y);
      f[fx] = fy;
    }
  }
  for (int i = 1; i <= m; ++i) {
    if (e[i].v) {
      add(find(e[i].y), find(e[i].x), e[i].v);
    }
  }
  for (int i = 1; i <= n; ++i) {
    if (!dfn[i]) dfs(i);
  }
  if (flg) fail();
  for (int i = 1; i <= n; ++i) {
    if (!d[i]) {
      pr[i] = i, go(i);
    }
  }
  if (flg) fail();
  puts("Yes");
  return 0;
}
