#include <bits/stdc++.h>
using namespace std;
int vis2[100001], visn[100001], vis[100001], recs[100001], flg = 0;
vector<pair<int, int> > v[100001], vn[100001];
void dfs(int r) {
  recs[r] = 1;
  vis[r] = 1;
  for (int i = 0; i < v[r].size(); i++) {
    int x = v[r][i].first;
    if (vis[x] == 0) {
      dfs(v[r][i].first);
    } else {
      if (recs[x] == 1) {
        flg = 1;
      }
    }
  }
  recs[r] = 0;
  return;
}
void dfsn(int r, long long sum, int parent) {
  visn[r] = 1;
  for (int i = 0; i < vn[r].size(); i++) {
    int x = vn[r][i].first;
    if (visn[x] == 0) {
      dfsn(x, sum + vn[r][i].second, r);
    } else if (visn[x] == 1) {
      if (x != parent && vis2[x] != 1) {
        if (sum + vn[r][i].second != 0)
          flg = 1;
        else {
          vis2[r] = 1;
        }
      }
    }
  }
}
int main() {
  int i, j, n, m;
  cin >> n >> m;
  for (i = 0; i < m; i++) {
    int l, r, d;
    cin >> l >> r >> d;
    v[l].push_back(make_pair(r, d));
  }
  for (i = 1; i <= n; i++) {
    if (vis[i] == 0) dfs(i);
  }
  if (flg == 1) {
    cout << "No\n";
    return 0;
  }
  for (i = 1; i <= n; i++) {
    for (j = 0; j < v[i].size(); j++) {
      int x = v[i][j].first;
      vn[i].push_back(make_pair(x, v[i][j].second));
      vn[x].push_back(make_pair(i, -1 * v[i][j].second));
    }
  }
  flg = 0;
  for (i = 1; i <= n; i++) {
    if (visn[i] == 0) dfsn(i, 0, 0);
  }
  if (flg == 1) {
    cout << "No\n";
    return 0;
  }
  cout << "Yes\n";
  return 0;
}
