#include <bits/stdc++.h>
using namespace std;
const long long INF =
    sizeof(long long) == sizeof(long long) ? 1000000000000000000LL : 1000000000;
const long long MOD = 1000000007;
const long double EPS = 1e-8;
using vi = vector<long long>;
using vvi = vector<vi>;
long long n, m, sz;
vector<bool> used;
struct edge {
  long long to;
  long long dist;
};
vector<vector<edge>> G;
map<long long, long long> pear, berry;
bool reach, mujun;
void dfs(long long now, long long goal, long long expect, long long sum) {
  if (mujun) return;
  if (now == goal) {
    reach = true;
    mujun = mujun || expect != sum;
  }
  for (long long i = (0); i < (G[now].size()); i++) {
    if (used[G[now][i].to]) continue;
    used[G[now][i].to] = true;
    dfs(G[now][i].to, goal, expect, sum + G[now][i].dist);
  }
  return;
}
signed main() {
  cin >> n >> m;
  G = vector<vector<edge>>(n);
  used = vector<bool>(n, false);
  long long l[m], r[m], d[m];
  map<long long, long long> exist;
  bool flag = false;
  sz = 0;
  for (long long i = (0); i < (m); i++) {
    cin >> l[i] >> r[i] >> d[i];
    if (flag) continue;
    if (exist[l[i]] != 0 && exist[r[i]] != 0) {
      used = vector<bool>(sz, false);
      used[pear[l[i]]] = true;
      reach = false;
      mujun = false;
      dfs(pear[l[i]], pear[r[i]], d[i], 0);
      dfs(pear[r[i]], pear[l[i]], -d[i], 0);
      if (!reach || mujun) flag = true;
    } else {
      if (exist[l[i]] == 0) {
        exist[l[i]] = true;
        pear[l[i]] = sz;
        berry[sz] = l[i];
        sz++;
      } else {
        for (long long j = (0); j < (G[pear[l[i]]].size()); j++)
          if (G[pear[l[i]]][j].dist == d[i]) flag = true;
      }
      if (exist[r[i]] == 0) {
        exist[r[i]] = true;
        pear[r[i]] = sz;
        berry[sz] = r[i];
        sz++;
      } else {
        for (long long j = (0); j < (G[pear[r[i]]].size()); j++)
          if (G[pear[r[i]]][j].dist == -d[i]) flag = true;
      }
      G[pear[l[i]]].push_back({pear[r[i]], d[i]});
      G[pear[r[i]]].push_back({pear[l[i]], -d[i]});
    }
  }
  cout << (flag ? "No" : "Yes") << endl;
  return 0;
}
