#include <bits/stdc++.h>
using namespace std;
long long gcd(long long n1, long long n2) {
  if (n2 == 0) return n1;
  if (n1 % n2 == 0) return n2;
  return gcd(n2, n1 % n2);
}
long long powmod(long long base, long long exponent) {
  if (exponent < 0) exponent += 1000000007LL - 1;
  long long ans = 1;
  while (exponent) {
    if (exponent & 1) ans = (ans * base) % 1000000007LL;
    base = (base * base) % 1000000007LL;
    exponent /= 2;
  }
  return ans;
}
bool visited[1000005];
int ans[1000005];
bool flag = true;
vector<pair<int, int> > v[1000005];
int lefti[1000005];
void DFS(int n) {
  visited[n] = true;
  for (auto i : v[n]) {
    if (i.second != 0) lefti[i.first]--;
    if ((!visited[i.first])) {
      ans[i.first] = ans[n] + i.second;
      DFS(i.first);
    } else if (ans[i.first] != ans[n] + i.second) {
      flag = false;
    }
  }
}
int main() {
  int n, m;
  cin >> n >> m;
  for (int i = 0; i < m; i++) {
    int l, r, d;
    cin >> l >> r >> d;
    v[l].push_back(make_pair(r, d));
    if (d != 0) lefti[r]++;
  }
  for (int i = 0; i < n; i++) {
    if ((!visited[i]) && lefti[i] == 0) {
      DFS(i);
    }
  }
  for (int i = 0; i < n; i++)
    if (ans[i] > 1e9 || lefti[i] != 0) {
      flag = false;
      cout << lefti[i] << '\n';
    }
  if (flag)
    cout << "Yes" << '\n';
  else
    cout << "No" << '\n';
}
