#include <bits/stdc++.h>
using namespace std;
int n, deg[1005], leaf[1005][1005], ans_cnt;
struct rec {
  int u, v, w;
} inp[1005], ans[10000];
struct Edge {
  int nxt, to;
} e[2005];
int hd[1005], e_cnt;
void add(int u, int v) {
  e[++e_cnt] = (Edge){hd[u], v};
  hd[u] = e_cnt;
}
int dfs1(int u, int r) {
  if (deg[u] == 1) return u;
  for (int i = hd[u]; i; i = e[i].nxt)
    if (e[i].to != r) return dfs1(e[i].to, u);
}
int main() {
  cin >> n;
  for (int i = 1; i <= n - 1; i++) {
    int u, v, w;
    cin >> u >> v >> w;
    add(u, v);
    add(v, u);
    inp[i] = (rec){u, v, w};
    deg[u]++;
    deg[v]++;
    if (n == 2) {
      cout << "YES\n1\n1 2 " << w;
      return 0;
    }
  }
  for (int i = 1; i <= n; i++)
    if (deg[i] == 2) {
      cout << "NO";
      return 0;
    }
  cout << "YES" << '\n';
  for (int i = 1; i <= n; i++)
    for (int j = hd[i]; j; j = e[j].nxt) leaf[i][e[j].to] = dfs1(e[j].to, i);
  for (int i = 1; i <= n - 1; i++) {
    int u = inp[i].u, v = inp[i].v, w = inp[i].w, t1 = 0, t2 = 0;
    if (deg[u] == 1) swap(u, v);
    for (int j = hd[u]; j; j = e[j].nxt)
      if (e[j].to != v)
        if (!t1)
          t1 = e[j].to;
        else if (!t2)
          t2 = e[j].to;
    ans[++ans_cnt] = (rec){leaf[u][v], leaf[u][t1], w / 2};
    ans[++ans_cnt] = (rec){leaf[u][v], leaf[u][t2], w / 2};
    ans[++ans_cnt] = (rec){leaf[u][t1], leaf[u][t2], -w / 2};
    if (deg[v] > 1) {
      t1 = 0;
      t2 = 0;
      for (int j = hd[v]; j; j = e[j].nxt)
        if (leaf[v][e[j].to] != leaf[u][v])
          if (!t1)
            t1 = e[j].to;
          else if (!t2)
            t2 = e[j].to;
      ans[++ans_cnt] = (rec){leaf[u][v], leaf[v][t1], -w / 2};
      ans[++ans_cnt] = (rec){leaf[u][v], leaf[v][t2], -w / 2};
      ans[++ans_cnt] = (rec){leaf[v][t1], leaf[v][t2], w / 2};
    }
  }
  cout << ans_cnt << '\n';
  for (int i = 1; i <= ans_cnt; i++)
    cout << ans[i].u << ' ' << ans[i].v << ' ' << ans[i].w << '\n';
  return 0;
}
