#include <bits/stdc++.h>
using namespace std;
using pii = pair<int, int>;
using tiii = tuple<int, int, int>;
vector<int> S;
vector<pii> adj[1009];
vector<tiii> ans;
int d[1009], rt, L[1009];
int go(int x, int p, int c) {
  if (x == p)
    return go(adj[x][0].first, x, adj[x][0].second);
  else if (d[x] == 1) {
    L[p] = L[x] = x;
    ans.push_back((tiii){x, S[0], -c});
    return -c;
  } else {
    int s = c, lc = -1, rc = -1;
    for (auto& it : adj[x]) {
      if (it.first != p) {
        s += go(it.first, x, it.second);
        if (lc == -1)
          lc = it.first;
        else if (rc == -1)
          rc = it.first;
      }
    }
    L[p] = L[x];
    ans.push_back((tiii){L[lc], S[0], -s / 2});
    ans.push_back((tiii){L[rc], S[0], -s / 2});
    ans.push_back((tiii){L[lc], L[rc], s / 2});
    return -c;
  }
}
int main() {
  int N;
  scanf("%d", &N);
  for (int i = 0; i < N - 1; i++) {
    int u, v, c;
    scanf("%d%d%d", &u, &v, &c);
    adj[u].push_back({v, c});
    adj[v].push_back({u, c});
    ++d[u];
    ++d[v];
  }
  if (N == 2) {
    puts("YES\n1");
    printf("1 2 %d", adj[1][0].second);
    return 0;
  }
  for (int i = 1; i <= N; i++) {
    if (d[i] == 2) return !printf("NO");
    if (d[i] == 1) S.push_back(i);
  }
  go(S[0], S[0], 0);
  puts("YES");
  printf("%d\n", ans.size());
  for (auto& it : ans) {
    int u, v, c;
    tie(u, v, c) = it;
    printf("%d %d %d\n", u, v, -c);
  }
  return 0;
}
