#include <bits/stdc++.h>
using namespace std;
struct E {
  int n1, n2, val;
};
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(nullptr);
  cout.tie(nullptr);
  int n, a, b, val;
  cin >> n;
  vector<E> v(n - 1);
  vector<int> edge[n + 1];
  for (int i = 0; i < n - 1; ++i) {
    cin >> a >> b >> val;
    edge[a].emplace_back(b);
    edge[b].emplace_back(a);
    v[i].n1 = a;
    v[i].n2 = b;
    v[i].val = val;
  }
  for (int i = 1; i <= n; ++i) {
    if (edge[i].size() == 2) {
      cout << "NO" << '\n';
      return 0;
    }
  }
  cout << "YES" << '\n';
  vector<pair<int, pair<int, int> > > ans;
  for (E ed : v) {
    int l1 = 0, l2 = 0, r1 = 0, r2 = 0, d = ed.val >> 1;
    function<void(int, int, bool)> dfs = [&](int second, int par, bool dir) {
      if (edge[second].size() == 1) {
        if (!dir) {
          if (!l1) l1 = second;
          l2 = second;
        } else {
          if (!r1) r1 = second;
          r2 = second;
        }
      }
      for (int a : edge[second]) {
        if (a != par) {
          dfs(a, second, dir);
        }
      }
    };
    dfs(ed.n1, ed.n2, 0);
    dfs(ed.n2, ed.n1, 1);
    ans.emplace_back(make_pair(l1, make_pair(r1, d)));
    ans.emplace_back(make_pair(l2, make_pair(r2, d)));
    if (edge[ed.n1].size() != 1)
      ans.emplace_back(make_pair(l2, make_pair(l1, -d)));
    if (edge[ed.n2].size() != 1)
      ans.emplace_back(make_pair(r2, make_pair(r1, -d)));
  }
  cout << ans.size() << '\n';
  for (auto pr : ans) {
    cout << pr.first << " " << pr.second.first << " " << pr.second.second
         << '\n';
  }
}
