#include <bits/stdc++.h>
using namespace std;
int toNumber(string s) {
  int Number;
  if (!(istringstream(s) >> Number)) Number = 0;
  return Number;
}
string toString(int number) {
  ostringstream ostr;
  ostr << number;
  return ostr.str();
}
long long ele(long long a, long long b) {
  if (b == 0) return 1;
  if (b % 2 == 0) {
    return ele((a * a), b / 2);
  } else {
    return a * ele((a * a), b / 2);
  }
}
long long mcd(long long a, long long b) {
  if (a == 0) return b;
  return mcd(b % a, a);
}
double d_abs(long a, long b) {
  if (a > b) {
    return a - b;
  }
  return b - a;
}
void solve(int caso) {
  int n, m;
  cin >> n >> m;
  vector<vector<pair<int, int> > > gr(n);
  for (int i = 0; i < (int)(m); i++) {
    int a, b, c;
    cin >> a >> b >> c;
    gr[a - 1].push_back(make_pair(b - 1, c));
  }
  vector<bool> vi(n, false);
  map<pair<int, int>, int> ma;
  for (int i = 0; i < (int)(n); i++) ma[make_pair(i, i)] = 0;
  for (int i = 0; i < (int)(n); i++) {
    queue<pair<pair<int, int>, int> > q;
    q.push(make_pair(make_pair(i, 0), 0));
    int dep = 0;
    while (!q.empty()) {
      pair<pair<int, int>, int> all = q.front();
      q.pop();
      pair<int, int> toy = all.first;
      if (all.second > 3) continue;
      for (int j = 0; j < (int)(gr[toy.first].size()); j++) {
        q.push(make_pair(make_pair(gr[toy.first][j].first,
                                   gr[toy.first][j].second + toy.second),
                         all.second + 1));
        pair<int, int> vec = make_pair(i, gr[toy.first][j].first);
        if (ma.find(make_pair(vec.second, vec.first)) != ma.end()) {
          cout << "No" << endl;
          return;
        }
        if (ma.find(vec) == ma.end()) {
          ma[vec] = gr[toy.first][j].second + toy.second;
        }
        if (ma[vec] != gr[toy.first][j].second + toy.second) {
          cout << "No" << endl;
          return;
        }
      }
    }
  }
  cout << "Yes\n";
}
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  int T;
  T = 1;
  for (int i = 0; i < (int)(T); i++) {
    solve(i);
  }
}
