#include <bits/stdc++.h>
using namespace std;
int n;
vector<int> e[1005];
int deg[1005];
pair<pair<int, int>, int> ed[1005];
vector<pair<pair<int, int>, int> > ad;
int gl(int cn, int p) {
  if (deg[cn] == 1) return cn;
  if (e[cn][0] != p)
    return gl(e[cn][0], cn);
  else
    return gl(e[cn][1], cn);
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cin >> n;
  if (n == 2) {
    int u, v, w;
    cin >> u >> v >> w;
    cout << "YES\n1\n";
    cout << u << " " << v << " " << w << "\n";
    return 0;
  }
  for (long long i = 0; i < (signed)(n - 1); i++) {
    int u, v, w;
    cin >> u >> v >> w;
    ed[i] = {{u, v}, w};
    e[u].push_back(v);
    e[v].push_back(u);
    deg[u]++;
    deg[v]++;
  }
  for (long long i = (1); i <= (signed)(n); i++) {
    if (deg[i] == 2) {
      cout << "NO\n";
      return 0;
    }
  }
  for (long long i = 0; i < (signed)(n - 1); i++) {
    int u = ed[i].first.first, v = ed[i].first.second;
    if (deg[u] > deg[v]) swap(u, v);
    int ch = ed[i].second / 2;
    if (deg[u] == 1) {
      vector<int> ok;
      for (auto nn : e[v])
        if (nn != u) {
          ok.push_back(gl(nn, v));
        }
      int x = ok[0], y = ok[1];
      ad.push_back({{u, x}, ch});
      ad.push_back({{u, y}, ch});
      ad.push_back({{x, y}, -ch});
    } else {
      vector<int> ok1;
      for (auto nn : e[u])
        if (nn != v) {
          ok1.push_back(gl(nn, u));
        }
      vector<int> ok2;
      for (auto nn : e[v])
        if (nn != u) {
          ok2.push_back(gl(nn, v));
        }
      int w = ok1[0], x = ok1[1], y = ok2[0], z = ok2[1];
      ad.push_back({{w, y}, ch});
      ad.push_back({{x, z}, ch});
      ad.push_back({{w, x}, -ch});
      ad.push_back({{y, z}, -ch});
    }
  }
  cout << "YES\n" << ad.size() << "\n";
  for (auto u : ad)
    cout << u.first.first << " " << u.first.second << " " << u.second << "\n";
  return 0;
}
