#include <bits/stdc++.h>
using namespace std;
const int N = 1010;
struct EDGE {
  int from, to, val, next;
} e[N * 2];
int a[N * 5], b[N * 5], c[N * 5], head[N], vis[N], fa[N], deg[N], leaf[N][5];
int n, cnt, s, rt;
void addedge(int u, int v, int w) {
  e[++cnt].from = u;
  e[cnt].to = v;
  e[cnt].val = w;
  e[cnt].next = head[u];
  head[u] = cnt;
}
void dfs(int x) {
  vis[x] = 1;
  int now = 0;
  for (int i = head[x]; i; i = e[i].next) {
    if (vis[e[i].to]) continue;
    dfs(e[i].to);
    fa[e[i].to] = x;
    if (now < 2) leaf[x][++now] = leaf[e[i].to][1];
  }
}
int main() {
  scanf("%d", &n);
  for (int i = 1; i < n; ++i) {
    int u, v, w;
    scanf("%d%d%d", &u, &v, &w);
    addedge(u, v, w);
    addedge(v, u, w);
    ++deg[u];
    ++deg[v];
  }
  for (int i = 1; i <= n; ++i)
    if (deg[i] == 1) {
      rt = i;
      leaf[i][1] = i;
    } else if (deg[i] == 2) {
      puts("NO");
      return 0;
    }
  puts("YES");
  dfs(rt);
  for (int i = 1; i <= cnt; i += 2) {
    int u = e[i].from, v = e[i].to, w = e[i].val;
    if (deg[u] == 1 && deg[v] == 1) {
      a[++s] = u;
      b[s] = v;
      c[s] = w;
      continue;
    }
    if (deg[u] != 1 && deg[v] != 1) {
      int ux, uy, vx, vy;
      if (fa[v] == u) swap(u, v);
      ux = leaf[u][1];
      uy = leaf[u][2];
      if (leaf[v][1] != ux && leaf[v][1] != uy) {
        vx = leaf[v][1];
        if (leaf[v][2] != uy && leaf[v][2] != ux)
          vy = leaf[v][2];
        else
          vy = rt;
      } else {
        vx = leaf[v][2];
        vy = rt;
      }
      a[++s] = ux;
      b[s] = vx;
      c[s] = w / 2;
      a[++s] = uy;
      b[s] = vy;
      c[s] = w / 2;
      a[++s] = ux;
      b[s] = uy;
      c[s] = -w / 2;
      a[++s] = vx;
      b[s] = vy;
      c[s] = -w / 2;
      continue;
    }
    if (deg[u] == 1) swap(u, v);
    int x, y;
    if (v == rt)
      x = leaf[u][1], y = leaf[u][2];
    else {
      x = rt;
      if (v == leaf[u][1])
        y = leaf[u][2];
      else
        y = leaf[u][1];
    }
    a[++s] = x;
    b[s] = v;
    c[s] = w / 2;
    a[++s] = y;
    b[s] = v;
    c[s] = w / 2;
    a[++s] = x;
    b[s] = y;
    c[s] = -w / 2;
  }
  printf("%d\n", s);
  for (int i = 1; i <= s; ++i) printf("%d %d %d\n", a[i], b[i], c[i]);
}
