#include <bits/stdc++.h>
using namespace std;
std::vector<vector<long long int> > reqmat(1000,
                                           vector<long long int>(1000, -1));
std::vector<vector<long long int> > adjl(1000);
std::vector<long long int> degv(1000, 0);
long long int find(long long int v, long long int x) {
  long long int ans;
  if (degv[v] == 1) ans = v;
  for (int i = 0; i < adjl[v].size(); i++) {
    if (adjl[v][i] != x) {
      ans = find(adjl[v][i], v);
      break;
    }
  }
  return ans;
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  long long int i, j, k, n, m, p, q, t, ans = 0, sum = 0, ct = 0, flag = 0;
  cin >> n;
  long long int u, v, val;
  if (n == 2) {
    cin >> u >> v >> val;
    cout << "YES\n1\n";
    cout << u << " " << v << " " << val;
    return 0;
  }
  map<pair<long long int, long long int>, long long int> mp;
  for (i = 0; i < n - 1; i++) {
    cin >> u >> v >> val;
    u--;
    v--;
    reqmat[u][v] = val;
    reqmat[v][u] = val;
    degv[u]++;
    degv[v]++;
    mp[{u, v}] = val;
    adjl[u].push_back(v);
    adjl[v].push_back(u);
  }
  for (i = 0; i < n; i++) {
    if (degv[i] == 2) {
      cout << "NO";
      return 0;
    }
  }
  std::vector<pair<pair<long long int, long long int>, long long int> > rslt;
  long long int v1, v2, x1, x2, y1, y2, itn = 0;
  for (auto x : mp) {
    u = x.first.first;
    v = x.first.second;
    val = x.second;
    itn++;
    if (degv[u] == 1) {
      ct = 0;
      for (i = 0; i < n; i++) {
        if (reqmat[v][i] != -1 && i != u) {
          if (ct == 0)
            v1 = find(i, v);
          else
            v2 = find(i, v);
          ct++;
        }
        if (ct >= 2) break;
      }
      rslt.push_back({{u, v1}, reqmat[u][v] / 2});
      rslt.push_back({{u, v2}, reqmat[u][v] / 2});
      rslt.push_back({{v1, v2}, -reqmat[u][v] / 2});
    } else if (degv[v] == 1) {
      ct = 0;
      for (i = 0; i < n; i++) {
        if (reqmat[u][i] != -1 && i != v) {
          if (ct == 0)
            v1 = find(i, u);
          else
            v2 = find(i, u);
          ct++;
        }
        if (ct >= 2) break;
      }
      rslt.push_back({{v, v1}, reqmat[u][v] / 2});
      rslt.push_back({{v, v2}, reqmat[u][v] / 2});
      rslt.push_back({{v1, v2}, -reqmat[u][v] / 2});
    } else {
      ct = 0;
      for (i = 0; i < adjl[u].size(); i++) {
        if (ct == 0 && adjl[u][i] != v) {
          x1 = find(adjl[u][i], u);
          ct++;
        } else if (ct == 1 && adjl[u][i] != v) {
          x2 = find(adjl[u][i], u);
          ct++;
        }
        if (ct == 2) break;
      }
      ct = 0;
      for (i = 0; i < adjl[v].size(); i++) {
        if (ct == 0 && adjl[v][i] != u) {
          y1 = find(adjl[v][i], v);
          ct++;
        } else if (ct == 1 && adjl[v][i] != u) {
          y2 = find(adjl[v][i], v);
          ct++;
        }
        if (ct == 2) break;
      }
      rslt.push_back({{x1, y1}, reqmat[u][v] / 2});
      rslt.push_back({{x2, y2}, reqmat[u][v] / 2});
      rslt.push_back({{x1, x2}, -reqmat[u][v] / 2});
      rslt.push_back({{y1, y2}, -reqmat[u][v] / 2});
    }
  }
  cout << "YES\n";
  cout << rslt.size() << "\n";
  for (auto x : rslt) {
    cout << x.first.first + 1 << " " << x.first.second + 1 << " " << x.second
         << "\n";
  }
  return 0;
}
