#include <bits/stdc++.h>
using namespace std;
int n, v[5010], w[5010], nxt[5010], h[5010], d[5010], ec, va, f[5010], ct,
    bk[5010], rt, sz, x[5010], y[5010], z[5010];
vector<vector<int>> lv;
void add(int x, int y, int z) {
  v[++ec] = y;
  w[ec] = z;
  nxt[ec] = h[x];
  h[x] = ec;
}
void dfs1(int x, int fa) {
  f[x] = fa;
  for (int i = h[x]; i; i = nxt[i])
    if (v[i] != fa) {
      dfs1(v[i], x);
      lv[x].push_back(lv[v[i]][0]);
    }
  if (!lv[x].size()) lv[x].push_back(x);
}
void adt(int a, int b, int c) {
  x[++sz] = a;
  y[sz] = b;
  z[sz] = c;
}
void adv(int v, int x) {
  if (lv[v].size() == 1) {
    adt(rt, v, x);
    return;
  }
  adt(rt, lv[v][0], x / 2);
  adt(rt, lv[v][1], x / 2);
  adt(lv[v][1], lv[v][0], -x / 2);
}
void adj(int v, int x) {
  if (f[v] == rt) {
    adv(v, x);
    return;
  }
  adv(v, x);
  adv(f[v], -x);
}
void dfs2(int x, int fa) {
  for (int i = h[x]; i; i = nxt[i])
    if (v[i] != fa) {
      adj(v[i], w[i]);
      dfs2(v[i], x);
    }
}
int main() {
  scanf("%d", &n);
  lv.resize(n + 5);
  for (int i = 1; i < n; i++) {
    int x, y, z;
    scanf("%d%d%d", &x, &y, &z);
    d[x]++;
    d[y]++;
    add(x, y, z);
    add(y, x, z);
    va = z;
  }
  if (n == 2) {
    printf("YES 1\n");
    printf("1 2 %d\n", va);
    return 0;
  }
  for (int i = 1; i < n; i++)
    if (d[i] == 2) {
      printf("NO\n");
      return 0;
    }
  for (int i = 1; i <= n; i++)
    if (d[i] == 1) {
      rt = i;
      dfs1(i, 0);
      dfs2(i, 0);
      break;
    }
  printf("YES %d\n", sz);
  for (int i = 1; i <= sz; i++) printf("%d %d %d\n", x[i], y[i], z[i]);
}
