#include <bits/stdc++.h>
using namespace std;
const int N = 1e3 + 50;
struct bian {
  int x, y, v;
} side[N];
struct node {
  int x, y, v;
  node() {}
  node(int xx, int yy, int vv) {
    x = xx;
    y = yy;
    v = vv;
  }
} out[N << 2];
vector<int> vec[N];
bool vis[N];
int b[3], cnt, co;
void dfs(int x) {
  if (vec[x].size() == 1) {
    b[cnt++] = x;
    return;
  }
  vis[x] = 1;
  int len = vec[x].size();
  for (int i = 0; i < len; i++) {
    int tx = vec[x][i];
    if (vis[tx]) continue;
    dfs(tx);
    break;
  }
  vis[x] = 0;
  return;
}
void fun(int k) {
  int x = side[k].x;
  int y = side[k].y;
  int x1, x2, y1, y2;
  if (vec[x].size() == 1)
    x1 = x2 = x;
  else {
    cnt = 0;
    vis[x] = 1;
    int len = vec[x].size();
    for (int i = 0; i < len; i++) {
      int tx = vec[x][i];
      if (tx == y) continue;
      dfs(tx);
      if (cnt >= 2) break;
    }
    vis[x] = 0;
    x1 = b[0];
    x2 = b[1];
  }
  if (vec[y].size() == 1)
    y1 = y2 = y;
  else {
    cnt = 0;
    vis[y] = 1;
    int len = vec[y].size();
    for (int i = 0; i < len; i++) {
      int ty = vec[y][i];
      if (ty == x) continue;
      dfs(ty);
      if (cnt >= 2) break;
    }
    vis[y] = 0;
    y1 = b[0];
    y2 = b[1];
  }
  int v = side[k].v >> 1;
  out[co++] = node(x1, y1, v);
  out[co++] = node(x2, y2, v);
  if (x1 != x2) out[co++] = node(x1, x2, -v);
  if (y1 != y2) out[co++] = node(y1, y2, -v);
  return;
}
int main() {
  int n;
  scanf("%d", &n);
  for (int i = 1; i < n; i++) {
    scanf("%d%d%d", &side[i].x, &side[i].y, &side[i].v);
    vec[side[i].x].push_back(side[i].y);
    vec[side[i].y].push_back(side[i].x);
  }
  for (int i = 1; i <= n; i++)
    if (vec[i].size() == 2) {
      printf("NO\n");
      return 0;
    }
  printf("YES\n");
  for (int i = 1; i < n; i++) fun(i);
  printf("%d\n", co);
  for (int i = 0; i < co; i++)
    printf("%d %d %d\n", out[i].x, out[i].y, out[i].v);
  return 0;
}
