#include <bits/stdc++.h>
using namespace std;
int n, m, a, b, c, cur;
int dp[100005], vis[100005], in[100005], sit[100005], tut[100005];
stack<int> s;
vector<pair<int, int> > v[100005];
void fail() {
  printf("No");
  exit(0);
}
void dfs2(int node) {
  if (vis[node]) return;
  vis[node] = 1;
  for (pair<int, int> i : v[node]) {
    in[i.first]--;
    if (!dp[i.first] || tut[i.first] != cur)
      dp[i.first] = dp[node] + i.second, tut[i.first] = cur;
    else if (dp[i.first] != dp[node] + i.second)
      fail();
    if (!in[i.first]) dfs2(i.first);
  }
}
void dfs(int node) {
  if (vis[node]) return;
  vis[node] = 1;
  for (pair<int, int> i : v[node]) {
    dfs(i.first);
  }
  s.push(node);
}
void cyc(int node) {
  if (vis[node]) {
    if (sit[node]) fail();
    return;
  }
  sit[node] = 1;
  vis[node] = 1;
  for (pair<int, int> i : v[node]) {
    cyc(i.first);
  }
  sit[node] = 0;
}
int main() {
  scanf("%d %d", &n, &m);
  for (int i = 1; i <= m; i++) {
    scanf("%d %d %d", &a, &b, &c);
    v[b].push_back({a, c});
    in[a]++;
  }
  for (int i = 1; i <= n; i++)
    if (!vis[i]) cyc(i);
  memset(vis, 0, sizeof(vis));
  for (int i = 1; i <= n; i++) {
    dfs(i);
  }
  memset(vis, 0, sizeof(vis));
  while (((int)s.size())) {
    ++cur;
    dfs2(s.top());
    s.pop();
  }
  printf("Yes");
}
