#include <bits/stdc++.h>
using namespace std;
map<int, vector<int>> tree;
int output[100000][3];
int lines = 0;
int getleaf(int root, int block) {
  if (tree[root].size() == 1) return root;
  int first = tree[root][0];
  int second = tree[root][1];
  if (first != block) {
    return getleaf(first, root);
  } else {
    return getleaf(second, root);
  }
}
void edge_add(int val, int a, int b) {
  int half_val = val / 2, root, sroot;
  if (val == 0) return;
  if (tree[a].size() >= 3) {
    root = a;
    sroot = b;
  } else {
    root = b;
    sroot = a;
  }
  int leaves[3];
  leaves[0] = getleaf(sroot, root);
  int counter = 1;
  for (vector<int>::iterator it = tree[root].begin(); it != tree[a].end();
       it++) {
    if (counter == 3) break;
    if (*it != sroot) {
      leaves[counter] = getleaf(*it, root);
      counter++;
    }
  }
  output[lines][0] = leaves[0];
  output[lines][1] = leaves[1];
  output[lines][2] = half_val;
  lines++;
  output[lines][0] = leaves[0];
  output[lines][1] = leaves[2];
  output[lines][2] = half_val;
  lines++;
  output[lines][0] = leaves[2];
  output[lines][1] = leaves[1];
  output[lines][2] = -half_val;
  lines++;
  int leaf;
  if (tree[sroot].size() != 1) {
    for (vector<int>::iterator it = tree[sroot].begin();
         it != tree[sroot].end(); it++) {
      if ((*it != root) && (getleaf(*it, sroot) != leaves[0])) {
        leaf = getleaf(*it, sroot);
        break;
      }
    }
    output[lines][0] = leaves[0];
    output[lines][1] = leaves[1];
    output[lines][2] = -half_val;
    lines++;
    output[lines][0] = leaves[0];
    output[lines][1] = leaf;
    output[lines][2] = -half_val;
    lines++;
    output[lines][0] = leaves[1];
    output[lines][1] = leaf;
    output[lines][2] = half_val;
    lines++;
  }
}
int main() {
  int n;
  int arr[10000][3];
  cin >> n;
  for (int i = 0; i < n - 1; i++) {
    int a, b, c;
    cin >> a >> b >> c;
    tree[a].push_back(b);
    tree[b].push_back(a);
    arr[i][0] = a;
    arr[i][1] = b;
    arr[i][2] = c;
  }
  for (map<int, vector<int>>::iterator it = tree.begin(); it != tree.end();
       it++) {
    if (it->second.size() == 2) {
      cout << "NO\n";
      return 0;
    }
  }
  cout << "YES\n";
  if (n != 2) {
    for (int i = 0; i < n - 1; i++) {
      edge_add(arr[i][2], arr[i][1], arr[i][0]);
    }
    cout << lines << "\n";
    for (int i = 0; i < lines; i++) {
      cout << output[i][0] << " " << output[i][1] << " " << output[i][2]
           << "\n";
    }
  } else {
    cout << "1\n";
    cout << "1 2 " << arr[0][2] << "\n";
  }
  return 0;
}
