#include <bits/stdc++.h>
using namespace std;
const int N = 1e3 + 5;
vector<pair<pair<int, int>, int>> vec;
vector<pair<int, int>> adj[N];
pair<int, int> down[N];
int n, up[N], w[N];
inline void add(int u, int v, int k) {
  if (k) vec.push_back({{u, v}, k});
}
void pre_dfs(int u, int par = -1) {
  if (adj[u].size() == 2) {
    cout << "NO";
    exit(0);
  }
  down[u] = {u, u};
  for (auto v : adj[u])
    if (v.first ^ par) {
      w[v.first] = v.second;
      pre_dfs(v.first, u);
      if (down[u].first == u)
        down[u] = {v.first, down[v.first].second};
      else {
        up[down[u].first] = down[v.first].second;
        up[v.first] = down[u].second;
      }
    }
}
void add_dfs(int u, int x) {
  if (adj[u].size() == 1) return;
  w[down[u].first] += x;
  add_dfs(down[u].first, x);
}
void dfs(int u, int par = -1) {
  if (adj[u].size() == 1) return;
  pair<int, int> v1 = down[u], v2 = {u, up[u]}, v3 = {u, up[u]};
  if (!~par)
    for (auto v : adj[u])
      if (v.first ^ v1.first) {
        v2 = {v.first, down[v.first].second};
        break;
      }
  for (auto v : adj[u])
    if (v.first ^ par && v.first ^ v1.first && v.first ^ v2.first) {
      v3 = {v.first, down[v.first].second};
      add(v1.second, v3.second, w[v.first] / 2);
      add(v2.second, v3.second, w[v.first] / 2);
      add(v1.second, v2.second, -w[v.first] / 2);
      add_dfs(v.first, -w[v.first]), dfs(v.first, u);
    }
  add(v1.second, v2.second, w[v1.first] / 2);
  add(v1.second, v3.second, w[v1.first] / 2);
  add(v2.second, v3.second, -w[v1.first] / 2);
  add_dfs(v1.first, -w[v1.first]), dfs(v1.first, u);
  if (!~par) {
    add(v1.second, v2.second, w[v2.first] / 2);
    add(v2.second, v3.second, w[v2.first] / 2);
    add(v1.second, v3.second, -w[v2.first] / 2);
    add_dfs(v2.first, -w[v2.first]), dfs(v2.first, u);
  }
}
inline void read_input() {
  cin >> n;
  for (int i = 1; i < n; i++) {
    int u, v, w;
    cin >> u >> v >> w;
    adj[--u].push_back({--v, w});
    adj[v].push_back({u, w});
  }
}
inline void solve() {
  for (int u = 0; u < n; u++)
    if (adj[u].size() > 1) {
      pre_dfs(u), dfs(u);
      return;
    }
  add(0, 1, adj[0][0].second);
}
inline void write_output() {
  cout << "YES\n" << vec.size() << endl;
  for (auto x : vec) {
    cout << ++x.first.first << ' ' << ++x.first.second;
    cout << ' ' << x.second << endl;
  }
}
int main() {
  ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
  read_input(), solve(), write_output();
  return 0;
}
