#include <bits/stdc++.h>
using namespace std;
long long n, m;
bitset<100005> visited;
vector<pair<long long, long long>> AdjList[100005];
long long pos[100005];
vector<long long> postOrder;
void getPostOrder(long long u) {
  if (visited[u]) return;
  visited[u] = true;
  for (auto v : AdjList[u]) getPostOrder(v.second);
  postOrder.push_back(u);
}
vector<long long> topoSort;
void dfsTopoSort() {
  for (long long i = 1; i <= n; i++)
    if (!visited[i]) getPostOrder(i);
  topoSort = postOrder;
  reverse(topoSort.begin(), topoSort.end());
}
signed main() {
  cin >> n >> m;
  for (long long i = 0; i < m; i++) {
    long long l, r, d;
    cin >> l >> r >> d;
    AdjList[l].push_back({d, r});
    AdjList[r].push_back({d, l});
  }
  dfsTopoSort();
  memset(pos, -1, sizeof(pos));
  pos[topoSort[0]] = 0;
  bool ok = 1;
  for (auto u : topoSort) {
    for (auto v : AdjList[u]) {
      if (pos[v.second] != -1 && pos[v.second] != pos[u] + v.first) ok = 0;
      pos[v.second] = pos[u] + v.first;
    }
  }
  cout << (ok ? "Yes" : "No") << endl;
}
