#include <bits/stdc++.h>
using namespace std;
const int maxn = 1005;
vector<pair<int, int> > G[maxn];
vector<int> lef[maxn];
vector<vector<int> > op;
int pr[maxn], root;
bool vis[maxn];
void dfs1(int s) {
  vis[s] = 1;
  for (auto it : G[s])
    if (!vis[it.first]) {
      pr[it.first] = s;
      dfs1(it.first);
      lef[s].push_back(lef[it.first][0]);
    }
  if (lef[s].size() == 0) lef[s].push_back(s);
}
void add_path(int v, int x) {
  if (lef[v].size() == 1) {
    op.push_back({root, v, x});
    return;
  }
  op.push_back({root, lef[v][0], x / 2});
  op.push_back({root, lef[v][1], x / 2});
  op.push_back({lef[v][0], lef[v][1], -x / 2});
}
void add_edge(int v, int x) {
  if (pr[v] == root) {
    add_path(v, x);
    return;
  }
  add_path(v, x);
  add_path(pr[v], -x);
}
void dfs2(int s) {
  vis[s] = 1;
  for (auto it : G[s])
    if (!vis[it.first]) {
      add_edge(it.first, it.second);
      dfs2(it.first);
    }
}
int main() {
  int n, u, v, x;
  cin >> n;
  if (n == 1) {
    puts("YES");
    puts("1");
    scanf("%d%d%d", &u, &v, &x);
    printf("%d %d %d", u, v, x);
    return 0;
  }
  for (int i = 0; i < n - 1; i++) {
    scanf("%d%d%d", &u, &v, &x);
    G[u].push_back(make_pair(v, x));
    G[v].push_back(make_pair(u, x));
  }
  for (int i = 1; i <= n; i++)
    if (G[i].size() == 2) {
      cout << "NO";
      return 0;
    }
  root = 1;
  puts("YES");
  while (G[root].size() != 1) root++;
  dfs1(root);
  memset(vis, 0, sizeof(vis));
  dfs2(root);
  printf("%d\n", op.size());
  for (auto it : op) printf("%d %d %d\n", it[0], it[1], it[2]);
  return 0;
}
