#include <bits/stdc++.h>
using namespace std;
vector<pair<int, int> > adj[1010];
void del(int u, int v, int val) {
  int j = lower_bound(adj[u].begin(), adj[u].end(),
                      pair<int, int>(v, -0x3f3f3f3f)) -
          adj[u].begin();
  adj[u][j].second -= val;
}
int find(int u, int f, int val, int flag = 1) {
  if (adj[u].size() == 1) return u;
  if (flag)
    for (int i = 0; i < adj[u].size(); i++) {
      int v = adj[u][i].first;
      if (v == f) continue;
      adj[u][i].second -= val;
      del(v, u, val);
      return find(v, u, val, flag);
    }
  else
    for (int i = adj[u].size(); i--;) {
      int v = adj[u][i].first;
      if (v == f) continue;
      adj[u][i].second -= val;
      del(v, u, val);
      return find(v, u, val, flag);
    }
}
void add(int u, int v, int w) {
  adj[u].push_back(pair<int, int>(v, w));
  for (int j = adj[u].size(); --j;) {
    if (adj[u][j] < adj[u][j - 1]) swap(adj[u][j - 1], adj[u][j]);
  }
}
void rem(int u, int v, int w) {
  adj[u].erase(find(adj[u].begin(), adj[u].end(), pair<int, int>(v, w)));
}
int main() {
  int n;
  cin >> n;
  for (int i = 1; i < n; i++) {
    int u, v, w;
    scanf("%d %d %d", &u, &v, &w);
    adj[u].push_back(pair<int, int>(v, w));
    adj[v].push_back(pair<int, int>(u, w));
  }
  for (int i = 1; i <= n; i++) sort(adj[i].begin(), adj[i].end());
  for (int i = 1; i <= n; i++)
    if (adj[i].size() == 2) return puts("NO"), 0;
  set<int> id;
  for (int i = 1; i <= n; i++) id.insert(i);
  vector<pair<pair<int, int>, int> > ans;
  while (!id.empty()) {
    if (id.size() == 2) {
      int u = *id.begin();
      int v = *id.rbegin();
      ans.push_back(
          pair<pair<int, int>, int>(pair<int, int>(u, v), adj[u][0].second));
      break;
    }
    for (auto u : id)
      if (adj[u].size() == 1) {
        int v = adj[u][0].first, z = adj[u][0].second;
        rem(v, u, z);
        id.erase(u);
        if (adj[v].size() > 2) {
          int w = find(v, u, z);
          ans.push_back(pair<pair<int, int>, int>(pair<int, int>(u, w), z));
          break;
        }
        int first = adj[v][0].second;
        int second = adj[v][1].second;
        int a = (first - second + z) / 2;
        int b = z - a;
        id.erase(v);
        int res = first - a, w1, w2;
        if (a & 1) {
          res++;
          w1 = find(v, u, a - 1);
          w2 = find(v, u, b - 1, 0);
          ans.push_back(pair<pair<int, int>, int>(pair<int, int>(w1, w2), -1));
        } else {
          w1 = find(v, u, a);
          w2 = find(v, u, b, 0);
        }
        ans.push_back(pair<pair<int, int>, int>(pair<int, int>(u, w1), a));
        ans.push_back(pair<pair<int, int>, int>(pair<int, int>(u, w2), b));
        rem(adj[v][0].first, v, res);
        rem(adj[v][1].first, v, res);
        add(adj[v][0].first, adj[v][1].first, res);
        add(adj[v][1].first, adj[v][0].first, res);
        break;
      }
  }
  puts("YES");
  cout << ans.size() << endl;
  for (pair<pair<int, int>, int> p : ans)
    printf("%d %d %d\n", p.first.first, p.first.second, p.second);
  return 0;
}
