#include <bits/stdc++.h>
using namespace std;
struct emp {
  int a, b, c;
};
struct emp1 {
  int a, b;
  bool operator<(const emp1 &x) const { return a > x.a; }
};
int n, m;
vector<vector<pair<int, int> > > net;
emp my[200005];
vector<pair<int, int> > indrg;
priority_queue<emp1> Q;
int dst[100005], cnt;
int chk[100005], chk_cnt[100005];
int is_in[100005];
void dfs(int c, int d) {
  int i;
  if (chk_cnt[c] == cnt) {
    if (dst[c] != d) {
      printf("No");
      exit(0);
    }
    return;
  }
  chk_cnt[c] = cnt;
  dst[c] = d;
  for (i = 0; i < net[c].size(); i++) {
    dfs(net[c][i].first, d + net[c][i].second);
  }
}
int main(void) {
  int i, j, x, y, z;
  emp1 curr;
  scanf("%d %d", &n, &m);
  net.resize(n + 5);
  indrg.resize(n + 5);
  for (i = 0; i < m; i++) {
    scanf("%d %d %d", &x, &y, &z);
    x--;
    y--;
    net[x].push_back(make_pair(y, z));
    indrg[y].first++;
    indrg[y].second = y;
    is_in[x] = is_in[y] = 1;
  }
  sort(indrg.begin(), indrg.end());
  for (i = 0; i < n; i++) {
    x = indrg[i].first;
    y = indrg[i].second;
    if (x > 0) break;
    cnt++;
    dfs(y, 1);
  }
  for (i = 0; i < n; i++) {
    if (is_in[i] == 1 && dst[i] == 0) break;
  }
  if (i >= n)
    printf("Yes");
  else
    printf("No");
  return 0;
}
