#include <bits/stdc++.h>
using namespace std;
const int maxn = 2e5 + 100;
const long long INF = (1e18) + 100;
long long d[maxn];
map<int, int> mp1[maxn];
map<int, int> mp2[maxn];
struct pp {
  int l, r, d;
} a[maxn];
struct p {
  int node, next, val;
} E[maxn * 4];
struct Node {
  int pos, val;
  Node(int pos = 0, int val = 0) {
    this->pos = pos;
    this->val = val;
  }
  friend bool operator<(const Node &a, const Node &b) { return a.val > b.val; }
};
int deg[maxn];
int head[maxn];
int vis[maxn];
int fr;
void Insert(int x, int y, int val) {
  E[fr].node = y;
  E[fr].next = head[x];
  E[fr].val = val;
  head[x] = fr;
  fr++;
}
queue<int> q;
int n, m;
int dij(int root) {
  for (int i = 1; i <= n; i++) {
    d[i] = INF;
  }
  d[root] = 0;
  priority_queue<Node> que;
  while (!que.empty()) que.pop();
  Node st;
  st.pos = root;
  st.val = 0;
  que.push(st);
  while (!que.empty()) {
    Node fr = que.top();
    que.pop();
    int now = fr.pos;
    if (vis[now]) continue;
    vis[now] = 1;
    for (int i = head[now]; i != -1; i = E[i].next) {
      int nod = E[i].node;
      if (!vis[nod]) {
        int val = E[i].val;
        if (d[nod] > d[now] + val) {
          if (d[nod] != INF)
            return 1;
          else {
            d[nod] = d[now] + val;
            Node tmp;
            tmp.pos = nod;
            tmp.val = d[nod];
            que.push(tmp);
          }
        } else {
          if (d[nod] < d[now] + val) return 1;
        }
      }
    }
  }
  return 0;
}
int main() {
  scanf("%d%d", &n, &m);
  fr = 0;
  memset(head, -1, sizeof(head));
  memset(deg, 0, sizeof(deg));
  int Cnt = n;
  int flag = 0;
  for (int i = 0; i < m; i++) {
    scanf("%d%d%d", &a[i].l, &a[i].r, &a[i].d);
    if (a[i].d == 0) continue;
    Insert(a[i].l, a[i].r, a[i].d);
    if (mp1[a[i].l][a[i].r] == 0) {
      mp2[a[i].l][a[i].r] = a[i].d;
      mp1[a[i].l][a[i].r] = 1;
    } else {
      if (mp2[a[i].l][a[i].r] != a[i].d) flag = 1;
    }
    deg[a[i].r]++;
  }
  if (flag) {
    printf("No\n");
    return 0;
  }
  int Pos;
  vector<int> v;
  v.clear();
  while (!q.empty()) q.pop();
  for (int i = 1; i <= n; i++) {
    if (!deg[i]) {
      q.push(i);
      Pos = i;
      Cnt--;
    }
  }
  for (int i = 1; i <= n; i++) {
    if (!deg[i]) {
      if (i != Pos) v.push_back(i);
    }
  }
  while (!q.empty()) {
    int fr = q.front();
    q.pop();
    for (int i = head[fr]; i != -1; i = E[i].next) {
      int nod = E[i].node;
      deg[nod]--;
      if (deg[nod] == 0) {
        q.push(nod);
        Cnt--;
      }
    }
  }
  if (Cnt) {
    printf("No\n");
    return 0;
  }
  if (!dij(Pos)) {
    printf("Yes\n");
  } else {
    printf("No\n");
  }
}
