#include <bits/stdc++.h>
using namespace std;
struct Comb {
  vector<vector<int64_t> > data;
  Comb(int n) {
    data = vector<vector<int64_t> >(n + 1, vector<int64_t>(n + 1, 1));
    for (register int i = (1); i <= ((int)n); i++) {
      for (register int j = (0); j <= ((int)(i + 1) - 1); j++) {
        if (!j || j == i)
          data[i][j] = 1;
        else
          data[i][j] = data[i - 1][j - 1] + data[i - 1][j];
      }
    }
  }
  int64_t ncr(int n, int r) { return data[n][r]; }
};
static inline int ri() {
  int a;
  scanf("%d", &a);
  return a;
}
int int_less(const void *a, const void *b) {
  return (*((const int *)a) - *((const int *)b));
}
int int_greater(const void *a, const void *b) {
  return (*((const int *)b) - *((const int *)a));
}
struct UnionFind {
  vector<int> data;
  UnionFind(int size) : data(size, -1) {}
  bool unite(int x, int y) {
    x = root(x);
    y = root(y);
    if (x != y) {
      if (data[y] < data[x]) swap(x, y);
      data[x] += data[y];
      data[y] = x;
    }
    return x != y;
  }
  bool find(int x, int y) { return root(x) == root(y); }
  int root(int x) { return data[x] < 0 ? x : data[x] = root(data[x]); }
  int size(int x) { return -data[root(x)]; }
  bool united() {
    int comroot = -1;
    for (register int i = (0); i <= ((int)(data.size()) - 1); i++) {
      if (comroot != -1 && root(i) != comroot) return false;
      comroot = root(i);
    }
    return true;
  }
};
int main() {
  int n = ri();
  int m = ri();
  vector<pair<int, int> > hen[n];
  UnionFind uni(n);
  for (register int i = (0); i <= ((int)(m)-1); i++) {
    int l = ri() - 1;
    int r = ri() - 1;
    hen[l].push_back({r, ri()});
    uni.unite(l, r);
  }
  queue<int> que;
  int dist[n];
  for (register int i = (0); i <= ((int)((sizeof(dist) / sizeof(*dist))) - 1);
       i++)
    dist[i] = ((1 << 30) - 1);
  for (register int i = (0); i <= ((int)(n)-1); i++)
    if (uni.root(i) == i) que.push((int)i), dist[i] = 0;
  while (que.size()) {
    int i = que.front();
    que.pop();
    for (auto j : hen[i]) {
      if (dist[j.first] == ((1 << 30) - 1)) {
        dist[j.first] = dist[i] + j.second;
        que.push(j.first);
      } else if (dist[j.first] != dist[i] + j.second) {
        cout << "No" << endl;
        return 0;
      }
    }
  }
  cout << "Yes" << endl;
  return 0;
}
