#include <bits/stdc++.h>
using namespace std;
template <typename X>
bool exist(vector<X> vec, X item) {
  return find(vec.begin(), vec.end(), item) != vec.end();
}
long long gcd(long long a, long long b) {
  if (b == 0) return a;
  return gcd(b, a % b);
}
long long lcm(long long a, long long b) { return a / gcd(a, b) * b; }
struct UnionFind {
  vector<int> node;
  UnionFind(int n) : node(n, -1) {}
  bool unite(int x, int y) {
    x = root(x);
    y = root(y);
    if (x != y) {
      if (node[y] < node[x]) swap(x, y);
      node[x] += node[y];
      node[y] = x;
    }
    return x != y;
  }
  bool same(int x, int y) { return root(x) == root(y); }
  int root(int x) { return node[x] < 0 ? x : node[x] = root(node[x]); }
  int size(int x) { return -node[root(x)]; }
};
long long N, M;
vector<long long> rut;
map<long long, vector<pair<long long, long long> > > to;
long long ans[100005];
int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  for (long long i = (long long)0; i < (long long)100005; i++) ans[i] = -1;
  cin >> N >> M;
  UnionFind UF(N);
  for (long long i = (long long)0; i < (long long)M; i++) {
    long long l, r, d;
    cin >> l >> r >> d;
    l--;
    r--;
    UF.unite(l, r);
    to[l].push_back(make_pair(r, d));
  }
  for (long long i = (long long)0; i < (long long)N; i++) {
    rut.push_back(UF.root(i));
  }
  sort(rut.begin(), rut.end()),
      rut.erase(unique(rut.begin(), rut.end()), rut.end());
  for (long long i = (long long)0; i < (long long)rut.size(); i++) {
    ans[rut[i]] = 0;
  }
  while (rut.size() != 0) {
    long long siz = rut.size();
    for (long long i = (long long)0; i < (long long)siz; i++) {
      long long now = rut[0];
      for (long long j = (long long)0; j < (long long)to[now].size(); j++) {
        long long next = to[now][j].first;
        long long dis = to[now][j].second;
        if (ans[next] == -1) {
          ans[next] = ans[now] + dis;
          rut.push_back(next);
        } else {
          if (ans[next] != ans[now] + dis) {
            cout << "No" << endl;
            return 0;
          }
        }
      }
      rut.erase(rut.begin());
    }
  }
  cout << "Yes" << endl;
  return 0;
}
