#include <bits/stdc++.h>
using namespace std;
const int MX = 1005;
int n, u, v, val, ra[6 * MX], rb[6 * MX], rx[6 * MX], r;
vector<pair<int, int> > adj[MX];
int dfs(int u, int p) {
  for (pair<int, int> &v : adj[u])
    if (v.first != p) return dfs(v.first, u);
  return u;
}
bool dfs(int u, int p, int t) {
  if (u == t) return 1;
  for (pair<int, int> &v : adj[u])
    if (v.first != p && dfs(v.first, u, t)) return 1;
  return 0;
}
void insert(int u, int v, int w) {
  ra[r] = u, rb[r] = v, rx[r] = w;
  r++;
}
void path(int u, int v, int w) {
  if (u == v) return;
  if (adj[v].size() == 1) {
    insert(u, v, w);
    return;
  }
  int l1 = -1, l2 = -1, l3 = -1;
  for (pair<int, int> &e : adj[v]) {
    if (l1 == -1)
      l1 = e.first;
    else if (l2 == -1)
      l2 = e.first;
    else if (l3 == -1)
      l3 = e.first;
    else
      break;
  }
  if (dfs(l1, v, u)) swap(l1, l3);
  if (dfs(l2, v, u)) swap(l2, l3);
  l1 = dfs(l1, v);
  l2 = dfs(l2, v);
  insert(u, l1, w / 2);
  insert(u, l2, w / 2);
  insert(l1, l2, -w / 2);
}
void solve(int u, int v, int w) {
  int l = dfs(u, v);
  path(l, v, w);
  path(l, u, -w);
}
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cin >> n;
  for (int i = 1; i < n; i++) {
    cin >> u >> v >> val;
    adj[u].emplace_back(v, val);
    adj[v].emplace_back(u, val);
  }
  if (n == 2) {
    cout << "YES" << '\n' << 1 << '\n';
    cout << 1 << " " << 2 << " " << adj[1].begin()->second << '\n';
    return 0;
  }
  for (int i = 1; i <= n; i++)
    if (adj[i].size() == 2) {
      cout << "NO" << '\n';
      return 0;
    }
  for (int u = 1; u <= n; u++)
    for (pair<int, int> v : adj[u])
      if (v.first < u) solve(u, v.first, v.second);
  cout << "YES" << '\n';
  cout << r << '\n';
  for (int i = 0; i < r; i++)
    cout << ra[i] << " " << rb[i] << " " << rx[i] << '\n';
  return 0;
}
