#include <bits/stdc++.h>
using namespace std;
const double PI = atan(1.0) * 4;
const int64_t INF = 100000000000000003;
const int32_t LOG = 21;
const int BIG = pow(2, 20);
const int N = 100005;
vector<pair<pair<int, int>, int>> edges;
vector<pair<int, int>> v[1005];
vector<pair<pair<int, int>, int>> ans;
int deg[1005];
bool leaf[1005];
void check_incase(int n) {
  for (int i = 1; i < n + 1; i++) {
    if (deg[i] == 2) {
      cout << "NO" << '\n';
      exit(0);
    } else if (deg[i] == 1)
      leaf[i] = true;
  }
}
void root_the_tree(int i, int prev) {
  for (int j = 0; j < v[i].size(); j++) {
    int ver = v[i][j].first;
    int node = v[i][j].second;
    if (ver != prev && node == -1 && leaf[ver]) {
      v[i][j].second = ver;
    } else if (ver != prev && node == -1) {
      root_the_tree(ver, i);
      for (int k = 0; k < v[ver].size(); k++) {
        if (v[ver][k].first != i) {
          v[i][j].second = v[ver][k].second;
          break;
        }
      }
    }
  }
}
void print_util(int x, int main_leaf, int helper1, int helper2, int val) {
  ans.push_back({{main_leaf, helper1}, val / 2});
  ans.push_back({{main_leaf, helper2}, val / 2});
  ans.push_back({{helper1, helper2}, -val / 2});
}
void print(int x, int y, int val) {
  if (leaf[x]) swap(x, y);
  if (leaf[x] && leaf[y]) {
    ans.push_back({{x, y}, val});
  } else if (leaf[y]) {
    vector<int> temp;
    for (int j = 0; j < v[x].size(); j++) {
      if (v[x][j].first != y) {
        temp.push_back(v[x][j].second);
      }
      if (temp.size() == 2) break;
    }
    print_util(x, y, temp[0], temp[1], val);
  } else {
    vector<int> temp;
    int main_leaf = -1;
    for (int j = 0; j < v[x].size(); j++) {
      if (v[x][j].first == y) {
        main_leaf = v[x][j].second;
      } else if (temp.size() < 2) {
        temp.push_back(v[x][j].second);
      }
    }
    print_util(x, main_leaf, temp[0], temp[1], val);
    temp.clear();
    for (int j = 0; j < v[y].size(); j++) {
      if (v[y][j].second != main_leaf && temp.size() < 2)
        temp.push_back(v[y][j].second);
    }
    print_util(y, main_leaf, temp[0], temp[1], -val);
  }
}
int32_t main() {
  ios_base::sync_with_stdio(false), cin.tie(NULL), cout.tie(NULL);
  int n;
  cin >> n;
  for (int i = 0; i < n - 1; i++) {
    int u1, v1, val;
    cin >> u1 >> v1 >> val;
    edges.push_back({{u1, v1}, val});
    v[u1].push_back({v1, -1});
    v[v1].push_back({u1, -1});
    deg[u1]++;
    deg[v1]++;
  }
  check_incase(n);
  cout << "YES" << '\n';
  for (int i = 1; i < n + 1; i++) {
    if (!leaf[i]) root_the_tree(i, -1);
  }
  for (int i = 0; i < edges.size(); i++) {
    print(edges[i].first.first, edges[i].first.second, edges[i].second);
  }
  cout << ans.size() << '\n';
  for (int i = 0; i < ans.size(); i++)
    cout << ans[i].first.first << " " << ans[i].first.second << " "
         << ans[i].second << '\n';
  return 0;
}
