#include <bits/stdc++.h>
using namespace std;
const int MAXM = 100005;
const int MAXN = 1005;
int n, ui[MAXN], vi[MAXN], val[MAXN], d[MAXN];
int ru[MAXM], rv[MAXM], rx[MAXM];
vector<int> a, b, g[MAXN];
int findleave(int u, int parent) {
  if (g[u].size() == 1) return u;
  for (int v : g[u]) {
    if (v == parent) continue;
    return findleave(v, u);
  }
}
int main() {
  scanf("%d", &n);
  for (int i = 0; i < n - 1; i++) {
    scanf("%d %d %d", &ui[i], &vi[i], &val[i]);
    ui[i]--, vi[i]--;
    d[ui[i]]++;
    d[vi[i]]++;
    g[ui[i]].push_back(vi[i]);
    g[vi[i]].push_back(ui[i]);
  }
  int c1 = 0, c2 = 0, cg = 0;
  for (int i = 0; i < n; i++) {
    if (d[i] == 1)
      c1++;
    else if (d[i] == 2)
      c2++;
    else
      cg++;
  }
  if (c2 > 0)
    printf("NO\n");
  else {
    printf("YES\n");
    if (n == 2) {
      printf("1\n1 2 %d\n", val[0]);
    } else {
      int m = 0;
      for (int i = 0; i < n - 1; i++) {
        if (g[ui[i]].size() == 1)
          a.push_back(ui[i]);
        else {
          for (int v : g[ui[i]]) {
            if (v == vi[i]) continue;
            a.push_back(findleave(v, ui[i]));
          }
        }
        if (g[vi[i]].size() == 1)
          b.push_back(vi[i]);
        else {
          for (int u : g[vi[i]]) {
            if (u == ui[i]) continue;
            b.push_back(findleave(u, vi[i]));
          }
        }
        if (a.size() < b.size()) swap(a, b);
        if (b.size() == 1) {
          ru[m] = a[0];
          rv[m] = a[1];
          rx[m] = -val[i] / 2;
          m++;
          ru[m] = a[1];
          rv[m] = b[0];
          rx[m] = val[i] / 2;
          m++;
          ru[m] = b[0];
          rv[m] = a[0];
          rx[m] = val[i] / 2;
          m++;
        } else {
          ru[m] = a[0];
          rv[m] = a[1];
          rx[m] = -val[i] / 2;
          m++;
          ru[m] = a[1];
          rv[m] = b[0];
          rx[m] = val[i] / 2;
          m++;
          ru[m] = b[0];
          rv[m] = b[1];
          rx[m] = -val[i] / 2;
          m++;
          ru[m] = b[1];
          rv[m] = a[0];
          rx[m] = val[i] / 2;
          m++;
        }
        a.clear();
        b.clear();
      }
      printf("%d\n", m);
      for (int i = 0; i < m; i++)
        printf("%d %d %d\n", ru[i] + 1, rv[i] + 1, rx[i]);
    }
  }
  return 0;
}
