#include <bits/stdc++.h>
using namespace std;
const int INF = 1e9 + 7;
vector<int> G[1024];
vector<pair<pair<int, int>, int>> e, ans, out;
int dfs(int u, int p) {
  for (int v : G[u])
    if (v != p) return dfs(v, u);
  return u;
}
int main() {
  std::ios::sync_with_stdio(0);
  std::cin.tie(0);
  ;
  int n;
  cin >> n;
  for (int i = 0; i < n - 1; i++) {
    int u, v, val;
    cin >> u >> v >> val;
    G[u].push_back(v);
    G[v].push_back(u);
    e.push_back({{u, v}, val / 2});
  }
  for (int i = 1; i <= n; i++) {
    if (G[i].size() == 2) {
      cout << "NO" << endl;
      return 0;
    }
  }
  cout << "YES" << endl;
  for (auto p : e) {
    int u = p.first.first, v = p.first.second, val = p.second;
    vector<int> x, y;
    for (int w : G[u]) {
      if (x.size() == 2) break;
      if (w != v) x.push_back(w);
    }
    for (int w : G[v]) {
      if (y.size() == 2) break;
      if (w != u) y.push_back(w);
    }
    int a, b, c, d;
    a = b = u, c = d = v;
    if (x.size()) a = dfs(x[0], u), b = dfs(x[1], u);
    if (y.size()) c = dfs(y[0], v), d = dfs(y[1], v);
    ans.push_back({{a, c}, val});
    ans.push_back({{b, d}, val});
    ans.push_back({{a, b}, -val});
    ans.push_back({{c, d}, -val});
  }
  for (auto p : ans) {
    if (p.first.first != p.first.second) out.push_back(p);
  }
  cout << out.size() << endl;
  for (auto p : out)
    cout << p.first.first << " " << p.first.second << " " << p.second << endl;
}
