#include <bits/stdc++.h>
using namespace std;
const long long inf = 1e9;
const long long inf64 = 1e18;
const long long MOD = inf + 7;
const long long N = 2e5 + 5;
vector<pair<long long, long long> > g[N];
long long vis[N];
void dfs(long long node, long long par, long long val) {
  vis[node] = 1;
  for (auto it : g[node]) {
    long long u = it.first;
    long long c = it.second;
    if (!vis[u]) {
      dfs(u, node, val + c);
    } else if (u != par && val + c != 0 && vis[u] == 1) {
      cout << "No";
      exit(0);
    }
  }
  vis[node] = 2;
}
int32_t main() {
  ios::sync_with_stdio(false), cin.tie(nullptr);
  ;
  long long n, m;
  cin >> n >> m;
  for (long long i = 0; i < (long long)m; i++) {
    long long u, v, c;
    cin >> u >> v >> c;
    g[u].push_back({v, c});
    g[v].push_back({u, -c});
  }
  for (long long i = 1; i <= n; i++)
    if (!vis[i]) dfs(i, 0, 0);
  cout << "Yes";
}
