#include <bits/stdc++.h>
using namespace std;
const int maxn = 1024;
int n;
int a[maxn], b[maxn], c[maxn];
vector<int> g[maxn];
vector<pair<pair<int, int>, int> > ans;
void add(int v, int u, int x) { ans.push_back({{v, u}, x}); }
int gfs(int v, int par, int d) {
  if (g[v].size() == 1) return v;
  for (int i : g[v]) {
    int u = a[i] + b[i] - v;
    if (u != par and u != d) {
      int res = gfs(u, v, d);
      if (res != -1) return res;
    }
  }
  return -1;
}
pair<int, int> gpr(int v, int d) {
  pair<int, int> ret = {-1, -1};
  for (int i : g[v]) {
    int u = a[i] + b[i] - v;
    if (u != d) {
      int l = gfs(u, v, d);
      if (l != -1) {
        if (ret.first == -1)
          ret.first = l;
        else
          ret.second = l;
      }
    }
  }
  return ret;
}
void see(int v, int u, int x) {
  pair<int, int> vp = gpr(v, u);
  pair<int, int> up = gpr(u, v);
  add(vp.first, up.first, x / 2);
  add(vp.second, up.second, x / 2);
  add(vp.first, vp.second, -x / 2);
  add(up.first, up.second, -x / 2);
}
void zee(int v, int d, int x) {
  pair<int, int> vp = gpr(d, v);
  add(vp.first, v, x / 2);
  add(vp.second, v, x / 2);
  add(vp.first, vp.second, -x / 2);
}
void dfs(int v, int par = -1, int lst = -1, int x = 0) {
  if (g[v].size() > 2) {
    if (lst != -1) see(v, lst, x);
    lst = v;
  } else if (g[v].size() == 1) {
    zee(v, lst, x);
  }
  for (int i : g[v]) {
    int u = a[i] + b[i] - v;
    if (u != par) {
      dfs(u, v, lst, c[i]);
    }
  }
}
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cin >> n;
  for (int i = 0; i < n - 1; i++) {
    cin >> a[i] >> b[i] >> c[i];
    a[i]--, b[i]--;
    g[a[i]].push_back(i);
    g[b[i]].push_back(i);
  }
  for (int i = 0; i < n; i++)
    if (g[i].size() == 2) {
      if (c[g[i][0]] != c[g[i][1]]) {
        cout << "NO" << endl;
        return 0;
      }
    }
  cout << "YES" << endl;
  vector<int> lv;
  int r = -1;
  for (int i = 0; i < n; i++)
    if (g[i].size() > 2)
      r = i;
    else if (g[i].size() == 1)
      lv.push_back(i);
  if (r == -1) {
    cout << 1 << endl;
    cout << lv[0] + 1 << " " << lv[1] + 1 << " " << c[0] << endl;
    return 0;
  }
  dfs(r);
  cout << ans.size() << endl;
  for (auto p : ans)
    cout << p.first.first + 1 << " " << p.first.second + 1 << " " << p.second
         << "\n";
  return 0;
}
