#include <bits/stdc++.h>
using namespace std;
const int mod = 1e9 + 7;
const int oo = 1e9 + 7;
const int N = 2e5 + 5;
long long d[N];
struct ccc {
  long long x, y, z;
} a[N];
vector<ccc> ans;
long long p[N][3], dp[N], f[N];
vector<long long> e[N];
bool ok[N];
void dfs(long long s, long long h) {
  ok[s] = 1;
  dp[s] = h;
  if (d[s] == 1 && s != 1) p[s][0] = s;
  long long c = 0;
  for (int i = 0; i < e[s].size(); ++i) {
    long long u = e[s][i];
    if (ok[u]) continue;
    f[u] = s;
    dfs(u, h + 1);
    if (c < 3) p[s][c++] = p[u][0];
  }
}
int main() {
  long long n;
  cin >> n;
  long long x, y, z;
  for (int i = 1; i <= n - 1; ++i) {
    cin >> x >> y >> z;
    e[x].push_back(y);
    e[y].push_back(x);
    a[i] = {x, y, z};
    ++d[x];
    ++d[y];
  }
  if (n > 2)
    for (int i = 1; i <= n; ++i) {
      if (d[i] == 2) {
        cout << "NO";
        return 0;
      }
    }
  cout << "YES\n";
  if (n == 2) {
    cout << "1\n";
    cout << a[1].x << ' ' << a[1].y << ' ' << a[1].z;
    return 0;
  }
  dfs(1, 1);
  if (d[1] == 1) p[1][0] = 1;
  for (int i = 1; i <= n - 1; ++i) {
    long long x = a[i].x, y = a[i].y, z = a[i].z;
    if (min(x, y) == 1) {
      if (x == 1) swap(x, y);
      if (d[1] == 1) {
        ans.push_back({y, p[x][0], z / 2});
        ans.push_back({y, p[x][1], z / 2});
        ans.push_back({p[x][0], p[x][1], -z / 2});
      } else {
        long long s1 = p[y][0], s2 = p[y][1];
        if (p[x][0] == p[y][0])
          s1 = p[y][2];
        else if (p[x][0] == p[y][1])
          s2 = p[y][2];
        ans.push_back({p[x][0], s1, z / 2});
        ans.push_back({p[x][0], s2, z / 2});
        ans.push_back({s1, s2, -z / 2});
        if (p[x][0] != x) a[(++n) - 1] = {p[x][0], x, -z};
      }
    } else {
      if (dp[y] > dp[x]) swap(x, y);
      long long v = f[y];
      long long t = p[y][0];
      if (p[x][0] == p[y][0]) t = p[y][1];
      if (p[x][0] == p[v][0] || t == p[v][0])
        v = p[v][1];
      else
        v = p[v][0];
      ans.push_back({p[x][0], t, z / 2});
      ans.push_back({p[x][0], v, z / 2});
      ans.push_back({t, v, -z / 2});
      if (p[x][0] != x) a[(++n) - 1] = {p[x][0], x, -z};
    }
  }
  cout << ans.size() << '\n';
  for (int i = 0; i < ans.size(); ++i) {
    cout << ans[i].x << ' ' << ans[i].y << ' ' << ans[i].z << '\n';
  }
  return 0;
}
