#include <bits/stdc++.h>
using namespace std;
const int maxn = 1005;
struct node {
  int u, v, val;
} ans[maxn * 10];
std::vector<int> g[maxn];
int n, tot;
int in[maxn];
int x[maxn], y[maxn], val[maxn];
void addedge(int u, int v, int val) { ans[++tot] = (node){u, v, val}; }
void find(int u, int fa, int &x3, int &x4) {
  if (g[u].size() == 1) {
    if (x3 == 0)
      x3 = u;
    else
      x4 = u;
    return;
  } else
    for (int i = 0; i < g[u].size(); i++) {
      if (g[u][i] == fa) continue;
      find(g[u][i], u, x3, x4);
    }
}
int main() {
  scanf("%d", &n);
  if (n == 2) {
    printf("YES\n1\n");
    int x, y, k;
    scanf("%d%d%d", &x, &y, &k);
    printf("%d %d %d\n", x, y, k);
    return 0;
  }
  for (int i = 1; i < n; i++) {
    scanf("%d%d%d", &x[i], &y[i], &val[i]);
    g[x[i]].push_back(y[i]);
    g[y[i]].push_back(x[i]);
    in[x[i]]++;
    in[y[i]]++;
  }
  for (int i = 1; i <= n; i++)
    if (in[i] == 2) return !printf("NO\n");
  printf("YES\n");
  for (int k = 1; k < n; k++) {
    if (in[x[k]] > in[y[k]]) swap(x[k], y[k]);
    if (in[x[k]] == 1) {
      int x4 = 0, x1 = 0, x2 = 0, x5 = 0, x3 = 0;
      x1 = y[k];
      x3 = x[k];
      find(x1, x3, x4, x5);
      addedge(x3, x4, val[k] / 2);
      addedge(x3, x5, val[k] / 2);
      addedge(x4, x5, -val[k] / 2);
    } else {
      int x1 = 0, x2 = 0, x3 = 0, x4 = 0, x5 = 0, x6 = 0;
      x1 = x[k];
      x2 = y[k];
      find(x1, x2, x3, x4);
      find(x2, x1, x5, x6);
      addedge(x3, x5, val[k] / 2);
      addedge(x4, x6, val[k] / 2);
      addedge(x3, x4, -val[k] / 2);
      addedge(x5, x6, -val[k] / 2);
    }
  }
  printf("%d\n", tot);
  for (int i = 1; i <= tot; i++) {
    printf("%d %d %d\n", ans[i].u, ans[i].v, ans[i].val);
  }
}
