#include <bits/stdc++.h>
using namespace std;
int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  int n, m;
  cin >> n >> m;
  int l[m], r[m], d[m];
  for (int i = 0; i < m; i++) cin >> l[i] >> r[i] >> d[i];
  vector<pair<int, int> > info[n];
  for (int i = 0; i < m; i++) {
    info[l[i] - 1].push_back(pair<int, int>(r[i] - 1, d[i]));
    info[r[i] - 1].push_back(pair<int, int>(l[i] - 1, -d[i]));
  }
  int x[n];
  memset(x, -1, sizeof(x));
  queue<int> q;
  x[0] = (int)1e9;
  q.push(0);
  string res = "Yes";
  while (q.size()) {
    int v = q.front();
    q.pop();
    for (auto p : info[v]) {
      int u = p.first;
      if (x[u] == -1) {
        x[u] = x[v] + p.second;
        q.push(u);
      } else {
        if (x[u] != x[v] + p.second) {
          cout << "No"
               << "\n";
          return 0;
        }
      }
    }
  }
  cout << res << "\n";
  for (int i = 0; i < 3; i++) {
    cout << x[i] << "\n";
  }
  for (int i = 0; i < m; i++) {
    for (auto p : info[i]) cout << p.first << " " << p.second << "\n";
  }
  return 0;
}
