#include <bits/stdc++.h>
using namespace std;
const int N = 1e3 + 10;
vector<pair<int, int> > g[N];
vector<int> ans[N * 10];
vector<int> leave[N];
int fa[N];
int n, root = 1, tot;
void addpath(int v, int w) {
  if (leave[v].size() == 1) {
    ans[tot++] = {root, v, w};
    return;
  }
  int v1 = leave[v][0], v2 = leave[v][1];
  ans[tot++] = {root, v1, w / 2};
  ans[tot++] = {root, v2, w / 2};
  ans[tot++] = {v1, v2, -w / 2};
}
void addedge(int v, int w) {
  addpath(v, w);
  if (fa[v] != root) addpath(fa[v], -w);
}
void dfs1(int u, int fat) {
  for (auto it : g[u]) {
    int v = it.first;
    if (v == fat) continue;
    fa[v] = u;
    dfs1(v, u);
    leave[u].push_back(leave[v][0]);
  }
  if (leave[u].empty()) leave[u].push_back(u);
}
void dfs2(int u, int fat) {
  for (auto it : g[u]) {
    int v = it.first;
    if (v == fat) continue;
    addedge(v, it.second);
    dfs2(v, u);
  }
}
int main() {
  scanf("%d", &n);
  for (int i = 1; i < n; i++) {
    int u, v, w;
    scanf("%d%d%d", &u, &v, &w);
    g[u].push_back(pair<int, int>(v, w));
    g[v].push_back(pair<int, int>(u, w));
  }
  for (int i = 1; i <= n; i++) {
    if (g[i].size() == 2) {
      puts("NO");
      return 0;
    }
  }
  while (g[root].size() != 1) root++;
  dfs1(root, -1);
  dfs2(root, -1);
  puts("YES");
  printf("%d\n", tot);
  for (int i = 0; i < tot; i++) {
    printf("%d %d %d\n", ans[i][0], ans[i][1], ans[i][2]);
  }
  return 0;
}
