#include <bits/stdc++.h>
using namespace std;
const int maxn = 1e3 + 10;
int deg[maxn]{0}, root, n;
vector<int> es[maxn];
int leaf[maxn][2], f[maxn];
void dfs(int x, int fa) {
  if (x != root && es[x].size() == 1) {
    leaf[x][0] = x;
    leaf[x][1] = -1;
    return;
  }
  vector<int> vec;
  for (auto y : es[x]) {
    if (y == fa) continue;
    f[y] = x;
    dfs(y, x);
    if (vec.size() < 2) {
      vec.push_back(leaf[y][0]);
    }
  }
  if (vec.size() == 1) {
    leaf[x][0] = vec[0];
    leaf[x][1] = -1;
  } else {
    leaf[x][0] = vec[0];
    leaf[x][1] = vec[1];
  }
}
int a[maxn][maxn], b[maxn];
struct P {
  int x, y, z;
  P(int a, int b, int c) { x = a, y = b, z = c; }
};
vector<P> ans;
void solve(int x, int z) {
  if (x == root) return;
  if (leaf[x][1] == -1) {
    ans.push_back(P(root, leaf[x][0], z));
    b[leaf[x][0]] += z;
  } else {
    ans.push_back(P(root, leaf[x][0], z / 2));
    ans.push_back(P(root, leaf[x][1], z / 2));
    ans.push_back(P(leaf[x][0], leaf[x][1], -z / 2));
    b[x] += z;
  }
}
void update(int x, int fa) {
  for (auto y : es[x]) {
    if (y == fa) continue;
    update(y, x);
    b[x] += b[y];
  }
}
bool check() {
  for (int i = 1; i <= n; i++) {
    if (i == root) continue;
    if (a[f[i]][i] != b[i]) return false;
  }
  return true;
}
int main() {
  cin >> n;
  for (int i = 1; i < n; i++) {
    int x, y, z;
    scanf("%d%d%d", &x, &y, &z);
    es[x].push_back(y);
    es[y].push_back(x);
    a[x][y] = a[y][x] = z;
    deg[x]++;
    deg[y]++;
  }
  for (int i = 1; i <= n; i++) {
    if (deg[i] == 1) {
      root = i;
      break;
    }
  }
  dfs(root, 0);
  for (int i = 1; i <= n; i++) {
    if (i == root) continue;
    int fi = f[i], z = a[fi][i];
    solve(i, z);
    solve(fi, -z);
  }
  update(root, 0);
  if (check()) {
    puts("YES");
    cout << ans.size() << endl;
    for (auto p : ans) printf("%d %d %d\n", p.x, p.y, p.z);
  } else {
    puts("NO");
  }
}
