#include <bits/stdc++.h>
#pragma GCC optimize("O3")
const long long INF = 0x3f3f3f3f3f3f3f3f;
const long long llinf = LLONG_MAX;
const int inf = INT_MAX;
const int nmax = 2e5 + 5;
const int mod = 1e9 + 7;
using namespace std;
int n, m, i, x, y, z, ok, viz[nmax], nr[nmax], sum[nmax];
vector<pair<int, int> > v[nmax];
map<int, int> mp;
void dfs(int x, int p) {
  if (!ok) return;
  viz[x] = 1;
  if (p == mp[x]) {
    ok = 0;
    return;
  }
  mp[x] = p;
  for (int i = 0; i < v[x].size(); i++) dfs(v[x][i].first, x);
}
void dfs1(int x, int s) {
  if ((sum[x] != s && sum[x]) || !ok) {
    ok = 0;
    return;
  }
  sum[x] = s;
  for (int i = 0; i < v[x].size(); i++) dfs1(v[x][i].first, s + v[x][i].second);
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cerr.tie(0);
  cout.tie(0);
  cin >> n >> m;
  for (i = 1; i <= m; i++) {
    cin >> x >> y >> z;
    v[x].push_back({y, z});
    nr[y]++;
  }
  for (i = 1; i <= n; i++)
    if (!viz[i] && v[i].size()) {
      ok = 1, dfs(i, -1);
      mp.clear();
      if (!ok) return cout << "No" << endl, 0;
    }
  for (i = 1; i <= n; i++)
    if (viz[i] && !nr[i]) {
      ok = 1, dfs1(i, 0);
      if (!ok) return cout << "No" << endl, 0;
    }
  return cout << "Yes" << endl, 0;
  return 0;
}
