#include <bits/stdc++.h>
using namespace std;
const int N = 101010;
int n, m;
int par[N], dis[N], sz[N];
pair<int, int> find(int x) {
  if (x == par[x]) return {x, 0};
  pair<int, int> res = find(par[x]);
  par[x] = res.first;
  dis[x] = dis[x] + res.second;
  return {par[x], dis[x]};
}
int main() {
  scanf("%d%d", &n, &m);
  for (int i = (0); i < (n); ++i) par[i] = i;
  bool ans = 1;
  for (int i = (0); i < (m); ++i) {
    int u, v, w;
    scanf("%d%d%d", &u, &v, &w);
    pair<int, int> a = find(u - 1), b = find(v - 1);
    if (a.first == b.first) {
      ans &= a.second + w == b.second;
    } else {
      par[b.first] = a.first;
      dis[b.first] = a.second + w;
    }
  }
  for (int i = (0); i < (n); ++i)
    if (find(i).second > 1e9) ans = false;
  puts(ans ? "Yes" : "No");
  return 0;
}
