#include <bits/stdc++.h>
long long int N, M;
std::vector<long long int> pos, G[112345], memo(112345), tmp(112345);
std::vector<std::pair<std::pair<long long int, long long int>, long long int>>
    dat;
std::vector<std::pair<long long int, long long int>> cou;
std::vector<bool> vis(112345);
bool flag = true;
long long int dfs(long long int p) {
  if (memo[p] != -1) return memo[p];
  if (vis[p]) {
    flag = false;
    return 0;
  }
  long long int res = 0;
  vis[p] = true;
  for (auto v : G[p]) res += dfs(v) + 1;
  return memo[p] = res;
}
int main() {
  std::cin >> N >> M;
  dat.resize(M);
  pos.resize(N + 1);
  for (int i = 0; i < M; ++i) {
    std::cin >> dat[i].first.first >> dat[i].first.second >> dat[i].second;
  }
  std::fill(memo.begin(), memo.end(), -1);
  for (int i = 0; i < M; ++i) {
    G[dat[i].first.first].push_back(dat[i].first.second);
  }
  for (int i = 0; i < N; ++i) {
    cou.push_back(std::make_pair(dfs(i + 1), i + 1));
  }
  if (!flag) {
    std::cout << "No" << std::endl;
    return 0;
  }
  std::sort(cou.begin(), cou.end(),
            std::greater<std::pair<long long int, long long int>>());
  for (int i = 0; i < N; ++i) {
    tmp[cou[i].second] = i + 1;
  }
  for (int i = 0; i < M; ++i) {
    dat[i].first.first = tmp[dat[i].first.first];
    dat[i].first.second = tmp[dat[i].first.second];
  }
  std::sort(dat.begin(), dat.end());
  std::fill(pos.begin(), pos.end(), -1);
  if (M > 0) {
    for (int i = 0; i < M; ++i) {
      auto l = dat[i].first.first, r = dat[i].first.second, d = dat[i].second;
      if (pos[r] == -1 || pos[l] == -1 || (pos[r] - pos[l]) == d) {
        if (pos[r] == -1 && pos[l] == -1) {
          pos[l] = 0;
          pos[r] = pos[l] + d;
        } else if (pos[l] == -1) {
          pos[l] = pos[r] - d;
        } else if (pos[r] == -1) {
          pos[r] = pos[l] + d;
        }
      } else {
        std::cout << "No" << std::endl;
        return 0;
      }
    }
  }
  std::cout << "Yes" << std::endl;
  return 0;
}
