#include <bits/stdc++.h>
using namespace std;
const int N = 1005;
long long add[N];
int f[N];
int n, rt;
struct node {
  int u, v;
  long long x;
};
vector<pair<int, int> > g[N];
vector<int> son[N];
vector<node> ans;
void Read() {
  cin >> n;
  int u, v, x;
  for (register int i = (2); i <= (n); ++i) {
    cin >> u >> v >> x;
    g[u].push_back(make_pair(v, x));
    g[v].push_back(make_pair(u, x));
  }
}
int dfs(int u, int fa) {
  f[u] = fa;
  for (int i = 0; i < g[u].size(); ++i) {
    int v = g[u][i].first;
    if (v == fa) continue;
    int tmp = dfs(v, u);
    son[u].push_back(tmp);
  }
  if (g[u].size() == 1) return u;
  return son[u][0];
}
void Update(int u, int goal, int val) {
  while (u != goal) {
    add[u] += val;
    u = f[u];
  }
}
void Dfs(int u, int fa) {
  if (u == rt) {
    int v = g[u][0].first, w = g[u][0].second;
    if (g[v].size() == 1) {
      ans.push_back((node){u, v, w});
      return;
    }
    ans.push_back((node){son[v][0], u, w / 2});
    ans.push_back((node){son[v][1], u, w / 2});
    ans.push_back((node){son[v][0], son[v][1], -w / 2});
    Dfs(v, u);
  } else {
    int cnt = 0;
    for (int i = 0; i < g[u].size(); ++i) {
      int v = g[u][i].first, w = g[u][i].second;
      if (v == fa) continue;
      long long tmp = w - add[v];
      int cas = !cnt;
      ans.push_back((node){son[u][cnt], rt, tmp / 2});
      ans.push_back((node){son[u][cnt], son[u][cas], tmp / 2});
      ans.push_back((node){rt, son[u][cas], -tmp / 2});
      Update(son[u][cnt], u, tmp);
      Dfs(v, u);
      ++cnt;
    }
  }
}
int main() {
  Read();
  for (register int i = (1); i <= (n); ++i)
    if (g[i].size() == 2) {
      puts("NO");
      return 0;
    }
  puts("YES");
  for (register int i = (1); i <= (n); ++i)
    if (g[i].size() == 1) {
      rt = i;
      break;
    }
  dfs(rt, 0);
  Dfs(rt, 0);
  cout << ans.size() << endl;
  for (int i = 0; i < ans.size(); ++i)
    cout << ans[i].u << ' ' << ans[i].v << ' ' << ans[i].x << endl;
  return 0;
}
