#include <bits/stdc++.h>
using namespace std;
int n, cnt = 1, root, tot, in[10010], id[10010], del[10010], head[10010];
struct Edge {
  int u, v, w, next;
} e[10010];
struct node {
  int u, v, w;
} d[10010];
void add(int u, int v, int w) {
  e[cnt].u = u;
  e[cnt].v = v;
  e[cnt].w = w;
  e[cnt].next = head[u];
  head[u] = cnt++;
}
void dfs(int u, int fa, int val) {
  if (in[u] == 1 && u != root) {
    id[u] = u;
    del[u] += -val;
    d[++tot].u = root;
    d[tot].v = u;
    d[tot].w = -val;
    return;
  }
  int pos1 = 0, pos2 = 0;
  for (int i = head[u]; i != -1; i = e[i].next) {
    int v = e[i].v;
    int w = e[i].w;
    if (v == fa) continue;
    dfs(v, u, w);
    del[u] += del[v];
    if (pos1 == 0)
      pos1 = id[v];
    else
      pos2 = id[v];
    id[u] = id[v];
  }
  if (u != root) {
    val += del[u];
    if (pos1 && pos2) {
      d[++tot].u = pos1;
      d[tot].v = pos2;
      d[tot].w = (val / 2);
      d[++tot].u = pos1;
      d[tot].v = root;
      d[tot].w = -(val / 2);
      d[++tot].u = pos2;
      d[tot].v = root;
      d[tot].w = -(val / 2);
      del[u] += -val;
    } else
      printf("NO\n"), exit(0);
  }
}
int main() {
  scanf("%d", &n);
  for (int i = 1; i <= n; i++) head[i] = -1;
  for (int i = 1; i <= n - 1; i++) {
    int x, y, z;
    scanf("%d%d%d", &x, &y, &z);
    add(x, y, z);
    add(y, x, z);
    in[x]++;
    in[y]++;
  }
  for (int i = 1; i <= n; i++) {
    if (in[i] == 1) {
      root = i;
      break;
    }
  }
  dfs(root, 0, 0);
  printf("YES\n%d\n", tot);
  for (int i = 1; i <= tot; i++) {
    printf("%d %d %d\n", d[i].u, d[i].v, -d[i].w);
  }
  return 0;
}
