#include <bits/stdc++.h>
using namespace std;
template <typename T>
inline void read(T &x) {
  T s = 0, f = 1;
  static char c;
  for (c = getchar(); !isdigit(c); c = getchar())
    if (c == '-') f = -1;
  for (; isdigit(c); c = getchar()) s = s * 10 + (c ^ 48);
  x = s * f;
}
const int MAXN = 1e5 + 7;
const int inf = 1e9 + 7;
static int in[MAXN], n, m, e, dis[MAXN], head[MAXN];
static struct edge { int v, nxt, w; } p[MAXN << 1];
inline void add(int u, int v, int w) {
  p[++e].v = v;
  p[e].w = w;
  p[e].nxt = head[u];
  head[u] = e;
}
inline void End() {
  printf("No\n");
  exit(0);
}
void dfs(int u) {
  for (register int v = head[u]; v; v = p[v].nxt) {
    if (dis[p[v].v] != inf && dis[p[v].v] != dis[u] + p[v].w) End();
    dis[p[v].v] = dis[u] + p[v].w;
    if (dis[p[v].v] > 1e9) End();
    if (!(--in[p[v].v])) dfs(p[v].v);
  }
}
int main() {
  read(n);
  read(m);
  if (!m) {
    printf("Yes\n");
    return 0;
  }
  static int u, v, w, root = 0;
  dis[0] = inf;
  for (register int i = (1), iend = (m); i <= iend; ++i)
    read(u), read(v), read(w), add(u, v, w), ++in[v], dis[u] = dis[v] = inf;
  for (register int i = (1), iend = (n); i <= iend; ++i)
    if (dis[i] == inf && !in[i]) {
      root = i;
      break;
    }
  if (!root) End();
  dis[root] = 0;
  dfs(root);
  for (register int i = (1), iend = (n); i <= iend; ++i)
    if (dis[i] > 1e9) End();
  printf("Yes\n");
  return 0;
}
