#include <bits/stdc++.h>
using namespace std;
template <typename T>
inline bool chkmin(T& x, T y) {
  return x > y ? x = y, 1 : 0;
}
template <typename T>
inline bool chkmax(T& x, T y) {
  return x < y ? x = y, 1 : 0;
}
template <typename T>
inline void read(T& x) {
  x = 0;
  char c;
  int sign = 1;
  do {
    c = getchar();
    if (c == '-') sign = -1;
  } while (!isdigit(c));
  do {
    x = x * 10 + c - '0';
    c = getchar();
  } while (isdigit(c));
  x *= sign;
}
const int N = 1e5 + 500;
int tot, head[N], nxt[N << 1], to[N << 1], val[N << 1];
int n, m, d[N];
bool vis[N];
inline void add(int x, int y, int w) {
  val[tot] = w;
  to[tot] = y;
  nxt[tot] = head[x];
  head[x] = tot++;
}
bool dfs(int x) {
  vis[x] = 1;
  for (register int i = head[x]; ~i; i = nxt[i])
    if (chkmin(d[to[i]], d[x] + val[i])) {
      if (vis[to[i]]) return false;
      if (!dfs(to[i])) return false;
    }
  vis[x] = 0;
  return true;
}
int main() {
  memset(d, 0x3f, sizeof d);
  memset(head, -1, sizeof head);
  read(n);
  read(m);
  for (register int i = 1; i <= m; ++i) {
    int a, b, c;
    read(a);
    read(b);
    read(c);
    add(a, b, c), add(b, a, -c);
  }
  for (register int i = 1; i <= n; ++i) add(0, i, 1);
  d[0] = 0;
  puts(dfs(0) ? "Yes" : "No");
  return 0;
}
