#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ull = unsigned long long;
using ld = long double;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
const int N = 1010;
vector<pii> g[N];
int lst[N], root;
struct item {
  int u, v, x;
};
vector<item> ans;
void add_to_ans(int v, int to, int third, int x) {
  ans.push_back({root, to, x / 2});
  ans.push_back({third, to, x / 2});
  ans.push_back({root, third, -x / 2});
  return;
}
void dfs(int v, int parent = -1, int x = 0) {
  lst[v] = v;
  for (auto to : g[v])
    if (to.first != parent) {
      dfs(to.first, v, -to.second);
      lst[v] = lst[to.first];
    }
  if (lst[v] == v) {
    return;
  }
  if (v == root) {
    ans.push_back({v, lst[g[v].back().first], g[v].back().second});
    return;
  }
  for (auto to : g[v])
    if (to.first != parent) {
      int third = 0;
      for (auto i : g[v])
        if (i.first != parent && i.first != to.first) {
          third = lst[i.first];
          break;
        }
      add_to_ans(v, lst[to.first], third, to.second);
    }
  int third = 0;
  for (auto i : g[v])
    if (i.first != parent && lst[i.first] != lst[v]) {
      third = lst[i.first];
      break;
    }
  add_to_ans(v, lst[v], third, x);
  return;
}
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  cout << fixed << setprecision(10);
  int n;
  cin >> n;
  for (int i = 0; i < n - 1; i++) {
    int u, v, x;
    cin >> u >> v >> x;
    g[u].emplace_back(v, x);
    g[v].emplace_back(u, x);
  }
  bool ok = true;
  for (int i = 1; i <= n; i++) ok &= (g[i].size() != 2);
  if (!ok) {
    cout << "NO" << endl;
    return 0;
  }
  for (int i = 1; i <= n; i++) {
    if (g[i].size() == 1) {
      root = i;
      dfs(i);
      break;
    }
  }
  cout << "YES" << endl;
  cout << ans.size() << endl;
  for (auto i : ans) cout << i.u << " " << i.v << " " << i.x << endl;
  return 0;
}
