#include <bits/stdc++.h>
using namespace std;
const int N = 1e5 + 10;
vector<pair<int, int> > a[N];
vector<pair<pair<int, int>, int> > edge, ans;
int n;
int getson(int u, int p) {
  if (a[u].size() == 1) return u;
  for (int i = 0; i < (int)a[u].size(); ++i) {
    int v = a[u][i].first;
    if (v == p)
      continue;
    else
      return getson(v, u);
  }
}
int main(void) {
  ios::sync_with_stdio(false), cin.tie(0);
  cin >> n;
  for (int i = 0; i < n - 1; ++i) {
    int u, v, w;
    cin >> u >> v >> w;
    a[u].push_back(make_pair(v, w));
    a[v].push_back(make_pair(u, w));
    edge.push_back(make_pair(make_pair(u, v), w));
  }
  for (int i = 1; i <= n; ++i) {
    if (a[i].size() == 2) return cout << "NO", 0;
  }
  cout << "YES" << endl;
  for (int i = 0; i < (int)edge.size(); ++i) {
    int u = edge[i].first.first;
    int v = edge[i].first.second;
    int w = edge[i].second / 2;
    pair<int, int> son;
    son.first = son.second = -1;
    for (int j = 0; j < (int)a[u].size(); ++j) {
      int t = a[u][j].first;
      if (t == v) continue;
      if (son.first == -1)
        son.first = getson(t, u);
      else if (son.second == -1) {
        son.second = getson(t, u);
        break;
      }
    }
    if (a[u].size() == 1) son.second = son.first = u;
    pair<int, int> son2;
    son2.first = son2.second = -1;
    for (int j = 0; j < (int)a[v].size(); ++j) {
      int t = a[v][j].first;
      if (t == u) continue;
      if (son2.first == -1)
        son2.first = getson(t, v);
      else if (son2.second == -1) {
        son2.second = getson(t, v);
        break;
      }
    }
    if (a[v].size() == 1) son2.second = son2.first = v;
    ans.push_back(make_pair(make_pair(son.first, son2.first), w));
    ans.push_back(make_pair(make_pair(son.second, son2.second), w));
    if (son.first != son.second)
      ans.push_back(make_pair(make_pair(son.first, son.second), -w));
    if (son2.first != son2.second)
      ans.push_back(make_pair(make_pair(son2.first, son2.second), -w));
  }
  cout << ans.size() << endl;
  for (int i = 0; i < (int)ans.size(); ++i) {
    cout << ans[i].first.first << ' ' << ans[i].first.second << ' '
         << ans[i].second << endl;
  }
  return 0;
}
