#include <bits/stdc++.h>
using namespace std;
const int N = 1e3 + 1e2;
const int M = 3e3 + 1e2;
const int inf = 1e9;
const long long INF = 1e18 + 1e2;
template <typename T>
void vout(T x) {
  cout << x << endl;
  exit(0);
}
int n, root, pr[N], a[N], b[N], c[N], lst[N], tin[N], tout[N], t;
vector<int> g[N];
struct low {
  int x, y, z;
};
vector<low> ans;
void dfs(int v, int p) {
  pr[v] = p;
  tin[v] = t++;
  for (auto i : g[v])
    if (i != p) dfs(i, v);
  lst[v] = ((int)g[v].size() == 1);
  tout[v] = t++;
}
int getlst(int v, int p) {
  if (lst[v]) return v;
  for (auto i : g[v])
    if (i != p) return getlst(i, v);
}
bool upper(int a, int b) { return tin[a] <= tin[b] && tout[b] <= tout[a]; }
void sett(int x, int y, int z) {
  if (upper(y, x)) swap(x, y);
  int col = 0, pos, vx, vy, vz;
  for (auto i : g[x]) {
    if (i != y) {
      pos = i;
      if (!col)
        vx = getlst(i, x);
      else
        vy = getlst(i, x);
      col++;
    }
    if (col == 2) break;
  }
  if (lst[y]) {
    ans.push_back({vx, y, z / 2});
    ans.push_back({vy, y, z / 2});
    ans.push_back({vx, vy, -z / 2});
    return;
  }
  for (auto i : g[y]) {
    if (i != x) {
      vz = getlst(i, y);
      break;
    }
  }
  ans.push_back({vx, vz, z / 2});
  ans.push_back({vy, vz, z / 2});
  ans.push_back({vx, vy, -z / 2});
  while (vz != y) {
    sett(vz, pr[vz], -z);
    vz = pr[vz];
  }
}
int main() {
  cin >> n;
  for (int i = 1; i <= n - 1; ++i) {
    cin >> a[i] >> b[i] >> c[i];
    g[a[i]].push_back(b[i]), g[b[i]].push_back(a[i]);
  }
  if (n == 2) {
    cout << "YES" << endl;
    cout << 1 << endl;
    cout << 1 << " " << 2 << " " << c[1] << endl;
    exit(0);
  }
  for (int i = 1; i <= n; ++i)
    if ((int)g[i].size() == 2) vout("NO");
  for (int i = 1; i <= n; ++i)
    if ((int)g[i].size() > 1) {
      root = i;
      break;
    }
  dfs(root, root);
  for (int i = 1; i <= n - 1; ++i) sett(a[i], b[i], c[i]);
  cout << "YES" << endl;
  cout << (int)ans.size() << endl;
  for (auto i : ans) cout << i.x << " " << i.y << " " << i.z << endl;
  return 0;
}
