#include <bits/stdc++.h>
int ta[100010], to[400040], co[400040], nt[400040], d[100010];
int main() {
  int n, m, i, j, t, r, a, b, c, q[100010], u[100010] = {};
  for (i = 0; i < 100005; i++) d[i] = ta[i] = -1;
  scanf("%d %d", &n, &m);
  for (i = 0; i < m; i++) {
    scanf("%d %d %d", &a, &b, &c);
    nt[i] = ta[to[i + m] = a];
    nt[i + m] = ta[to[i] = b];
    co[ta[b] = i + m] = -c;
    co[ta[a] = i] = c;
  }
  for (j = 1; j <= n; j++) {
    if (u[j]) continue;
    d[j] = 1e9;
    q[t = 0] = j;
    for (r = 1; r - t; t++) {
      u[q[t]] = 1;
      for (i = ta[q[t]]; i + 1; i = nt[i]) {
        printf("%d %d\n", q[t], to[i]);
        if (d[to[i]] > 0 && d[to[i]] != d[q[t]] + co[i]) goto END;
        if (u[to[i]]) continue;
        d[to[i]] = d[q[t]] + co[i];
        q[r++] = to[i];
      }
    }
  }
  printf("Yes\n");
  return 0;
END:;
  printf("No\n");
  return 0;
}
