#include <bits/stdc++.h>
using namespace std;
const int N = (int)1e5 + 10;
int n;
vector<vector<int>> vs, ans;
vector<bool> is_leaf;
vector<pair<pair<int, int>, int>> edges;
void dfs(int node, int par, vector<int>& leafs) {
  if (is_leaf[node]) {
    leafs.push_back(node + 1);
    return;
  }
  for (int v : vs[node])
    if (v != par) {
      dfs(v, node, leafs);
    }
}
void add(int u, int v, int w) {
  if (u == v) return;
  vector<int> cur = {u, v, w};
  ans.push_back(cur);
}
void solve() {
  cin >> n;
  vs.resize(n);
  is_leaf.resize(n);
  for (int i = 0; i < n - 1; ++i) {
    int u, v, w;
    cin >> u >> v >> w, --u, --v;
    vs[u].push_back(v);
    vs[v].push_back(u);
    edges.emplace_back(make_pair(u, v), w);
  }
  for (int i = 0; i < n; ++i) {
    is_leaf[i] = vs[i].size() == 1;
    if (vs[i].size() == 2) {
      cout << "NO" << endl;
      return;
    }
  }
  cout << "YES" << endl;
  if (n == 2) {
    int u, v, w;
    tie(u, v) = edges[0].first;
    w = edges[0].second;
    u++, v++;
    cout << 1 << endl;
    cout << u << " " << v << " " << w << endl;
    return;
  }
  for (auto edge : edges) {
    int u, v;
    tie(u, v) = edge.first;
    int w = edge.second;
    if (is_leaf[v]) swap(u, v);
    vector<int> u_leafs, v_leafs;
    dfs(u, v, u_leafs), dfs(v, u, v_leafs);
    int u_side1 = u_leafs.front(), u_side2 = u_leafs.back();
    int v_side1 = v_leafs.front(), v_side2 = v_leafs.back();
    add(u_side1, v_side1, w / 2);
    add(u_side2, v_side2, w / 2);
    add(u_side1, u_side2, -w / 2);
    add(v_side1, v_side2, -w / 2);
  }
  cout << ans.size() << endl;
  for (vector<int> cur : ans) {
    for (int x : cur) cout << x << " ";
    cout << endl;
  }
}
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout.precision(20);
  cout << fixed;
  solve();
  return 0;
}
