#include <bits/stdc++.h>
using namespace std;
const int maxn = 1e3 + 5;
const int mod = 1e9 + 7;
int read() {
  int x = 0, w = 1;
  char ch = getchar();
  while ((ch < '0' || ch > '9') && ch != '-') ch = getchar();
  if (ch == '-') w = 0, ch = getchar();
  while (ch >= '0' && ch <= '9')
    x = (x << 3) + (x << 1) + ch - '0', ch = getchar();
  return w ? x : -x;
}
int head[maxn], tot;
struct node {
  int next, va, to;
};
node eddge[maxn * 2];
node side[maxn];
node ans[maxn * 100];
void add_edge(int u, int v, int w) {
  eddge[tot].next = v;
  eddge[tot].va = w;
  eddge[tot].to = head[u];
  head[u] = tot++;
}
int x[maxn], y[maxn], s;
void dfs(int now, int fa, vector<int> &y) {
  if (x[now] == 1) {
    y.push_back(now);
    return;
  }
  for (int i = head[now]; i != -1; i = eddge[i].to)
    if (eddge[i].next != fa) dfs(eddge[i].next, now, y);
}
void add(int i, int j, int w, int &g) {
  ans[++g].next = i;
  ans[g].to = j;
  ans[g].va = w;
}
int main() {
  int n = read();
  tot = 0;
  memset(head, -1, sizeof(head));
  memset(x, 0, sizeof(x));
  for (int a = 1; a < n; a++) {
    int i = read(), j = read(), w = read();
    add_edge(i, j, w);
    add_edge(j, i, w);
    side[a].next = i;
    side[a].to = j;
    side[a].va = w;
    x[i]++;
    x[j]++;
  }
  for (int a = 1; a <= n; a++) {
    if (x[a] == 2) {
      printf("NO\n");
      return 0;
    }
  }
  int an = 0;
  for (int a = 1; a < n; a++) {
    vector<int> v1;
    vector<int> v2;
    dfs(side[a].to, side[a].next, v1);
    dfs(side[a].next, side[a].to, v2);
    add(v1.front(), v2.back(), side[a].va / 2, an);
    add(v2.front(), v1.back(), side[a].va / 2, an);
    if (v1.front() != v1.back())
      add(v1.front(), v1.back(), -side[a].va / 2, an);
    if (v2.front() != v2.back())
      add(v2.front(), v2.back(), -side[a].va / 2, an);
  }
  printf("YES %d\n", an);
  for (int a = 1; a <= an; a++)
    printf("%d %d %d\n", ans[a].next, ans[a].to, ans[a].va);
}
