#include <bits/stdc++.h>
using namespace std;
const long long mod = 1000000007;
long long powmod(long long a, long long b) {
  long long res = 1;
  a %= mod;
  assert(b >= 0);
  for (; b; b >>= 1) {
    if (b & 1) res = res * a % mod;
    a = a * a % mod;
  }
  return res;
}
long long gcd(long long a, long long b) { return b ? gcd(b, a % b) : a; }
struct Edge {
  int u, v, w;
  Edge(int u, int v, int w) : u(u), v(v), w(w) {}
};
const int maxn = 1e3 + 100;
vector<Edge> e;
vector<int> G[maxn];
vector<Edge> ans;
int a, b, c, d;
void dfs(int x, int y) {
  if (G[x].size() == 1) {
    if (a == 0) a = x;
    b = x;
  }
  for (auto xx : G[x]) {
    if (xx != y) dfs(xx, x);
  }
}
void dfs2(int x, int y) {
  if (G[x].size() == 1) {
    if (c == 0) c = x;
    d = x;
  }
  for (auto xx : G[x]) {
    if (xx != y) dfs2(xx, x);
  }
}
int n, u, v, w;
int main(int argc, char const *argv[]) {
  ios_base::sync_with_stdio(false), cin.tie(0), cout.tie(0);
  cin >> n;
  for (int i = 0; i < n - 1; i++) {
    cin >> u >> v >> w;
    e.push_back(Edge(u, v, w));
    G[u].push_back(v);
    G[v].push_back(u);
  }
  for (int i = 1; i < n + 1; i++) {
    if (G[i].size() == 2) {
      cout << "NO" << endl;
      return 0;
    }
  }
  cout << "YES" << endl;
  for (int i = 0; i < n - 1; i++) {
    u = e[i].u;
    v = e[i].v;
    w = e[i].w;
    a = b = c = d = 0;
    dfs(u, v);
    dfs2(v, u);
    ans.push_back(Edge(a, c, w / 2));
    ans.push_back(Edge(b, d, w / 2));
    if (a != b) ans.push_back(Edge(a, b, -w / 2));
    if (c != d) ans.push_back(Edge(c, d, -w / 2));
  }
  cout << ans.size() << endl;
  for (auto s : ans) {
    cout << s.u << " " << s.v << " " << s.w << endl;
  }
  return 0;
}
