#include <bits/stdc++.h>
using namespace std;
int N, M;
vector<pair<pair<int, int>, int> > q;
vector<pair<int, int> > g[100101];
int parent[100101], dp[20][100101], p[100101];
long long depth[100101];
int Find(int n) {
  if (n == parent[n]) return n;
  return parent[n] = Find(parent[n]);
}
void Union(int l, int r, int d) {
  int pl = l, pr = r;
  l = Find(l);
  r = Find(r);
  if (l == r) {
    q.push_back({{pl, pr}, d});
    return;
  }
  parent[l] = r;
  g[l].push_back({r, d});
  g[r].push_back({l, -d});
}
void DFS(int n, int prev) {
  for (int i = 0; i < g[n].size(); i++) {
    int next = g[n][i].first, cost = g[n][i].second;
    if (next == prev) continue;
    p[next] = n;
    depth[next] = depth[n] + cost;
    DFS(next, n);
  }
}
int LCA(int a, int b) {
  if (a == b) return a;
  for (int i = 19; i >= 0; i--)
    if (dp[i][a] != dp[i][b]) {
      a = dp[i][a];
      b = dp[i][b];
    }
  return p[a];
}
int main() {
  for (int i = 0; i < 100101; i++) parent[i] = i;
  scanf("%d %d", &N, &M);
  for (int i = 0; i < M; i++) {
    int a, b, c;
    scanf("%d %d %d", &a, &b, &c);
    Union(a, b, c);
  }
  depth[1] = 0;
  DFS(1, 0);
  for (int i = 1; i <= N; i++) dp[0][i] = p[i];
  for (int i = 1; i < 20; i++)
    for (int j = 1; j <= N; j++) dp[i][j] = dp[i - 1][dp[i - 1][j]];
  for (int i = 0; i < q.size(); i++) {
    int l = q[i].first.first, r = q[i].first.second, d = q[i].second;
    int lca = LCA(l, r);
    if (depth[l] + depth[r] - depth[lca] * 2 != (long long)d)
      return !printf("No");
  }
  printf("Yes");
  return 0;
}
