#include <bits/stdc++.h>
using namespace std;
struct query {
  int a, b, c;
} query[200001];
int n, m, q;
vector<pair<int, int> > adj[100001];
int ea[18][100001], ed[18][100001], pa[100001], dist[100001];
int find(int cur) { return cur == pa[cur] ? cur : pa[cur] = find(pa[cur]); }
void dfs(int cur, int p, int d, int cost) {
  dist[cur] = d;
  int pp = p, a = 1;
  ea[0][cur] = p;
  ed[0][cur] = cost;
  while (ea[a - 1][pp] != 0) {
    ea[a][cur] = ea[a - 1][pp];
    ed[a][cur] = ed[a - 1][pp] + ed[a - 1][cur];
    pp = ea[a - 1][pp];
    a++;
  }
  for (auto &it : adj[cur])
    if (it.second != p) {
      dfs(it.second, cur, d + 1, -it.first);
    }
}
int lca(int u, int v) {
  int f = 1, ds = 0;
  if (dist[v] < dist[u]) swap(u, v), f = -1;
  int dif = dist[v] - dist[u];
  for (int i = 0; 1 << i <= dif; i++) {
    if (dif >> i & 1) {
      ds += ed[i][v];
      v = ea[i][v];
    }
  }
  if (u == v) return u;
  int du = 0, dv = ds;
  for (int i = 17; i >= 0; i--)
    if (ea[i][u] != 0 && ea[i][v] != 0 && ea[i][u] != ea[i][v]) {
      u = ed[i][u];
      v = ed[i][v];
    }
  return ea[0][v];
}
int getLen(int u, int v) {
  int dif = dist[v] - dist[u], ds = 0;
  for (int i = 0; 1 << i <= dif; i++) {
    if (dif >> i & 1) {
      ds += ed[i][v];
      v = ea[i][v];
    }
  }
  return ds;
}
int main() {
  scanf("%d%d", &n, &m);
  for (int i = 1; i <= n; i++) pa[i] = i;
  for (int i = 0; i < m; i++) {
    int a, b, c;
    scanf("%d%d%d", &a, &b, &c);
    if (find(a) != find(b)) {
      adj[a].push_back(pair<int, int>(c, b));
      adj[b].push_back(pair<int, int>(-c, a));
      int pu = find(b), pv = find(a);
      pa[pu] = pv;
    } else {
      query[q].a = a;
      query[q].b = b;
      query[q].c = c;
      q++;
    }
  }
  for (int i = 1; i <= n; i++)
    if (!dist[i]) dfs(i, 0, 1, 0);
  for (int i = 0; i < q; i++) {
    int aa = lca(query[i].a, query[i].b);
    int d = getLen(aa, query[i].a) - getLen(aa, query[i].b);
    if (d != query[i].c) {
      puts("No");
      return 0;
    }
  }
  puts("Yes");
  return 0;
}
