#include using namespace std; int main() { ios::sync_with_stdio(false); cin.tie(0); int n; cin >> n; vector> graph(n + 1); for(int i = 1; i < n; i++) { int u, v; cin >> u >> v; graph[u].push_back(v); graph[v].push_back(u); } vector weight(n + 1, 0); vector father(n + 1, 0); function dfs = [&](int nod, int tata) { weight[nod] = 1; father[nod] = tata; for(auto it:graph[nod]) { if(it == tata) { continue; } dfs(it, nod); weight[nod] += weight[it]; } }; dfs(1, 0); int curr = 1; while(true) { int idx = -1; for(auto it:graph[curr]) { if(it == father[curr]) { continue; } if(idx == -1 || weight[idx] < weight[it]) { idx = it; } } if(idx == -1 || weight[idx] * 2 <= n) { break; } curr = idx; } vector local_weights; function check = [&](int nod, int tata) { weight[nod] = 1; father[nod] = tata; for(auto it:graph[nod]) { if(it == tata) { continue; } if(!check(it, nod)) { return false; } weight[nod] += weight[it]; } local_weights.clear(); for(auto it: graph[nod]) { if(it == tata) { continue; } local_weights.push_back(weight[it]); } sort(local_weights.begin(), local_weights.end()); int curr_weight = 1; for(auto it: local_weights) { if(curr_weight < it) { return false; } curr_weight += it; } return true; }; cout << (check(curr, 0) ? "YES":"NO"); return 0; }