#include <bits/stdc++.h>
using namespace std;
class UnionFind {
 public:
  vector<int> uni;
  UnionFind(int s) : uni(s, -1) {}
  int root(int a) {
    if (uni[a] < 0) return a;
    return uni[a] = root(uni[a]);
  }
  bool connect(int a, int b) {
    a = root(a);
    b = root(b);
    if (a == b) return false;
    if (uni[a] > uni[b]) swap(a, b);
    uni[a] = uni[a] + uni[b];
    uni[b] = a;
    return true;
  }
  bool isConnect(int a, int b) { return root(a) == root(b); }
  int size(int a) { return -uni[root(a)]; }
};
bool solve() {
  int N, M;
  cin >> N >> M;
  UnionFind uf(N);
  for (int i = 0; i < M; ++i) {
    int l, r, d;
    cin >> l >> r >> d;
    l--, r--;
    if (uf.isConnect(l, r)) {
      if (uf.size(l) != d + 1) return false;
    } else {
      uf.connect(l, r);
    }
  }
  return true;
}
int main() {
  cout << (solve() ? "Yes" : "No") << endl;
  return 0;
}
