#include <bits/stdc++.h>
using namespace std;
vector<bool> used;
vector<vector<int>> res(0, vector<int>(3));
vector<int> pr;
vector<vector<pair<int, int>>> gr;
vector<vector<int>> leaves;
int first;
void l_dfs(int v) {
  used[v] = true;
  for (auto& to : gr[v])
    if (!used[to.first]) {
      l_dfs(to.first);
      pr[to.first] = v;
      leaves[v].push_back(leaves[to.first][0]);
    }
  if (leaves[v].size() == 0) leaves[v].push_back(v);
}
void add(int v, int x) {
  if (leaves[v].size() == 1) {
    res.push_back({first, v, x});
    return;
  }
  res.push_back({first, leaves[v][0], x / 2});
  res.push_back({first, leaves[v][1], x / 2});
  res.push_back({leaves[v][0], leaves[v][1], -x / 2});
}
void Doedge(int v, int x) {
  if (pr[v] == first) {
    add(v, x);
    return;
  }
  add(v, x);
  add(pr[v], -x);
}
void dfs(int v) {
  used[v] = true;
  for (auto& to : gr[v])
    if (!used[to.first]) {
      Doedge(to.first, to.second);
      dfs(to.first);
    }
}
int main() {
  std::ios::sync_with_stdio(false);
  int n;
  cin >> n;
  pr.resize(n);
  leaves.resize(n, vector<int>());
  gr.resize(n, vector<pair<int, int>>());
  for (int i = 1; i < n; i++) {
    int u, v, val;
    cin >> u >> v >> val;
    u--;
    v--;
    auto p = make_pair(u, val);
    gr[v].push_back(p);
    p = make_pair(v, val);
    gr[u].push_back(p);
  }
  first = 0;
  for (int i = 0; i < n; i++) {
    if (gr[i].size() == 2) {
      cout << "NO";
      return 0;
    }
  }
  cout << "YES" << endl;
  while (gr[first].size() != 1) first++;
  used.resize(n);
  l_dfs(first);
  used.assign(n, false);
  dfs(first);
  cout << res.size() << endl;
  for (auto& i : res) {
    cout << i[0] + 1 << " " << i[1] + 1 << " " << i[2] << endl;
  }
  return 0;
}
