#include <bits/stdc++.h>
using namespace std;
int n;
vector<vector<int> > adj;
vector<int> par;
vector<int> leaf;
struct edge {
  int u, v, w;
};
vector<edge> E;
void data() {
  adj.resize(n + 1);
  par.resize(n + 1);
  leaf.resize(n + 1);
  E.resize(n - 1);
}
void dfs(const int &u, const int &parent) {
  par[u] = parent;
  if (adj[u].size() == 2) {
    cout << "NO";
    exit(0);
  }
  if (parent && adj[u].size() == 1) {
    leaf[u] = u;
    return;
  }
  for (const int &v : adj[u])
    if (v != parent) dfs(v, u), leaf[u] = leaf[v];
}
int leafdad(const int &u, const int &v) {
  if (adj[u][0] != v && adj[u][0] != par[u])
    return leaf[adj[u][0]];
  else if (adj[u][1] != v && adj[u][1] != par[u])
    return leaf[adj[u][1]];
  else
    return leaf[adj[u][2]];
}
int leafson(const int &v, const int &u) {
  if (adj[v][0] != u && leaf[adj[v][0]] != leaf[v])
    return leaf[adj[v][0]];
  else if (adj[v][1] != u && leaf[adj[v][1]] != leaf[v])
    return leaf[adj[v][1]];
  else
    return leaf[adj[v][2]];
}
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  cin >> n;
  data();
  for (int i = 0; i < n - 1; i++)
    cin >> E[i].u >> E[i].v >> E[i].w, adj[E[i].u].push_back(E[i].v),
        adj[E[i].v].push_back(E[i].u);
  int root = -1;
  for (int i = 1; i <= n; i++)
    if (adj[i].size() == 1) {
      dfs(root = i, 0);
      break;
    }
  vector<edge> ans;
  for (const edge &e : E) {
    int u = e.u, v = e.v, w = e.w;
    int l1, l2;
    if (adj[u].size() == 1 || adj[v].size() == 1) {
      if (adj[u].size() == 1) swap(u, v);
      if (adj[u].size() == 1 && adj[v].size() == 1)
        ans.push_back({u, v, w});
      else if (u == par[v]) {
        l1 = leafdad(u, v);
        ans.push_back({root, v, w / 2}), ans.push_back({l1, v, w / 2}),
            ans.push_back({root, l1, -w / 2});
      } else {
        l1 = leafson(u, v);
        ans.push_back({leaf[u], v, w / 2}), ans.push_back({l1, v, w / 2}),
            ans.push_back({leaf[u], l1, -w / 2});
      }
      continue;
    }
    if (u != par[v]) swap(u, v);
    l1 = leafdad(u, v);
    l2 = leafson(v, u);
    ans.push_back({root, leaf[v], w / 2});
    ans.push_back({l1, l2, w / 2});
    ans.push_back({root, l1, -w / 2});
    ans.push_back({leaf[v], l2, -w / 2});
  }
  cout << "YES\n";
  cout << ans.size() << "\n";
  for (const edge &e : ans) cout << e.u << " " << e.v << " " << e.w << "\n";
  return 0;
}
