#include <bits/stdc++.h>
using namespace std;
vector<pair<int, int>> g[1010];
vector<int> l1, l2;
vector<pair<pair<int, int>, int>> ans;
int le[1010];
int prec(int x, int par) {
  int ans = x;
  for (auto y : g[x])
    if (y.first != par) ans = prec(y.first, x);
  return le[x] = ans;
}
void getl(vector<int> &v, int x, int pre) {
  if (int(g[x].size()) == 1) v.push_back(x);
  for (auto y : g[x])
    if (y.first != pre && int(v.size()) < 2) v.push_back(prec(y.first, x));
}
void dfs(int pos, int pre) {
  for (auto x : g[pos])
    if (x.first != pre) {
      int v = x.second / 2;
      l1.clear();
      l2.clear();
      getl(l1, x.first, pos);
      getl(l2, pos, x.first);
      if (int(l1.size()) > int(l2.size())) swap(l1, l2);
      if (int(l1.size()) == 1 && int(l2.size()) == 1)
        ans.push_back({{l1[0], l2[0]}, x.second});
      else if (int(l1.size()) == 1 && int(l2.size()) == 2) {
        ans.push_back({{l1[0], l2[0]}, v});
        ans.push_back({{l1[0], l2[1]}, v});
        ans.push_back({{l2[0], l2[1]}, -v});
      } else if (int(l1.size()) == 2 && int(l2.size()) == 2) {
        ans.push_back({{l1[0], l2[0]}, v});
        ans.push_back({{l1[1], l2[1]}, v});
        ans.push_back({{l1[0], l1[1]}, -v});
        ans.push_back({{l2[0], l2[1]}, -v});
      }
      dfs(x.first, pos);
    }
}
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  int n;
  cin >> n;
  for (int i = 1, ThxDem = n; i < ThxDem; ++i) {
    int x, y, w;
    cin >> x >> y >> w;
    x--;
    y--;
    g[x].push_back({y, w});
    g[y].push_back({x, w});
  }
  for (int i = 0, ThxDem = n; i < ThxDem; ++i)
    if (int(g[i].size()) == 2) cout << "NO\n", exit(0);
  dfs(0, -1);
  cout << "YES\n" << int(ans.size()) << "\n";
  for (auto x : ans)
    cout << x.first.first + 1 << " " << x.first.second + 1 << " " << x.second
         << "\n";
}
