#include <bits/stdc++.h>
constexpr long long mod = static_cast<long long>(1e9 + 7);
struct Edge {
  int to;
  int w;
};
void hasCycleHelper(int i, std::vector<std::pair<int, int>>& memo,
                    const std::vector<std::vector<Edge>>& edges, int& cnt) {
  memo[i].first = cnt;
  ++cnt;
  for (auto edge : edges[i]) {
    if (memo[edge.to].first < 0) hasCycleHelper(edge.to, memo, edges, cnt);
  }
  ++cnt;
  memo[i].second = cnt;
}
bool hasCycle(const std::vector<std::vector<Edge>>& edges) {
  std::vector<std::pair<int, int>> memo(edges.size(), std::make_pair(-1, -1));
  for (int i = 0; i < memo.size(); ++i) {
    int cnt = 0;
    if (memo[i].first < 0) {
      hasCycleHelper(i, memo, edges, cnt);
      ++cnt;
    }
  }
  for (int i = 0; i < edges.size(); ++i) {
    for (auto edge : edges[i]) {
      if (memo[edge.to].first < memo[i].first &&
          memo[i].second < memo[edge.to].second)
        return true;
    }
  }
  return false;
}
int main() {
  int N, M;
  std::cin >> N >> M;
  std::vector<std::vector<Edge>> edges(N, std::vector<Edge>());
  std::vector<int> counts(N, 0);
  while (M--) {
    int l, r, d;
    std::cin >> l >> r >> d;
    --l;
    --r;
    ++counts[r];
    edges[l].push_back(Edge{r, d});
  }
  if (hasCycle(edges)) {
    std::cout << "No" << std::endl;
  } else {
    bool ans = true;
    for (int i = 0; i < N; ++i) {
      if (counts[i] == 0 && !edges[i].empty()) {
        std::vector<long long> memo(N, std::numeric_limits<long long>::max());
        memo[i] = 0;
        std::queue<std::pair<int, long long>> que;
        que.push(std::make_pair(i, 0));
        while (!que.empty() && ans) {
          auto now = que.front();
          que.pop();
          int v = now.first;
          long long w = now.second;
          for (auto edge : edges[v]) {
            if (memo[edge.to] == std::numeric_limits<long long>::max()) {
              memo[edge.to] = edge.w + w;
              que.push(std::make_pair(edge.to, w + edge.w));
            } else {
              if (memo[edge.to] != edge.w + w) {
                ans = false;
                break;
              }
            }
          }
        }
      }
    }
    if (ans)
      std::cout << "Yes" << std::endl;
    else
      std::cout << "No" << std::endl;
  }
  return 0;
}
