#include <bits/stdc++.h>
using namespace std;
int n, a, b, c, d;
struct edge {
  int u, v, val;
} e[2000 + 5];
vector<int> G[2000 + 5];
vector<edge> ans;
void dfs(int x, int fa, int kdf) {
  if (G[x].size() == 1) {
    if (!kdf) {
      if (a == 0) a = x;
      b = x;
    } else {
      if (c == 0) c = x;
      d = x;
    }
  }
  for (int i = 0; i < G[x].size(); i++) {
    int nxt = G[x][i];
    if (nxt == fa) continue;
    dfs(nxt, x, kdf);
  }
}
int main() {
  scanf("%d", &n);
  for (int i = 1; i < n; i++) {
    int u, v, val;
    scanf("%d%d%d", &u, &v, &val);
    e[i] = (edge){u, v, val};
    G[u].push_back(v);
    G[v].push_back(u);
  }
  for (int i = 1; i <= n; i++)
    if (G[i].size() == 2) {
      printf("NO\n");
      return 0;
    }
  printf("YES\n");
  for (int i = 1; i < n; i++) {
    int u = e[i].u, v = e[i].v, val = e[i].val;
    a = b = c = d = 0;
    dfs(u, v, 0);
    dfs(v, u, 1);
    ans.push_back((edge){a, c, val / 2});
    ans.push_back((edge){b, d, val / 2});
    if (a != b) ans.push_back((edge){a, b, -val / 2});
    if (c != d) ans.push_back((edge){c, d, -val / 2});
  }
  printf("%d\n", ans.size());
  for (int i = 0; i < ans.size(); i++)
    printf("%d %d %d\n", ans[i].u, ans[i].v, ans[i].val);
}
