#include <bits/stdc++.h>
using namespace std;
const int maxn = 2e5 + 20;
int n, m;
vector<pair<int, int> > adj[maxn];
int bio[maxn];
int dsu[maxn];
map<int, int> loc;
int dsu_find(int first) {
  if (first == dsu[first]) return first;
  return dsu[first] = dsu_find(dsu[first]);
}
void dsu_merge(int first, int second) {
  first = dsu[first];
  second = dsu[second];
  if (first != second) {
    if (rand() & 1) swap(first, second);
    dsu[first] = second;
  }
}
bool dfs(int u, int par) {
  int v = dsu_find(u);
  bio[v] = 1;
  for (pair<int, int> e : adj[v]) {
    int w = dsu_find(e.first);
    if (w != par) {
      if (bio[w] == 0) {
        loc[w] = loc[v] + e.second;
        dfs(w, v);
      } else if (bio[w] == 1) {
        if (loc[w] != loc[v] + e.second) {
          return true;
        }
      }
    }
  }
  return false;
}
int main() {
  srand(0);
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cin >> n >> m;
  for (int i = 1; i <= n; i++) {
    dsu[i] = i;
  }
  for (int i = 0, u, v, d; i < m; i++) {
    cin >> u >> v >> d;
    if (d) {
      adj[u].push_back(pair<int, int>(v, d));
      adj[v].push_back(pair<int, int>(u, -d));
    } else {
      dsu_merge(u, v);
    }
  }
  for (int i = 1; i <= n; i++) {
    int j = dsu_find(i);
    if (!bio[j]) {
      loc[j] = 0;
      if (dfs(j, 0)) {
        cout << "No" << endl;
        return 0;
      }
    }
  }
  cout << "Yes" << endl;
  return 0;
}
