#include <bits/stdc++.h>
using namespace std;
struct P {
  int x;
  int y;
  bool operator<(const P &a) const { return x > a.x; }
};
struct S {
  int x, y;
};
vector<P> v[300333];
int a, c, i, b, k = -1987654321, d, n, m, e = 1987654321;
int l[2000010];
int o[222333];
int j[222222];
int dx[10] = {0, 1, 0, -1}, dy[10] = {1, 0, -1, 0},
    dz[10] = {0, 0, 0, 0, 1, -1};
stack<S> s;
queue<int> q;
queue<int> q1;
map<int, int> p[22][22];
string r, r2;
int f(int a) {
  if (a < 2) return a;
  return f(a / 2) + a % 2;
}
int main() {
  scanf("%d %d", &a, &b);
  if (b < 2) {
    puts("Yes");
    return 0;
  }
  for (int t = 1; t <= b; t++) {
    scanf("%d %d %d", &n, &m, &i);
    v[n].push_back({m, i});
    v[m].push_back({n, -i});
    j[m] = 1;
    q.push(n);
  }
  i = 0;
  for (; q.size(); q.pop())
    if (!j[q.front()]) {
      i = q.front();
      break;
    }
  for (int t = 1; t <= a; t++) l[t] = -2087654321;
  if (!i) {
    puts("No");
    return 0;
  }
  l[i] = 0;
  e = 0;
  k = 0;
  q.push(i);
  for (; q.size(); q.pop())
    for (int h = 0; h < v[q.front()].size(); h++) {
      if (l[v[q.front()][h].x] == -2087654321) {
        l[v[q.front()][h].x] = l[q.front()] + v[q.front()][h].y;
        e = max(e, l[v[q.front()][h].x]);
        k = min(k, l[v[q.front()][h].x]);
        q.push(v[q.front()][h].x);
      } else {
        if (l[v[q.front()][h].x] != l[q.front()] + v[q.front()][h].y) {
          puts("No");
          return 0;
        }
      }
    }
  if (e - k <= 1000000000)
    puts("Yes");
  else
    puts("No");
}
