#include <bits/stdc++.h>
using namespace std;
const int sj = 10010;
int n, h[sj], e, tot, f[sj * 3], t[sj * 3], vl[sj * 3], d[sj], rt;
bool op;
struct B {
  int ne, v, w;
} b[sj << 1];
void add(int x, int y, int z) {
  b[e].v = y, b[e].w = z, b[e].ne = h[x], h[x] = e++;
  b[e].v = x, b[e].w = z, b[e].ne = h[y], h[y] = e++;
  d[x]++, d[y]++;
}
int dfs(int x, int fa, int sum) {
  if (op) return 0;
  if (x != rt && d[x] == 1) {
    ++tot;
    f[tot] = rt, t[tot] = x, vl[tot] = sum;
    return x;
  }
  int ret = 0, son1 = 0, son2 = 0;
  for (int i = h[x]; i != -1; i = b[i].ne) {
    if (b[i].v == fa) continue;
    if (d[x] == 2 && b[i].w != sum) {
      op = 1;
      return 0;
    }
    ret += b[i].w;
    if (son1)
      son2 = dfs(b[i].v, x, b[i].w);
    else
      son1 = dfs(b[i].v, x, b[i].w);
    if (op) return 0;
  }
  if (x == rt) return 0;
  if (sum != ret) {
    if ((sum & 1) != (ret & 1)) {
      op = 1;
      return 0;
    }
    f[++tot] = son1, t[tot] = son2, vl[tot] = (ret - sum) / 2;
    f[++tot] = son1, t[tot] = rt, vl[tot] = (sum - ret) / 2;
    f[++tot] = son2, t[tot] = rt, vl[tot] = (sum - ret) / 2;
  }
  return son1;
}
int main() {
  scanf("%d", &n);
  memset(h, -1, sizeof(h));
  for (int i = 1; i < n; ++i) {
    int a1, a2, a3;
    scanf("%d%d%d", &a1, &a2, &a3);
    add(a1, a2, a3);
  }
  for (int i = 1; i <= n; ++i)
    if (d[i] == 1) {
      rt = i;
      dfs(i, 0, 0);
      break;
    }
  if (op)
    printf("NO");
  else {
    printf("YES\n%d\n", tot);
    for (int i = 1; i <= tot; ++i) printf("%d %d %d\n", f[i], t[i], vl[i]);
  }
  return 0;
}
