#include <bits/stdc++.h>
using namespace std;
const int N = 1e5 + 10;
int e[N][2], w[N], deg[N];
pair<int, int> node[N][2];
int head[N], to[N << 1], nxt[N << 1], cnt;
inline void addedge(int x, int y) {
  to[++cnt] = y, nxt[cnt] = head[x], head[x] = cnt;
  to[++cnt] = x, nxt[cnt] = head[y], head[y] = cnt;
}
inline pair<int, int> dfs(int x, int fa) {
  if (deg[x] == 1) {
    return pair<int, int>(x, x);
  }
  pair<int, int> ans(0, 0), tmp;
  for (int i = head[x]; i; i = nxt[i]) {
    int y = to[i];
    if (y == fa) continue;
    tmp = dfs(y, x);
    if (ans.first == 0)
      ans = tmp;
    else
      ans.second = tmp.first;
  }
  return ans;
}
int main() {
  int n;
  scanf("%d", &n);
  for (int i = 1; i < n; i++) {
    scanf("%d%d%d", &e[i][0], &e[i][1], &w[i]);
    addedge(e[i][0], e[i][1]);
    deg[e[i][0]]++;
    deg[e[i][1]]++;
  }
  for (int i = 1; i <= n; i++)
    if (deg[i] == 2) {
      puts("NO");
      return 0;
    }
  puts("YES");
  dfs(1, 0);
  int cnt = 0;
  for (int i = 1; i < n; i++) {
    cnt += 4;
    node[i][0] = dfs(e[i][0], e[i][1]);
    node[i][1] = dfs(e[i][1], e[i][0]);
    if (deg[e[i][0]] == 1) cnt--;
    if (deg[e[i][1]] == 1) cnt--;
  }
  printf("%d\n", cnt);
  for (int i = 1; i < n; i++) {
    printf("%d %d %d\n", node[i][0].first, node[i][1].first, w[i] / 2);
    printf("%d %d %d\n", node[i][0].second, node[i][1].second, w[i] / 2);
    if (deg[e[i][0]] > 1)
      printf("%d %d %d\n", node[i][0].first, node[i][0].second, -w[i] / 2);
    if (deg[e[i][1]] > 1)
      printf("%d %d %d\n", node[i][1].first, node[i][1].second, -w[i] / 2);
  }
  return 0;
}
