#include <bits/stdc++.h>
using namespace std;
const int N = 1005, M = 505;
const long long MOD = 1e9 + 7;
const double eps = 1e-9;
const double PI = acos(-1.0);
int n, d[N], dpth[N], num, S[N], E[N];
bool isLeaf[N];
vector<int> allLeafs;
vector<vector<int> > g;
vector<pair<pair<int, int>, int> > e, sol;
void dfs(int u, int p) {
  isLeaf[u] = true;
  S[u] = ++num;
  for (int i = 0; i < g[u].size(); i++)
    if (g[u][i] != p) {
      dpth[g[u][i]] = dpth[u] + 1;
      dfs(g[u][i], u);
      isLeaf[u] = false;
    }
  if (isLeaf[u]) {
    allLeafs.push_back(u);
  }
  E[u] = num;
}
int getLeaf(int u, int p) {
  if (isLeaf[u]) return u;
  int l = -1;
  for (int i = 0; i < g[u].size(); i++)
    if (g[u][i] != p) {
      l = getLeaf(g[u][i], u);
      if (l != -1) break;
    }
  return l;
}
bool isUinV(int u, int v) { return (S[u] >= S[v] && E[u] <= E[v]); }
void addToLeaf(int u, int v, int x) {
  int s = -1;
  for (int i = 0; i < g[u].size(); i++)
    if (isUinV(g[u][i], u) && isUinV(v, g[u][i])) {
      s = g[u][i];
      break;
    }
  int l1 = -1, l2 = -1;
  for (int i = 0; i < g[u].size(); i++) {
    if (g[u][i] == s) continue;
    int l = getLeaf(g[u][i], u);
    if (l == -1) continue;
    if (l1 == -1)
      l1 = l;
    else {
      l2 = l;
      break;
    }
  }
  sol.push_back({{v, l1}, x / 2});
  sol.push_back({{v, l2}, x / 2});
  sol.push_back({{l1, l2}, -x / 2});
}
void add(int u, int v, int x) {
  int w = -1;
  for (int i = 0; i < allLeafs.size(); i++) {
    int o = allLeafs[i];
    if (isUinV(o, v)) {
      w = o;
      break;
    }
  }
  addToLeaf(u, w, x);
  addToLeaf(v, w, -x);
}
int main() {
  scanf("%d", &n);
  g.resize(n);
  for (int i = 1, a, b, c; i < n; i++) {
    scanf("%d%d%d", &a, &b, &c);
    a--, b--;
    g[a].push_back(b);
    g[b].push_back(a);
    e.push_back({{a, b}, c});
    d[a]++;
    d[b]++;
  }
  int root = -1;
  for (int i = 0; i < n; i++) {
    if (d[i] == 2) {
      puts("NO");
      return 0;
    }
    if (root == -1 && d[i] != 1) root = i;
  }
  if (root == -1) {
    printf("YES\n1\n%d %d %d\n", e[0].first.first + 1, e[0].first.second + 1,
           e[0].second);
    return 0;
  }
  dfs(root, -1);
  for (int i = 0; i < e.size(); i++) {
    int u = e[i].first.first, v = e[i].first.second;
    if (dpth[u] > dpth[v]) swap(u, v);
    if (isLeaf[v])
      addToLeaf(u, v, e[i].second);
    else
      add(u, v, e[i].second);
  }
  printf("YES\n%d\n", sol.size());
  for (int i = 0; i < sol.size(); i++)
    printf("%d %d %d\n", sol[i].first.first + 1, sol[i].first.second + 1,
           sol[i].second);
  return 0;
}
