#include <bits/stdc++.h>
using namespace std;
const int maxN = 1010;
vector<pair<int, int> > g[maxN];
vector<vector<int> > path;
void print_path(int v, int u, int val) {
  assert(v != u);
  assert(g[v].size() == 1);
  assert(g[u].size() == 1);
  path.push_back({v + 1, u + 1, val});
}
int get_leaf_below(int p, int v) {
  if (g[v].size() == 1) return v;
  for (auto u_val : g[v]) {
    int u = u_val.first;
    if (u != p) return get_leaf_below(v, u);
  }
  assert(false);
}
vector<int> get_leaves_below(int p, int v) {
  if (g[v].size() == 1) return vector<int>(1, v);
  vector<int> res;
  for (auto u_val : g[v]) {
    int u = u_val.first;
    if (u != p) {
      res.push_back(get_leaf_below(v, u));
    }
    if (res.size() == 2) return res;
  }
  assert(false);
}
void fix_edge(int v, int u, int val) {
  vector<int> leaves_u = get_leaves_below(v, u);
  vector<int> leaves_v = get_leaves_below(u, v);
  if (leaves_u.size() == 2 && leaves_v.size() == 2) {
    print_path(leaves_u[0], leaves_u[1], -val / 2);
    print_path(leaves_v[0], leaves_v[1], -val / 2);
    print_path(leaves_u[0], leaves_v[0], +val / 2);
    print_path(leaves_u[1], leaves_v[1], +val / 2);
  } else if (leaves_u.size() == 1 && leaves_v.size() == 2) {
    print_path(leaves_v[0], leaves_v[1], -val / 2);
    print_path(leaves_v[0], leaves_u[0], +val / 2);
    print_path(leaves_v[1], leaves_u[0], +val / 2);
  } else if (leaves_u.size() == 2 && leaves_v.size() == 1) {
    print_path(leaves_u[0], leaves_u[1], -val / 2);
    print_path(leaves_u[0], leaves_v[0], +val / 2);
    print_path(leaves_u[1], leaves_v[0], +val / 2);
  } else if (leaves_u.size() == 1 && leaves_v.size() == 1) {
    print_path(leaves_u[0], leaves_v[0], +val);
  } else {
    assert(false);
  }
}
void fix_edges_below(int p, int v) {
  for (auto u_val : g[v]) {
    int u = u_val.first;
    int val = u_val.second;
    if (u == p) continue;
    fix_edge(v, u, val);
    fix_edges_below(v, u);
  }
}
int main() {
  int N;
  while (cin >> N) {
    path.clear();
    for (int i = 0; i < int(maxN); i++) g[i].clear();
    for (int i = 0; i < int(N - 1); i++) {
      int u, v, val;
      cin >> u >> v >> val;
      u--;
      v--;
      g[u].push_back(make_pair(v, val));
      g[v].push_back(make_pair(u, val));
    }
    bool deg_2 = false;
    for (int i = 0; i < int(N); i++) {
      deg_2 |= (g[i].size() == 2);
    }
    if (deg_2) {
      cout << "NO" << endl;
    } else {
      cout << "YES" << endl;
      fix_edges_below(-1, 0);
      cout << path.size() << endl;
      for (auto p : path) {
        cout << p[0] << " " << p[1] << " " << p[2] << endl;
      }
    }
  }
  return 0;
}
