#include <bits/stdc++.h>
using namespace std;
inline int read() {
  int x = 0, f = 1;
  char ch = getchar();
  for (; !isdigit(ch); ch = getchar()) {
    if (ch == '-') f = -1;
  }
  for (; isdigit(ch); ch = getchar()) {
    x = x * 10 + ch - 48;
  }
  return x * f;
}
const int mxN = 1000;
struct Edge {
  int v, nxt;
  long long w;
} e[(mxN << 1) + 3];
int fe[mxN + 3];
long long a[mxN + 3];
int du[mxN + 3];
int fa[mxN + 3];
int u1[mxN + 3], u2[mxN + 3];
struct Operation {
  int u, v;
  long long w;
};
vector<Operation> ans;
int n, en, rt;
void addedge(int u, int v, int w) {
  en++;
  e[en].v = v, e[en].w = w;
  e[en].nxt = fe[u];
  fe[u] = en;
}
void dfs1(int u) {
  if (u != rt && du[u] == 1) {
    u1[u] = u;
    ans.push_back((Operation){rt, u, a[u]});
    return;
  }
  long long x = a[u];
  for (int i = fe[u]; i; i = e[i].nxt) {
    int v = e[i].v;
    if (v == fa[u]) continue;
    fa[v] = u;
    a[v] = e[i].w;
    dfs1(v);
    x -= a[v];
    if (!u1[u]) {
      u1[u] = u1[v];
    } else if (!u2[u]) {
      u2[u] = u1[v];
    }
  }
  if (u != rt) {
    ans.push_back((Operation){rt, u1[u], x / 2});
    ans.push_back((Operation){rt, u2[u], x / 2});
    ans.push_back((Operation){u1[u], u2[u], -x / 2});
  }
}
int main() {
  n = read();
  for (int i = 1; i < n; i++) {
    int u = read(), v = read(), w = read();
    addedge(u, v, w), addedge(v, u, w);
    du[u]++, du[v]++;
  }
  for (int i = 1; i <= n; i++) {
    if (du[i] == 2) {
      puts("NO");
      return 0;
    }
  }
  for (int i = 1; i <= n; i++) {
    if (du[i] == 1) {
      rt = i;
      break;
    }
  }
  dfs1(rt);
  puts("YES");
  printf("%d\n", ans.size());
  for (int i = 0; i < ans.size(); i++)
    printf("%d %d %I64d\n", ans[i].u, ans[i].v, ans[i].w);
  return 0;
}
