#include <bits/stdc++.h>
using namespace std;
int n;
struct node {
  int x, y, z;
};
vector<node> ans, E;
vector<int> ve[1005];
int dfs(int x, int ba, int z) {
  if (x == z) return -1;
  if (ve[x].size() == 1) return x;
  int o = n;
  for (auto y : ve[x]) {
    if (y == ba) continue;
    o = min(o, dfs(y, x, z));
  }
  return o;
}
void ADD(int x, int y, int z) {
  if (ve[x].size() == 1 && ve[y].size() == 1) {
    ans.push_back((node){x, y, z});
    return;
  }
  if (ve[x].size() < ve[y].size()) swap(x, y);
  int y1 = -1;
  int y2 = -1;
  for (auto p : ve[x]) {
    if (p == y) continue;
    int yy = dfs(p, x, y);
    if (yy == -1) continue;
    if (y1 == -1)
      y1 = yy;
    else {
      y2 = yy;
      break;
    }
  }
  if (ve[y].size() == 1) {
    ans.push_back((node){y1, y, z / 2});
    ans.push_back((node){y2, y, z / 2});
    ans.push_back((node){y1, y2, -z / 2});
  } else {
    ADD(y1, y, z);
    ADD(y1, x, -z);
  }
}
int main() {
  scanf("%d", &n);
  for (int i = 1; i < n; i++) {
    int x, y, z;
    scanf("%d%d%d", &x, &y, &z);
    ve[x].push_back(y);
    ve[y].push_back(x);
    E.push_back((node){x, y, z});
  }
  for (int i = 1; i <= n; i++) {
    if (ve[i].size() == 2) {
      puts("NO");
      exit(0);
    }
  }
  for (auto p : E) {
    ADD(p.x, p.y, p.z);
  }
  puts("YES");
  printf("%d\n", ans.size());
  for (auto p : ans) {
    printf("%d %d %d\n", p.x, p.y, p.z);
  }
}
