#include <bits/stdc++.h>
const int M = 2e5 + 10;
int f[M];
int a[M], b[M], c[M];
std::vector<int> d[M];
int find(int x) { return f[x] == -1 ? x : f[x] = find(f[x]); }
int main() {
  int n, m;
  scanf("%d%d", &n, &m);
  memset(f, -1, sizeof(f));
  for (int i = 0; i < n; i++) d[i].push_back(0);
  for (int i = 0; i < m; i++) {
    int u, v, w;
    scanf("%d%d%d", &u, &v, &w);
    u--, v--;
    a[i] = u;
    b[i] = v;
    c[i] = w;
    int fa = find(u);
    int fb = find(v);
    if (fa == fb) {
      continue;
    } else {
      if (fa < fb) {
        f[fb] = fa;
        d[v].clear();
        for (int x : d[u]) {
          d[v].push_back(x + w);
          d[v].push_back(x - w);
        }
      } else {
        f[fa] = fb;
        d[u].clear();
        for (int x : d[v]) {
          d[u].push_back(x + w);
          d[u].push_back(x - w);
        }
      }
    }
  }
  bool flag = true;
  for (int i = 0; i < m; i++) {
    int u = a[i], v = b[i], w = c[i];
    int fa = find(u);
    int fb = find(v);
    if (fa == fb) {
      int flg = false;
      for (auto x : d[u])
        for (auto y : d[v]) {
          if (abs(x - y) == w) flg = true;
        }
      if (!flg) flag = false;
    }
  }
  if (flag)
    puts("Yes");
  else
    puts("No");
}
