#include <bits/stdc++.h>
using namespace std;
int i, j, n, m, st[1000005], f[1000005], vis[1000005], a, b, dis[1000005];
struct edge {
  int to, cost;
} t;
vector<edge> v[1000005];
queue<int> q;
int findSet(int x) {
  if (x == st[x])
    return x;
  else
    return st[x] = findSet(st[x]);
}
void unionSet(int x, int y) {
  int fx = findSet(x);
  int fy = findSet(y);
  if (fx != fy) st[fx] = fy;
}
int main() {
  cin >> n >> m;
  for (int i = 0; i < m; i++) {
    cin >> a >> b >> t.cost;
    unionSet(a, b);
    if (!f[findSet(a)]) {
      f[findSet(a)] = 1;
      q.push(a);
      vis[a] = 1;
      dis[a] = 0;
    }
    t.to = b;
    v[a].push_back(t);
    t.to = a;
    t.cost = -t.cost;
    v[b].push_back(t);
  }
  while (!q.empty()) {
    int cur = q.front();
    q.pop();
    int sz = v[cur].size();
    for (i = 0; i < sz; i++) {
      if (!vis[v[cur][i].to]) {
        vis[v[cur][i].to] = 1;
        q.push(v[cur][i].to);
        dis[v[cur][i].to] = dis[cur] + v[cur][i].cost;
      } else if (dis[v[cur][i].to] != dis[cur] + v[cur][i].cost) {
        printf("No");
        return 0;
      }
    }
  }
  printf("Yes");
  return 0;
}
