#include <bits/stdc++.h>
using namespace std;
int N, M, A, B, C, comp[100005], Size[100005], depth[100005], anc[20][100005],
    dist[20][100005];
vector<pair<int, int> > Graph[100005];
void Reroot(int node, int father, int cost) {
  depth[node] = 1 + depth[father];
  anc[0][node] = father;
  dist[0][node] = cost;
  for (int i = 1; i <= 17; i++) {
    anc[i][node] = anc[i - 1][anc[i - 1][node]];
    dist[i][node] = dist[i - 1][node] + dist[i - 1][anc[i - 1][node]];
  }
  for (int i = 0; i < Graph[node].size(); i++) {
    if (Graph[node][i].first != father)
      Reroot(Graph[node][i].first, node, Graph[node][i].second);
  }
}
int Find(int X) {
  int Y = X, t;
  while (Y != comp[Y]) Y = comp[Y];
  while (X != Y) {
    t = comp[X];
    comp[X] = Y;
    X = t;
  }
  return Y;
}
void Unite(int X, int Y, int C) {
  int x = X, y = Y;
  X = Find(X), Y = Find(Y);
  if (Size[X] > Size[Y]) {
    Size[X] += Size[Y];
    comp[Y] = X;
    Reroot(y, x, C);
  } else {
    Size[Y] += Size[X];
    comp[X] = Y;
    Reroot(x, y, -C);
  }
}
int Dist(int A, int B) {
  int Ans = 0;
  if (depth[A] > depth[B])
    for (int i = 17; i >= 0; i--)
      if (depth[A] - (1 << i) > depth[B]) {
        Ans += dist[i][A];
        A = anc[i][A];
      }
  if (depth[B] > depth[A])
    for (int i = 17; i >= 0; i--)
      if (depth[B] - (1 << i) > depth[A]) {
        Ans -= dist[i][B];
        B = anc[i][B];
      }
  if (A != B) {
    for (int i = 17; i >= 0; i--)
      if (anc[i][A] != anc[i][B]) {
        Ans += dist[i][B];
        Ans -= dist[i][A];
        B = anc[i][B];
        A = anc[i][A];
      }
  }
  if (A != B) Ans += dist[0][B] - dist[0][A];
  return Ans;
}
int main() {
  cin >> N >> M;
  for (int i = 1; i <= N; i++) {
    depth[i] = 1;
    comp[i] = i;
    Size[i] = 1;
  }
  for (int i = 1; i <= M; i++) {
    cin >> A >> B >> C;
    if (Find(A) != Find(B)) {
      Graph[A].push_back({B, C});
      Graph[B].push_back({A, -C});
      Unite(A, B, C);
    } else {
      if (C != Dist(A, B)) {
        cout << "No";
        return 0;
      }
    }
  }
  cout << "Yes";
  return 0;
}
