#include <bits/stdc++.h>
using namespace std;
int n, t1, t2, t3, t4, t5, dif, yes, rep, cnt[1005], last[1005],
    ans[1005][1005], ma[1005][1005];
vector<int> nod, re, v[1005];
vector<pair<int, int> > path, more;
vector<pair<pair<int, int>, int> > sol;
bool vis[1005];
pair<int, int> pl, pr;
bool ok;
void clr() {
  for (int i = 1; i <= n; i++) vis[i] = 0;
  return;
}
int any(int mo) {
  vis[mo] = 1;
  if (v[mo].size() == 1)
    return mo;
  else {
    for (int i = 0; i < v[mo].size(); i++) {
      if (!vis[v[mo][i]]) {
        return any(v[mo][i]);
      }
    }
  }
}
pair<int, int> exp(int mo) {
  clr();
  vis[t4] = 1, vis[t5] = 1;
  vector<int> ret;
  for (int i = 0; i < v[mo].size(); i++) {
    if (v[mo][i] != t4 && v[mo][i] != t5) {
      ret.push_back(any(v[mo][i]));
      if (ret.size() > 1) {
        return make_pair(ret[0], ret[1]);
      }
    }
  }
}
void dfs(int from, int to, int val) {
  ok = 0;
  vis[from] = 1;
  if (from == to) {
    ok = 1, yes = from;
    return;
  }
  for (int i = 0; i < v[from].size(); i++) {
    if (!vis[v[from][i]] && !ok) {
      dfs(v[from][i], to, val);
    }
  }
  if (ok) {
    ma[from][yes] += val;
    ma[yes][from] += val;
    yes = from;
    return;
  }
}
int main() {
  cin >> n;
  for (int i = 0; i < n - 1; i++) {
    cin >> t1 >> t2 >> t3;
    path.push_back(make_pair(t1, t2));
    cnt[t1]++, cnt[t2]++;
    last[t1] = t3, last[t2] = t3;
    v[t1].push_back(t2);
    v[t2].push_back(t1);
    ans[t1][t2] = t3;
  }
  for (int i = 1; i <= n; i++) {
    if (cnt[i] == 2) {
      cout << "NO" << endl;
      return 0;
    }
    if (cnt[i] == 1 && last[i] != 0) {
      nod.push_back(i);
    }
  }
  for (int i = 0; i < path.size(); i++) {
    if (cnt[path[i].first] > 1 && cnt[path[i].second] > 1) {
      more.push_back(path[i]);
    }
  }
  sort(nod.begin(), nod.end());
  while (nod.size() > 1) {
    sol.push_back(make_pair(make_pair(nod[0], nod[1]), last[nod[0]]));
    clr();
    dfs(nod[0], nod[1], last[nod[0]]);
    last[nod[1]] -= last[nod[0]];
    if (re.size() < 2) re.push_back(nod[0]);
    nod.erase(nod.begin());
  }
  if (nod.size() == 1 && n > 2) {
    sol.push_back(make_pair(make_pair(re[1], nod[0]), last[nod[0]] / 2));
    clr();
    dfs(re[1], nod[0], last[nod[0]] / 2);
    sol.push_back(make_pair(make_pair(re[0], re[1]), last[nod[0]] / -2));
    clr();
    dfs(re[0], re[1], last[nod[0]] / -2);
    sol.push_back(make_pair(make_pair(re[0], nod[0]), last[nod[0]] / 2));
    clr();
    dfs(re[0], nod[0], last[nod[0]] / 2);
  }
  for (int i = 0; i < more.size(); i++) {
    t4 = more[i].first, t5 = more[i].second;
    if (ma[t4][t5] != ans[t4][t5]) {
      pl = exp(t4), pr = exp(t5), dif = ans[t4][t5] - ma[t4][t5];
      sol.push_back(make_pair(make_pair(pl.first, pr.first), dif / 2));
      sol.push_back(make_pair(make_pair(pl.second, pr.second), dif / 2));
      sol.push_back(make_pair(make_pair(pl.first, pl.second), dif / -2));
      sol.push_back(make_pair(make_pair(pr.first, pr.second), dif / -2));
    }
  }
  cout << "YES" << endl << sol.size() << endl;
  for (int i = 0; i < sol.size(); i++) {
    cout << sol[i].first.first << ' ' << sol[i].first.second << ' '
         << sol[i].second << endl;
  }
}
