#include <bits/stdc++.h>
using namespace std;
const int N = 1111;
int n;
struct Edge {
  int u, v;
  long long weight;
  int adj(int x) { return x == u ? v : u; }
};
struct Path {
  int u, v;
  long long weight;
};
vector<Edge> E;
vector<int> G[N];
vector<Path> res;
int Trace[N];
int FindLeaf(int u, int parent) {
  if ((int)G[u].size() == 1) return u;
  for (auto e : G[u]) {
    int v = E[e].adj(u);
    if (v == parent) continue;
    Trace[v] = u;
    int l = FindLeaf(v, u);
    if (l != -1) return l;
  }
  return -1;
}
void Solve() {
  for (int i = 1; i <= n; ++i) {
    if ((int)G[i].size() == 2) {
      cout << "NO\n";
      return;
    }
  }
  cout << "YES\n";
  for (auto e : E) {
    vector<int> U, V;
    int u = e.u;
    int v = e.v;
    long long w = e.weight;
    for (int i = 0; i < (int)G[u].size(); ++i) {
      int uu = E[G[u][i]].adj(u);
      if (uu == v) continue;
      U.push_back(FindLeaf(uu, u));
    }
    if (U.empty()) U.push_back(u);
    for (int i = 0; i < (int)G[v].size(); ++i) {
      int vv = E[G[v][i]].adj(v);
      if (vv == u) continue;
      V.push_back(FindLeaf(vv, v));
    }
    if (V.empty()) V.push_back(v);
    res.push_back({U[0], V[0], w / 2});
    if ((int)U.size() > 1 && (int)V.size() > 1)
      res.push_back({U[1], V[1], w / 2});
    else if ((int)U.size() > 1)
      res.push_back({U[1], V[0], w / 2});
    else if ((int)V.size() > 1)
      res.push_back({U[0], V[1], w / 2});
    else
      res.push_back({U[0], V[0], w / 2});
    if ((int)U.size() > 1) res.push_back({U[0], U[1], -w / 2});
    if ((int)V.size() > 1) res.push_back({V[0], V[1], -w / 2});
  }
  cout << (int)res.size() << '\n';
  for (int i = 0; i < (int)res.size(); ++i) {
    cout << res[i].u << ' ' << res[i].v << ' ' << res[i].weight << '\n';
  }
}
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  cin >> n;
  for (int i = 0; i < n - 1; ++i) {
    int u, v;
    long long w;
    cin >> u >> v >> w;
    G[u].push_back(i);
    G[v].push_back(i);
    E.push_back({u, v, w});
  }
  Solve();
  return 0;
}
