#include <bits/stdc++.h>
using namespace std;
int n;
vector<pair<pair<int, int>, int>> sol;
vector<int> G[1000];
vector<pair<pair<int, int>, int>> E;
bool seen[1000];
int DFS(int u) {
  seen[u] = true;
  if (G[u].size() == 1) return u;
  for (int v : G[u])
    if (!seen[v]) return DFS(v);
}
void do_edge(int u, int v, int val) {
  int u1, u2, v1, v2;
  fill(seen, seen + n, false);
  seen[u] = true;
  seen[v] = true;
  if (G[u].size() == 1) {
    u1 = u;
    u2 = u;
  } else {
    if (G[u][0] == v) swap(G[u][0], G[u][2]);
    if (G[u][1] == v) swap(G[u][1], G[u][2]);
    u1 = DFS(G[u][0]);
    u2 = DFS(G[u][1]);
  }
  if (G[v].size() == 1) {
    v1 = v;
    v2 = v;
  } else {
    if (G[v][0] == u) swap(G[v][0], G[v][2]);
    if (G[v][1] == u) swap(G[v][1], G[v][2]);
    v1 = DFS(G[v][0]);
    v2 = DFS(G[v][1]);
  }
  sol.push_back(make_pair(make_pair(u1, v1), val / 2));
  sol.push_back(make_pair(make_pair(u2, v2), val / 2));
  if (u1 != u2) sol.push_back(make_pair(make_pair(u1, u2), -val / 2));
  if (v1 != v2) sol.push_back(make_pair(make_pair(v1, v2), -val / 2));
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cin >> n;
  for (int i = 0; i < n - 1; i++) {
    int u, v, val;
    cin >> u >> v >> val;
    u--;
    v--;
    E.push_back(make_pair(make_pair(u, v), val));
    G[u].push_back(v);
    G[v].push_back(u);
  }
  for (int i = 0; i < n; i++) {
    if (G[i].size() == 2) {
      cout << "NO" << endl;
      return 0;
    }
  }
  for (int i = 0; i < E.size(); i++) {
    do_edge(E[i].first.first, E[i].first.second, E[i].second);
  }
  cout << "YES\n" << sol.size() << "\n";
  for (int i = 0; i < sol.size(); i++) {
    cout << sol[i].first.first + 1 << " " << sol[i].first.second + 1 << " "
         << sol[i].second << "\n";
  }
  return 0;
}
