#include "bits/stdc++.h" using namespace std; using LL = long long; using ll = long long; #define all(x) begin(x),end(x) typedef array pii; int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); int n; cin >> n; vector> v(n); vector d(n, 1); priority_queue, greater> q; for(int i = 1; i < n; ++i){ int a, b; cin >> a >> b; v[a-1].insert(b-1); v[b-1].insert(a-1); } for(int i = 0; i < n; ++i) if(v[i].size() == 1) q.push({1, i}); // add leaves for (int j = 0; j < n - 1; ++j) { int i = q.top()[1]; q.pop(); int p = *v[i].begin(); if(d[p] < d[i]){ // cannot move leaf, is this a no? cout << "NO" << endl; exit(0); } v[p].erase(i); d[p] += d[i]; if(v[p].size() == 1) q.push({d[p], p}); } cout << "YES" << endl; } /* 7 5 1 3 2 4 6 3 6 7 1 1 3 1 2 1 1 3 5 1 1 4 0 1 1 6 0 1 2 5 2 2 2 0 2 3 4 2 0 7 3 NO */