#include <bits/stdc++.h>
using namespace std;
const int MAX_N = 100005;
struct edge {
  int to, cost;
};
vector<edge> G[MAX_N];
int d[MAX_N];
set<pair<pair<int, int>, int> > st;
int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  int n, m;
  cin >> n >> m;
  for (int i = 0; i < (int)(m); ++i) {
    int a, b, c;
    cin >> a >> b >> c;
    G[a - 1].push_back((edge){b - 1, c}), G[b - 1].push_back((edge){a - 1, c});
  }
  for (int i = 0; i < (int)(n); ++i) {
    d[i] = INT_MAX;
  }
  for (int i = 0; i < (int)(n); ++i) {
    if (d[i] == INT_MAX) {
      queue<int> que;
      que.push(i);
      d[i] = 0;
      while (!que.empty()) {
        int p = que.front();
        que.pop();
        for (auto v : G[p]) {
          if (st.find(pair<pair<int, int>, int>(
                  pair<int, int>(min(p, v.to), max(p, v.to)), v.cost)) ==
              st.end()) {
            st.insert(pair<pair<int, int>, int>(
                pair<int, int>(min(p, v.to), max(p, v.to)), v.cost));
            if (d[v.to] == INT_MAX) {
              d[v.to] = d[p] + v.cost;
              que.push(v.to);
            } else if (d[v.to] != d[p] + v.cost) {
              cout << "No\n";
              return 0;
            }
          }
        }
      }
    }
  }
  cout << "Yes\n";
  return 0;
}
