#include <bits/stdc++.h>
using namespace std;
int const maxn = 1e6 + 10;
long long const inf = (long long)1e18;
struct bkn {
  int next, to;
  long long w;
} e[maxn * 2], e2[maxn * 2];
stack<int> st;
int tot = 1, head[maxn], vis[maxn], dfn[maxn], low[maxn], cnt, scc, h[maxn];
int col[maxn], q[maxn];
long long dp[maxn], sum[maxn];
int n, m;
void add(int hg[], bkn e[], int x, int y, long long w) {
  e[tot].to = y, e[tot].next = hg[x], e[tot].w = w, hg[x] = tot++;
}
void tarjan(int x) {
  low[x] = dfn[x] = ++cnt;
  st.push(x);
  vis[x] = 1;
  for (int i = head[x]; i; i = e[i].next) {
    int y = e[i].to;
    if (!dfn[y])
      tarjan(y), low[x] = min(low[x], low[y]);
    else if (vis[y])
      low[x] = min(low[x], low[y]);
  }
  if (low[x] == dfn[x]) {
    scc++;
    while (1) {
      int y = st.top();
      st.pop();
      vis[y] = 0;
      col[y] = scc;
      if (x == y) break;
    }
  }
}
void dfs(int x) {
  vis[x] = 1;
  for (int i = h[x]; i; i = e2[i].next) {
    int y = e2[i].to;
    if (!vis[y]) dfs(y);
  }
  q[++cnt] = x;
}
int main() {
  scanf("%d%d", &n, &m);
  for (int i = 1; i <= m; i++) {
    int x, y, w;
    scanf("%d%d%d", &x, &y, &w);
    add(head, e, y, x, w);
  }
  for (int i = 1; i <= n; i++) {
    if (!dfn[i]) tarjan(i);
  }
  tot = 1;
  for (int x = 1; x <= n; x++) {
    for (int i = head[x]; i; i = e[i].next) {
      int y = e[i].to;
      if (col[y] == col[x]) {
        if (e[i].w != 0) {
          cout << "No" << endl;
          return 0;
        }
      } else
        add(h, e2, col[x], col[y], e[i].w);
    }
  }
  cnt = 0;
  for (int i = 1; i <= scc; i++) {
    if (!vis[i]) dfs(i);
  }
  for (int i = cnt; i >= 1; i--) {
    int x = q[i];
    for (int j = h[x]; j; j = e2[j].next) {
      int y = e2[j].to;
      if (!dp[y])
        dp[y] = dp[x] + e2[j].w;
      else if (dp[y] != dp[x] + e2[j].w) {
        cout << "No" << endl;
        return 0;
      }
    }
  }
  cout << "Yes" << endl;
}
