#include <bits/stdc++.h>
#pragma optimization_level 3
#pragma GCC optimize("Ofast,no-stack-protector")
#pragma GCC optimize("unroll-loops")
#pragma GCC optimize("fast-math")
using namespace std;
mt19937 rnd(chrono::steady_clock::now().time_since_epoch().count());
struct Q {
  int l, r, k;
  Q() {}
  Q(int a, int b, int c) {
    l = a;
    r = b;
    k = c;
  }
};
int a;
vector<vector<pair<int, int>>> l;
vector<int> leaf;
vector<Q> o;
void dfl(int v, int p) {
  if (l[v].size() == 1) leaf.push_back(v);
  for (pair<int, int> h : l[v]) {
    if (h.first == p) continue;
    dfl(h.first, v);
  }
}
void dfs(int v, int p) {
  for (pair<int, int> h : l[v]) {
    if (h.first == p) continue;
    leaf.clear();
    int l1, l2;
    if (l[v].size() == 1) {
      dfl(h.first, v);
      l1 = leaf[0], l2 = leaf.back();
      o.push_back(Q(v, l1, h.second / 2));
      o.push_back(Q(v, l2, h.second / 2));
      o.push_back(Q(l1, l2, -h.second / 2));
    } else if (l[h.first].size() == 1) {
      dfl(v, h.first);
      l1 = leaf[0], l2 = leaf.back();
      o.push_back(Q(h.first, l1, h.second / 2));
      o.push_back(Q(h.first, l2, h.second / 2));
      o.push_back(Q(l1, l2, -h.second / 2));
    } else {
      dfl(h.first, v);
      l1 = leaf[0], l2 = leaf.back();
      leaf.clear();
      dfl(v, h.first);
      int l3 = leaf[0], l4 = leaf.back();
      o.push_back(Q(l1, l3, h.second / 2));
      o.push_back(Q(l2, l4, h.second / 2));
      o.push_back(Q(l1, l2, -h.second / 2));
      o.push_back(Q(l3, l4, -h.second / 2));
    }
    dfs(h.first, v);
  }
}
int main() {
  cin.tie(0);
  cout.tie(0);
  cin.sync_with_stdio(0);
  cout.sync_with_stdio(0);
  ;
  cin >> a;
  l = vector<vector<pair<int, int>>>(a, vector<pair<int, int>>());
  for (int q = 0; q < a - 1; q++) {
    int x, y, c;
    cin >> x >> y >> c;
    x--;
    y--;
    l[x].push_back({y, c});
    l[y].push_back({x, c});
  }
  for (int q = 0; q < a; q++)
    if (l[q].size() == 2) {
      cout << "NO";
      return 0;
    }
  if (a == 2) {
    cout << "YES\n1\n1 2 " << l[0][0].second;
    return 0;
  }
  dfs(0, -1);
  cout << "YES\n" << o.size() << "\n";
  for (Q i : o) cout << i.l + 1 << " " << i.r + 1 << " " << i.k << "\n";
}
