#include using namespace std; typedef long long ll; typedef pair pii; #define fi first #define se second #define mp make_pair #define fastIO ios::sync_with_stdio(false);cin.tie(0);cout.tie(0); mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count()); bool ans = false; const int N = (int)2e5 + 10; vector T[N]; int sub[N]; void dfs(int u, int pa){ sub[u]=1; for(auto x : T[u]){ if(x != pa){ dfs(x,u); sub[u] += sub[x]; } } } bool valid(int nd, int pa){ if(nd == -1) return false; bool y = true; vector S; sub[nd] = 1; for(auto x : T[nd]){ if(x != pa){ y &= valid(x, nd); sub[nd] += sub[x]; S.push_back(sub[x]); } } if(!y) return false; sort(S.begin(), S.end()); int r = 1; for(auto x : S){ if(x > r) return false; r += x; } return true; } int main(){ fastIO; int n; cin >> n; int u, v; for(int i = 1; i < n; i ++ ){ cin >> u >> v; T[u].push_back(v); T[v].push_back(u); } dfs(1,1); int f = 1, p = -1; bool ok = true; while(ok){ ok=false; for(auto x : T[f]){ if(x == p) continue; if(sub[x] * 2 > sub[1]){ p = f; f = x; ok=true; break; } } } int ff = -1; for(auto x : T[f]){ if(x == p) continue; if(sub[x] * 2 == sub[1]){ ff = x; } } if(valid(f,-1) || valid(ff, -1)){ cout << "YES\n"; } else{ cout << "NO\n"; } return 0; }