#include <bits/stdc++.h>
using namespace std;
vector<vector<int>> ans;
vector<pair<int, int>> G[1001];
vector<int> leaves[1001];
bool visited[1001];
int pr[1001];
int root = 1;
void add_edge(int v, int x) {
  if (leaves[v].size() == 1) {
    ans.push_back({root, v, x});
  } else {
    ans.push_back({root, leaves[v][0], x / 2});
    ans.push_back({root, leaves[v][1], x / 2});
    ans.push_back({leaves[v][0], leaves[v][1], -x / 2});
  }
  if (pr[v] == root) return;
  if (leaves[pr[v]].size() == 1) {
    ans.push_back({root, pr[v], -x});
    return;
  } else {
    ans.push_back({root, leaves[pr[v]][0], -x / 2});
    ans.push_back({root, leaves[pr[v]][1], -x / 2});
    ans.push_back({leaves[pr[v]][0], leaves[pr[v]][1], x / 2});
  }
}
void dfs(int s, int x) {
  visited[s] = true;
  for (auto it : G[s]) {
    if (!visited[it.first]) {
      if (x) {
        pr[it.first] = s;
        dfs(it.first, 1);
        leaves[s].push_back(leaves[it.first][0]);
      } else {
        add_edge(it.first, it.second);
        dfs(it.first, 0);
      }
    }
  }
  if (leaves[s].empty()) leaves[s].push_back(s);
}
int main() {
  int n;
  cin >> n;
  int u, v, val;
  for (int i = 0; i < n - 1; i++) {
    cin >> u >> v >> val;
    G[u].push_back(make_pair(v, val));
    G[v].push_back(make_pair(u, val));
  }
  for (int i = 1; i <= n; i++) {
    if (G[i].size() == 2) {
      cout << "NO";
      return 0;
    }
  }
  cout << "YES" << endl;
  while (G[root].size() != 1) root++;
  dfs(root, 1);
  memset(visited, 0, sizeof visited);
  dfs(root, 0);
  cout << ans.size() << endl;
  for (auto it : ans) cout << it[0] << " " << it[1] << " " << it[2] << endl;
}
