#include <bits/stdc++.h>
using namespace std;
int deg[1005];
struct edge {
  int u, v, w;
} e[2005];
int head[1005], nxt[2005], cnt;
void addnode(int u, int v, int w) {
  e[++cnt] = (edge){u, v, w};
  nxt[cnt] = head[u];
  head[u] = cnt;
}
int x[1005 * 1005], y[1005 * 1005], v[1005 * 1005], m;
int b[1005];
void dfs(int rt, int u, int f) {
  if (deg[u] == 1) return (void)(b[u] = rt);
  b[u] = 0;
  for (int i = head[u]; i; i = nxt[i])
    if (e[i].v != f) dfs(rt, e[i].v, u);
}
void addedge(int a, int b, int c) {
  ++m;
  x[m] = a;
  y[m] = b;
  v[m] = c;
}
int n;
void addpath(int u, int l, int x) {
  if (u == l) return;
  if (deg[u] == 1) return addedge(u, l, x);
  b[u] = 0;
  for (int i = head[u]; i; i = nxt[i]) dfs(e[i].v, e[i].v, u);
  int l1 = 0, l2 = 0;
  for (int i = 1; i <= n; i++)
    if (deg[i] == 1 && b[i] != b[l] && !l2) {
      if (!l1)
        l1 = i;
      else if (b[i] != b[l1])
        l2 = i;
    }
  addedge(l, l1, x / 2);
  addedge(l, l2, x / 2);
  addedge(l1, l2, -x / 2);
}
int lv[1005];
void DFS(int u, int f) {
  if (deg[u] == 1 && f) return (void)(lv[u] = u);
  for (int i = head[u]; i; i = nxt[i])
    if (e[i].v != f) {
      DFS(e[i].v, u);
      lv[u] = lv[e[i].v];
      addpath(u, lv[u], e[i].w);
      addpath(e[i].v, lv[e[i].v], -e[i].w);
    }
}
int main() {
  scanf("%d", &n);
  for (int i = 1; i < n; i++) {
    int u, v, w;
    scanf("%d%d%d", &u, &v, &w);
    ++deg[u];
    ++deg[v];
    addnode(u, v, w);
    addnode(v, u, w);
  }
  for (int i = 1; i <= n; i++)
    if (deg[i] == 2) {
      puts("NO");
      return 0;
    }
  puts("YES");
  DFS(1, 0);
  printf("%d\n", m);
  for (int i = 1; i <= m; i++) printf("%d %d %d\n", x[i], y[i], v[i]);
  return 0;
}
