#include <bits/stdc++.h>
using namespace std;
unsigned long long over = 1000000007;
signed long long dfs_r(
    signed long long idx,
    vector<vector<tuple<signed long long, signed long long> > >& path,
    vector<bool>& visited) {
  visited[idx] = true;
  if (path[idx].size() == 0) return idx;
  for (auto n : path[idx]) {
    if (get<1>(n) == 1) continue;
    if (visited[get<0>(n)]) return -1;
    return dfs_r(get<0>(n), path, visited);
  }
  return idx;
}
bool dfs(signed long long idx,
         vector<vector<tuple<signed long long, signed long long> > >& path,
         vector<bool>& visited, vector<signed long long>& dist) {
  visited[idx] = true;
  for (auto n : path[idx]) {
    signed long long ci = get<0>(n);
    signed long long cd = get<1>(n);
    if (visited[ci]) {
      if (dist[idx] + cd == dist[ci]) continue;
      return false;
    }
    dist[ci] = dist[idx] + cd;
    dfs(ci, path, visited, dist);
  }
  return true;
}
int main(void) {
  cin.tie(0);
  ios::sync_with_stdio(false);
  cout << fixed;
  signed long long n, m;
  cin >> n >> m;
  vector<vector<tuple<signed long long, signed long long> > > path(n);
  vector<vector<tuple<signed long long, signed long long> > > path_r(n);
  vector<signed long long> same(n);
  for (signed long long i = 0; i < n; ++i) same[i] = i;
  for (signed long long i = 0; i < m; ++i) {
    signed long long l, r, d;
    cin >> l >> r >> d;
    l--;
    r--;
    if (d == 0) {
      signed long long s_idx = min(l, min(r, min(same[l], same[r])));
      same[l] = s_idx;
      same[r] = s_idx;
    }
    l = same[l];
    r = same[r];
    path[l].push_back(make_tuple(r, d));
    path_r[r].push_back(make_tuple(l, d));
    if (d == 0) {
      path[r].push_back(make_tuple(l, d));
    }
  }
  vector<bool> visited(n, false);
  vector<signed long long> dist(n, 0);
  vector<bool> v_r(n, false);
  for (signed long long i = 0; i < n; ++i) {
    if (visited[i] || path[i].size() == 0) continue;
    signed long long root = dfs_r(i, path_r, v_r);
    if (root == -1) {
      cout << "No" << endl;
      return 0;
    }
    bool flg = dfs(i, path, visited, dist);
    if (!flg) {
      cout << "No" << endl;
      return 0;
    }
  }
  cout << "Yes" << endl;
  return 0;
}
