#include <bits/stdc++.h>
using namespace std;
inline int read() {
  int x = 0, f = 1;
  char c = getchar();
  for (; !isdigit(c); c = getchar())
    if (c == '-') f = -1;
  for (; isdigit(c); c = getchar()) x = x * 10 + c - '0';
  return x * f;
}
const int MAXN = 10010;
int Node[MAXN], Next[MAXN], Root[MAXN], Deg[MAXN];
int cnte;
int L[MAXN], R[MAXN];
int N, Ans;
inline void insert(int x, int y) {
  Node[++cnte] = y;
  Next[cnte] = Root[x];
  Root[x] = cnte;
  Deg[x]++;
}
inline int Findl(int x, int Fa) {
  for (int i = Root[x]; i; i = Next[i]) {
    int y = Node[i];
    if (y != Fa) return Findl(y, x);
  }
  return x;
}
struct data {
  int x, y, z;
} e[MAXN], ans[MAXN];
int main() {
  N = read();
  for (int i = 1; i < N; i++) {
    e[i].x = read();
    e[i].y = read();
    e[i].z = read();
    insert(e[i].x, e[i].y);
    insert(e[i].y, e[i].x);
  }
  if (N == 2) {
    puts("YES");
    puts("1");
    printf("%d %d %d\n", e[1].x, e[1].y, e[1].z);
    return 0;
  }
  int cntL, cntR;
  for (int i = 1; i < N; i++) {
    int x = e[i].x, y = e[i].y, z = e[i].z;
    if (Deg[x] == 2 || Deg[y] == 2) {
      puts("NO");
      return 0;
    }
    if (Deg[y] == 1) swap(x, y);
    if (Deg[x] == 1) {
      cntR = 0;
      for (int j = Root[y]; j; j = Next[j])
        if (Node[j] != x) R[++cntR] = Findl(Node[j], y);
      ans[++Ans] = (data){x, R[1], z / 2};
      ans[++Ans] = (data){x, R[2], z / 2};
      ans[++Ans] = (data){R[1], R[2], -z / 2};
      continue;
    }
    cntL = cntR = 0;
    for (int j = Root[x]; j; j = Next[j])
      if (Node[j] != y) L[++cntL] = Findl(Node[j], x);
    for (int j = Root[y]; j; j = Next[j])
      if (Node[j] != x) R[++cntR] = Findl(Node[j], y);
    ans[++Ans] = (data){L[1], L[2], -z / 2};
    ans[++Ans] = (data){R[1], R[2], -z / 2};
    ans[++Ans] = (data){L[1], R[1], z / 2};
    ans[++Ans] = (data){L[2], R[2], z / 2};
  }
  puts("YES");
  printf("%d\n", Ans);
  for (int i = 1; i <= Ans; i++)
    printf("%d %d %d\n", ans[i].x, ans[i].y, ans[i].z);
  return 0;
}
