#include <bits/stdc++.h>
using namespace std;
const long long maxn = 1e3 + 10;
struct node {
  long long u, v, w;
} a[maxn];
struct edge {
  long long to, nxt;
} e[maxn << 1];
long long n, tot, cnt, top, head[maxn], deg[maxn], f[maxn], sta[maxn],
    ans[maxn][maxn];
bool flag = 0;
long long read() {
  long long x = 0, f = 1;
  char ch = getchar();
  while (ch < '0' || ch > '9') {
    if (ch == '-') f = -1;
    ch = getchar();
  }
  while (ch >= '0' && ch <= '9') {
    x = x * 10 + ch - '0';
    ch = getchar();
  }
  return x * f;
}
void print(long long x) {
  if (x < 0) putchar('-'), x = -x;
  if (x > 9) print(x / 10);
  putchar(x % 10 + '0');
}
void write(long long x) {
  print(x);
  puts("");
}
void add(long long u, long long v) {
  e[++tot].to = v;
  e[tot].nxt = head[u];
  head[u] = tot;
  deg[v]++;
}
void insert(long long u, long long v) {
  add(u, v);
  add(v, u);
}
long long dfs(long long id, long long x, long long fa, long long ed) {
  sta[++top] = x;
  if (deg[x] == 1 && !f[x] && !flag && (fa == id || !f[fa])) {
    long long now = top;
    while (now) f[sta[now--]] = 1;
    f[x] = 1;
    flag = 1;
    return x;
  }
  for (long long i = head[x], v = e[i].to; i; i = e[i].nxt, v = e[i].to)
    if (v != fa && v != ed && !f[v]) return dfs(id, v, x, ed);
  top--;
}
signed main() {
  n = read();
  for (long long i = 1; i < n; i++) a[i] = (node){read(), read(), read()};
  for (long long i = 1; i < n; i++) insert(a[i].u, a[i].v);
  for (long long i = 1; i <= n; i++)
    if (deg[i] == 2) {
      puts("NO");
      return 0;
    }
  for (long long i = 1; i < n; i++) {
    long long u = a[i].u, v = a[i].v, w = a[i].w;
    long long flag1 = (deg[u] == 1), flag2 = (deg[v] == 1);
    if (flag1 && flag2) ans[u][v] += w, ans[v][u] += w;
    if (flag1 && !flag2) {
      long long x = dfs(v, v, 0, u);
      flag = 0;
      top = 0;
      long long y = dfs(v, v, 0, u);
      flag = 0;
      top = 0;
      ans[u][x] += w / 2;
      ans[u][y] += w / 2;
      ans[x][y] += -w / 2;
      ans[x][u] += w / 2;
      ans[y][u] += w / 2;
      ans[y][x] += -w / 2;
      memset(f, 0, sizeof(f));
    }
    if (!flag1 && flag2) {
      long long x = dfs(u, u, 0, v);
      flag = 0;
      top = 0;
      long long y = dfs(u, u, 0, v);
      flag = 0;
      top = 0;
      ans[v][x] += w / 2;
      ans[v][y] += w / 2;
      ans[x][y] += -w / 2;
      ans[x][v] += w / 2;
      ans[y][v] += w / 2;
      ans[y][x] += -w / 2;
      memset(f, 0, sizeof(f));
    }
    if (!flag1 && !flag2) {
      long long x1 = dfs(u, u, 0, v);
      flag = 0;
      top = 0;
      long long y1 = dfs(u, u, 0, v);
      flag = 0;
      top = 0;
      long long x2 = dfs(v, v, 0, u);
      flag = 0;
      top = 0;
      long long y2 = dfs(v, v, 0, u);
      flag = 0;
      top = 0;
      ans[x1][x2] += w / 2;
      ans[y1][y2] += w / 2;
      ans[x1][y1] += -w / 2;
      ans[x2][y2] += -w / 2;
      ans[x2][x1] += w / 2;
      ans[y2][y1] += w / 2;
      ans[y1][x1] += -w / 2;
      ans[y2][x2] += -w / 2;
      memset(f, 0, sizeof(f));
    }
  }
  puts("YES");
  for (long long i = 1; i <= n; i++)
    for (long long j = i + 1; j <= n; j++)
      if (ans[i][j]) cnt++;
  write(cnt);
  for (long long i = 1; i <= n; i++)
    for (long long j = i + 1; j <= n; j++)
      if (ans[i][j]) printf("%lld %lld %lld\n", i, j, ans[i][j]);
  return 0;
}
