#include <bits/stdc++.h>
using namespace std;
int n;
struct edge {
  int d;
  int nxt;
  bool operator<(const edge &e) const { return nxt < e.nxt; }
};
set<edge> fake[1003];
vector<edge> graph[1003];
inline int deg(int u) { return (int)graph[u].size(); }
pair<int, int> find_two(int u, int v) {
  vector<int> two;
  for (auto &p : graph[u]) {
    if (p.nxt == v) continue;
    two.push_back(p.nxt);
    if ((int)two.size() == 2) break;
  }
  pair<int, int> res;
  for (int i = 0; i < 2; i++) {
    int node = two[i], par = u;
    while (deg(node) != 1) {
      for (auto &p : graph[node]) {
        if (p.nxt == par) continue;
        par = node;
        node = p.nxt;
        break;
      }
    }
    if (i == 0)
      res.first = node;
    else
      res.second = node;
  }
  return res;
}
int main() {
  ios::sync_with_stdio(false);
  cin.tie(NULL);
  cin >> n;
  for (int i = 0; i < n - 1; i++) {
    int u, v, c;
    cin >> u >> v >> c;
    fake[u].insert({c, v});
    fake[v].insert({c, u});
  }
  for (int i = 1; i <= n; i++) {
    if ((int)fake[i].size() == 2) {
      auto e0 = *fake[i].begin();
      auto e1 = *next(fake[i].begin());
      if (e0.d != e1.d) {
        cout << "NO" << '\n';
        return 0;
      }
      int u = e0.nxt, v = e1.nxt;
      int d = e0.d;
      fake[u].erase({i, d});
      fake[v].erase({i, d});
      fake[u].insert({d, v});
      fake[v].insert({d, u});
      fake[i].clear();
    }
  }
  vector<pair<int, edge>> vp;
  for (int i = 1; i <= n; i++) {
    for (auto &p : fake[i]) {
      graph[i].push_back(p);
      if (i < p.nxt) vp.emplace_back(i, p);
    }
  }
  vector<tuple<int, int, int>> ans;
  for (auto &p : vp) {
    int u = p.first, v = p.second.nxt, c = p.second.d;
    if (deg(u) == 1) {
      if (deg(v) == 1) {
        ans.emplace_back(u, v, c);
      } else {
        int v1, v2;
        tie(v1, v2) = find_two(v, u);
        ans.emplace_back(v1, v2, -c / 2);
        ans.emplace_back(v1, u, c / 2);
        ans.emplace_back(v2, u, c / 2);
      }
    } else if (deg(v) == 1) {
      int u1, u2;
      tie(u1, u2) = find_two(u, v);
      ans.emplace_back(u1, u2, -c / 2);
      ans.emplace_back(u1, v, c / 2);
      ans.emplace_back(u2, v, c / 2);
    } else {
      int u1, u2, v1, v2;
      tie(u1, u2) = find_two(u, v);
      tie(v1, v2) = find_two(v, u);
      ans.emplace_back(u1, u2, -c / 2);
      ans.emplace_back(v1, v2, -c / 2);
      ans.emplace_back(u1, v1, c / 2);
      ans.emplace_back(u2, v2, c / 2);
    }
  }
  cout << "YES" << '\n';
  cout << ans.size() << '\n';
  for (auto &t : ans) {
    int u, v, c;
    tie(u, v, c) = t;
    cout << u << ' ' << v << ' ' << c << '\n';
  }
  return 0;
}
