#include <bits/stdc++.h>
using namespace std;
const double INF = 1e100;
const double EPS = 1e-9;
template <class T1>
void deb(T1 e1) {
  cout << e1 << endl;
}
template <class T1, class T2>
void deb(T1 e1, T2 e2) {
  cout << e1 << " " << e2 << endl;
}
template <class T1, class T2, class T3>
void deb(T1 e1, T2 e2, T3 e3) {
  cout << e1 << " " << e2 << " " << e3 << endl;
}
template <class T1, class T2, class T3, class T4>
void deb(T1 e1, T2 e2, T3 e3, T4 e4) {
  cout << e1 << " " << e2 << " " << e3 << " " << e4 << endl;
}
template <class T1, class T2, class T3, class T4, class T5>
void deb(T1 e1, T2 e2, T3 e3, T4 e4, T5 e5) {
  cout << e1 << " " << e2 << " " << e3 << " " << e4 << " " << e5 << endl;
}
template <class T1, class T2, class T3, class T4, class T5, class T6>
void deb(T1 e1, T2 e2, T3 e3, T4 e4, T5 e5, T6 e6) {
  cout << e1 << " " << e2 << " " << e3 << " " << e4 << " " << e5 << " " << e6
       << endl;
}
template <class T>
T gcd(const T a, const T b) {
  return (b ? gcd<T>(b, a % b) : a);
}
template <class T>
T lcm(const T a, const T b) {
  return (a / gcd<T>(a, b) * b);
}
struct node {
  long long x, y;
  node() {}
  node(long long x, long long y) : x(x), y(y) {}
  bool operator<(const node& p) const { return x < p.x; }
};
bool ok[100005];
vector<long long> v[100004], cost[100004];
bool ck;
long long val[100002], vis[100002];
void dfs(long long u, long long sum) {
  if (vis[u]) {
    if (sum != val[u]) ck = 1;
    return;
  }
  vis[u] = 1;
  val[u] = sum;
  for (long long i = 0; i < v[u].size(); i++) {
    long long x = v[u][i];
    dfs(x, sum + cost[u][i]);
  }
}
void dfs1(long long u) {
  if (vis[u]) return;
  vis[u] = 1;
  ok[u] = 1;
  for (long long i = 0; i < v[u].size(); i++) {
    long long x = v[u][i];
    if (!vis[x])
      dfs1(x);
    else if (ok[x])
      ck = 1;
  }
  ok[u] = 1;
}
long long a[100003];
int main() {
  long long i, j, k, l, x, y, z, t, m, n, l1, l2;
  while (scanf("%lld %lld", &n, &m) == 2) {
    memset(a, 0, sizeof(a));
    for (i = 1; i <= 100000; i++) v[i].clear();
    for (i = 1; i <= m; i++) {
      scanf("%lld %lld %lld", &x, &y, &z);
      v[x].push_back(y);
      a[y]++;
      cost[x].push_back(z);
    }
    ck = 0;
    memset(vis, 0, sizeof(vis));
    memset(ok, 0, sizeof(ok));
    for (i = 1; i <= n; i++) {
      if (!vis[i]) dfs1(i);
    }
    memset(vis, 0, sizeof(vis));
    for (i = 1; i <= n; i++) val[i] = -99194853094755497;
    for (i = 1; i <= n; i++) {
      if (a[i] == 0) dfs(i, 0);
    }
    if (ck)
      deb("No");
    else
      deb("Yes");
  }
  return 0;
}
