#include <bits/stdc++.h>
using namespace std;
int root;
vector<pair<int, int> > G[1234];
vector<int> leaf[1234];
struct ops {
  int a, b, c;
  ops(int aa, int bb, int cc) {
    a = aa;
    b = bb;
    c = cc;
  }
};
void dfs1(int cur, int pre) {
  for (pair<int, int> tmp : G[cur]) {
    int nxt = tmp.first, val = tmp.second;
    if (pre == nxt) continue;
    dfs1(nxt, cur);
    leaf[cur].push_back(leaf[nxt][0]);
  }
  if (leaf[cur].size() == 0) leaf[cur].push_back(cur);
}
vector<ops> ans;
void addpath(int cur, int val) {
  if (leaf[cur].size() == 1)
    ans.push_back(ops(root, leaf[cur][0], val));
  else {
    ans.push_back(ops(root, leaf[cur][0], val / 2));
    ans.push_back(ops(root, leaf[cur][1], val / 2));
    ans.push_back(ops(leaf[cur][0], leaf[cur][1], -val / 2));
  }
}
void addedge(int cur, int pre, int val) {
  if (pre == root)
    addpath(cur, val);
  else {
    addpath(cur, val);
    addpath(pre, -val);
  }
}
void dfs2(int cur, int pre) {
  for (pair<int, int> tmp : G[cur]) {
    int nxt = tmp.first, val = tmp.second;
    if (pre == nxt) continue;
    addedge(nxt, cur, val);
    dfs2(nxt, cur);
  }
}
int main() {
  ios::sync_with_stdio();
  cin.tie(0);
  int n;
  cin >> n;
  for (int i = 0; i < n - 1; i++) {
    int u, v, w;
    cin >> u >> v >> w;
    G[u].push_back(make_pair(v, w));
    G[v].push_back(make_pair(u, w));
  }
  for (int i = 1; i <= n; i++)
    if (G[i].size() == 2) {
      cout << "NO\n";
      return 0;
    }
  root = 1;
  while (G[root].size() != 1) root++;
  dfs1(root, 0);
  dfs2(root, 0);
  cout << "YES\n" << ans.size() << endl;
  for (int i = 0; i < ans.size(); i++)
    cout << ans[i].a << ' ' << ans[i].b << ' ' << ans[i].c << endl;
}
