#include <bits/stdc++.h>
using namespace std;
const int MAXN = 1111;
int n;
vector<int> adj[MAXN];
vector<tuple<int, int, int>> sol;
int w[MAXN][MAXN];
int findleaf(int curr, int avoid, int add) {
  for (auto x : adj[curr]) {
    if (x != avoid) {
      w[curr][x] += add;
      w[x][curr] += add;
      return findleaf(x, curr, add);
    }
  }
  return curr;
}
void dfs(int curr, int prev) {
  for (int i = 0; i < adj[curr].size(); i++) {
    int nxt = adj[curr][i];
    if (nxt == prev) {
      continue;
    }
    int val = w[curr][nxt] / 2;
    int l1, l2;
    if (i == 0) {
      l1 = adj[curr][i + 1];
      l2 = adj[curr][i + 2];
    } else if (i + 1 == adj[curr].size()) {
      l1 = adj[curr][i - 1];
      l2 = adj[curr][i - 2];
    } else {
      l1 = adj[curr][i - 1];
      l2 = adj[curr][i + 1];
    }
    l1 = findleaf(l1, curr, 0);
    l2 = findleaf(l2, curr, 0);
    int u = findleaf(nxt, curr, 0);
    sol.push_back({u, l1, val});
    sol.push_back({u, l2, val});
    sol.push_back({l1, l2, -val});
    w[curr][nxt] = 0;
    w[nxt][curr] = 0;
    findleaf(nxt, curr, -2 * val);
    dfs(nxt, curr);
  }
}
int main() {
  ios_base::sync_with_stdio(false);
  cin >> n;
  for (int i = 1; i < n; i++) {
    int a, b, c;
    cin >> a >> b >> c;
    a--;
    b--;
    adj[a].push_back(b);
    adj[b].push_back(a);
    w[a][b] = c;
    w[b][a] = c;
  }
  for (int i = 0; i < n; i++) {
    if (adj[i].size() == 2) {
      cout << "NO" << endl;
      return 0;
    }
  }
  for (int i = 0; i < n; i++) {
    if (adj[i].size() > 1) {
      dfs(i, -1);
      break;
    }
  }
  if (n == 2) {
    cout << "YES" << endl;
    cout << 1 << endl;
    cout << "1 2 " << w[0][1] << endl;
    return 0;
  }
  cout << "YES" << endl << sol.size() << endl;
  for (auto x : sol) {
    cout << get<0>(x) + 1 << " " << get<1>(x) + 1 << " " << get<2>(x) << endl;
  }
  return 0;
}
