#include <bits/stdc++.h>
using ll = long long;
constexpr ll MOD = 1000000007;
using std::cin;
using std::cout;
using std::endl;
using std::list;
using std::map;
using std::multimap;
using std::multiset;
using std::pair;
using std::set;
using std::stack;
using std::string;
using std::unordered_map;
using std::unordered_multimap;
using std::unordered_set;
using std::vector;
ll gcd(ll a, ll b) { return b ? gcd(b, a % b) : a; }
ll lcm(ll a, ll b) { return a / gcd(a, b) * b; }
ll pow(ll a, ll b) {
  ll ans = 1;
  while (b > 0) {
    if (b % 2 == 1) {
      ans *= a;
      ans %= MOD;
    }
    b /= 2;
    a *= a;
    a %= MOD;
  }
  return ans;
}
ll comb(ll a, ll b) {
  if (a - b < b) {
    return comb(a, a - b);
  }
  ll c = 1;
  for (ll i = (ll)(a - b + 1); i < (ll)(a + 1); ++i) {
    c *= i;
    c %= MOD;
  }
  ll k = 1;
  for (ll i = (ll)(2); i < (ll)(b + 1); ++i) {
    k *= i;
    k %= MOD;
  }
  c *= pow(k, MOD - 2);
  return c % MOD;
}
multiset<ll> prime_decomposition(ll n) {
  ll i = 2;
  multiset<ll> table{};
  while (i * i <= n) {
    while (n % i == 0) {
      n /= i;
      table.emplace(i);
    }
    ++i;
  }
  if (n > 1) {
    table.emplace(n);
    return table;
  }
  return table;
}
struct edge {
  ll to;
  ll cost;
};
ll toCost(ll a, ll b, const unordered_multimap<ll, edge>& graph) {
  ll c = 0;
  stack<pair<ll, ll> > s;
  unordered_set<ll> memo;
  s.emplace(a, 0);
  while (!s.empty()) {
    auto f = s.top();
    s.pop();
    if (f.first == b) {
      return f.second;
    }
    if (memo.find(f.first) != memo.end()) {
      continue;
    }
    memo.emplace(f.first);
    auto path = graph.equal_range(f.first);
    for (auto itr = path.first; itr != path.second; ++itr) {
      if ((*itr).second.to != 0) {
        s.emplace((*itr).second.to, (*itr).second.cost + f.second);
      }
    }
  }
  return -1;
}
int main() {
  ll n, m;
  cin >> n >> m;
  unordered_multimap<ll, edge> graph;
  for (ll i = (ll)(0); i < (ll)(m); ++i) {
    ll l, r, d;
    cin >> l >> r >> d;
    ll c = toCost(l, r, graph);
    if (c != -1 && c != d) {
      cout << "No" << endl;
      return 0;
    }
    graph.emplace(l, edge{r, d});
    graph.emplace(r, edge{l, d});
  }
  cout << "Yes" << endl;
}
