#include <bits/stdc++.h>
using namespace std;
const int N = 1005;
int n, r, par[N], c[N], leaf1[N], leaf2[N], m, x[10 * N], y[10 * N], d[10 * N];
vector<pair<int, int> > ke[N];
void dfs(int u) {
  for (auto e : ke[u])
    if (e.second != par[u]) {
      int v = e.second;
      c[v] = e.first;
      par[v] = u;
      dfs(v);
      leaf2[u] = leaf1[u];
      leaf1[u] = leaf1[v];
    }
  if (leaf1[u] == 0) leaf1[u] = u;
}
void leaf_leaf(int u, int v, int c) {
  m += 1;
  x[m] = u;
  y[m] = v;
  d[m] = c;
}
void leaf_node(int v, int u, int c) {
  if (u == r) leaf_leaf(v, r, c);
  if (u == r || u == v) return;
  int z = v != leaf1[u] ? leaf1[u] : leaf2[u];
  leaf_leaf(v, z, c / 2);
  leaf_leaf(v, r, c / 2);
  leaf_leaf(r, z, -c / 2);
}
void node_node(int u, int v, int c) {
  leaf_node(leaf1[v], u, c);
  leaf_node(leaf1[v], v, -c);
}
int main() {
  scanf("%d", &n);
  for (int i = 1; i < n; ++i) {
    int u, v, c;
    scanf("%d%d%d", &u, &v, &c);
    ke[u].push_back(pair<int, int>(c, v));
    ke[v].push_back(pair<int, int>(c, u));
  }
  for (int i = 1; i <= n; ++i) {
    if (ke[i].size() == 2) {
      puts("NO");
      return 0;
    }
    if (ke[i].size() == 1) r = i;
  }
  dfs(r);
  for (int i = 1; i <= n; ++i)
    if (i != r) node_node(par[i], i, c[i]);
  printf("YES\n%d\n", m);
  for (int i = 1; i <= m; ++i) printf("%d %d %d\n", x[i], y[i], d[i]);
}
