#include <bits/stdc++.h>
using namespace std;
const int MAXN = 1e3 + 5;
struct node {
  int t, v;
};
struct edge {
  int x, y, v;
  edge(int _x, int _y, int _v) { x = _x, y = _y, v = _v; }
};
int n;
int fa[MAXN];
vector<node> g[MAXN];
vector<int> LEV, lev[MAXN];
bool mark[MAXN];
int Lpos[MAXN], Rpos[MAXN], tot;
void dfs(int x, int f) {
  Lpos[x] = ++tot;
  fa[x] = f;
  bool son = false;
  for (int i = 0, iend = g[x].size(); i < iend; ++i) {
    int t = g[x][i].t, v = g[x][i].v;
    if (t == f) continue;
    dfs(t, x);
    son = true;
  }
  if (!son) LEV.push_back(x), mark[x] = true;
  Rpos[x] = tot;
}
bool inTree(int x, int y) {
  if (Lpos[x] >= Lpos[y] && Lpos[x] <= Rpos[y])
    return true;
  else
    return false;
}
int find(int x, int fa) {
  if (mark[x]) return x;
  for (int i = 0, iend = g[x].size(); i < iend; ++i) {
    int t = g[x][i].t;
    if (t == fa) continue;
    return find(t, x);
  }
}
pair<int, int> find2(int x, int fa) {
  int a = -1, b = -1;
  for (int i = 0, iend = g[x].size(); i < iend; ++i) {
    int t = g[x][i].t;
    if (t == fa) continue;
    if (a == -1)
      a = find(t, x);
    else if (b == -1)
      b = find(t, x);
  }
  return make_pair(a, b);
}
vector<edge> res;
void getres(int x) {
  for (int i = 0, iend = g[x].size(); i < iend; ++i) {
    int t = g[x][i].t, v = g[x][i].v;
    if (t == fa[x]) continue;
    if (mark[t]) {
      int a = -1, b = -1;
      pair<int, int> p2 = find2(x, t);
      a = p2.first, b = p2.second;
      res.push_back(edge(a, t, v / 2));
      res.push_back(edge(b, t, v / 2));
      res.push_back(edge(a, b, -v / 2));
    } else {
      int a = -1, b = -1, c, d;
      pair<int, int> p1 = find2(x, t), p2 = find2(t, x);
      a = p1.first, b = p1.second;
      c = p2.first, d = p2.second;
      res.push_back(edge(a, c, v / 2));
      res.push_back(edge(b, d, v / 2));
      res.push_back(edge(a, b, -v / 2));
      res.push_back(edge(c, d, -v / 2));
    }
    getres(t);
  }
}
int main() {
  cin >> n;
  for (int i = 1, iend = n - 1; i <= iend; ++i) {
    int x, y, v;
    scanf("%d %d %d", &x, &y, &v);
    g[x].push_back((node){y, v});
    g[y].push_back((node){x, v});
  }
  bool chk = true;
  for (int i = 1, iend = n; i <= iend; ++i)
    if (g[i].size() == 2) chk = false;
  if (!chk) {
    puts("NO");
    return 0;
  }
  puts("YES");
  if (n == 2) {
    puts("1");
    printf("1 2 %d", g[1][0].v);
    return 0;
  }
  int rt;
  for (int i = 1, iend = n; i <= iend; ++i) {
    if (g[i].size() > 1) {
      rt = i;
      dfs(i, 0);
      break;
    }
  }
  getres(rt);
  cout << res.size() << endl;
  for (int i = 0, iend = res.size(); i < iend; ++i)
    printf("%d %d %d\n", res[i].x, res[i].y, res[i].v);
  return 0;
}
