#include <bits/stdc++.h>
using namespace std;
struct Node {
  int to, val, nxt;
} node[2005];
int head[1005], tot = 1;
int du[1005], le = 1;
bool vis[1005];
int pr[1005];
vector<vector<int> > ans, leaves;
void dfs1(int x) {
  vis[x] = true;
  for (int i = head[x]; i > 0; i = node[i].nxt) {
    if (vis[node[i].to]) continue;
    pr[node[i].to] = x;
    dfs1(node[i].to);
    leaves[x].push_back(leaves[node[i].to][0]);
  }
  if (leaves[x].size() == 0) leaves[x].push_back(x);
}
void add_path(int v, int x) {
  if (leaves[v].size() == 1) {
    ans.push_back({le, v, x});
    return;
  }
  ans.push_back({le, leaves[v][0], x / 2});
  ans.push_back({le, leaves[v][1], x / 2});
  ans.push_back({leaves[v][0], leaves[v][1], -x / 2});
}
void add_edge(int v, int x) {
  if (pr[v] == le) {
    add_path(v, x);
    return;
  }
  add_path(v, x);
  add_path(pr[v], -x);
}
void dfs2(int x) {
  vis[x] = true;
  for (int i = head[x]; i > 0; i = node[i].nxt) {
    if (vis[node[i].to]) continue;
    add_edge(node[i].to, node[i].val);
    dfs2(node[i].to);
  }
}
int main() {
  int n;
  cin >> n;
  int u, v, val;
  if (n == 2) {
    cin >> u >> v >> val;
    cout << "YES\n";
    cout << 1 << endl;
    cout << u << ' ' << v << ' ' << val << endl;
    return 0;
  }
  leaves.resize(n + 5);
  for (int i = 1; i < n; i++) {
    cin >> u >> v >> val;
    du[u]++, du[v]++;
    node[tot].to = v, node[tot].val = val, node[tot].nxt = head[u];
    head[u] = tot++;
    node[tot].to = u, node[tot].val = val, node[tot].nxt = head[v];
    head[v] = tot++;
  }
  for (int i = 1; i <= n; i++) {
    if (du[i] == 2) {
      cout << "NO\n";
      return 0;
    }
  }
  cout << "YES\n";
  while (du[le] != 1) le++;
  dfs1(le);
  memset(vis, false, sizeof(vis));
  dfs2(le);
  cout << ans.size() << endl;
  for (auto i : ans) {
    cout << i[0] << ' ' << i[1] << ' ' << i[2] << endl;
  }
  return 0;
}
