#include <bits/stdc++.h>
using namespace std;
const int ms = 1010;
int n, root;
vector<pair<int, int> > G[ms];
vector<int> leaves[ms];
bool vis[ms];
struct opt {
  int u, v, x;
};
vector<opt> res;
void dfs1(int x) {
  vis[x] = true;
  if (G[x].size() == 1) {
    leaves[x].push_back(x);
  }
  for (auto i : G[x]) {
    if (vis[i.first]) continue;
    dfs1(i.first);
    leaves[x].push_back(leaves[i.first][0]);
  }
}
void output(int u, int v, int x) {
  if (leaves[v].size() == 1) {
    res.push_back({u, v, x});
    return;
  }
  res.push_back({u, leaves[v][1], x / 2});
  res.push_back({u, leaves[v][0], x / 2});
  res.push_back({leaves[v][0], leaves[v][1], -x / 2});
}
void dfs2(int x) {
  vis[x] = true;
  for (auto i : G[x]) {
    if (vis[i.first]) continue;
    output(root, i.first, i.second);
    if (x != root) {
      output(root, x, -i.second);
    }
    dfs2(i.first);
  }
}
int main() {
  int a, b, c;
  scanf("%d", &n);
  for (int i = 0; i < n - 1; ++i) {
    scanf("%d%d%d", &a, &b, &c);
    G[a].emplace_back(b, c);
    G[b].emplace_back(a, c);
  }
  for (int i = 0; i < n; ++i) {
    if (G[i].size() == 2) {
      return 0 * printf("NO\n");
    }
  }
  root = 1;
  while (G[root].size() != 1) root++;
  dfs1(root);
  memset(vis, false, sizeof(vis));
  dfs2(root);
  printf("YES\n%d\n", res.size());
  for (auto i : res) {
    printf("%d %d %d\n", i.u, i.v, i.x);
  }
}
