#include using namespace std; const int N = 200000 + 7; int n; int sub[N]; int par[N]; vector g[N]; void build(int a, int p = -1) { assert(sub[a] == 0); //cout << " vert : " << a << "\n"; sub[a] = 1; par[a] = p; for (auto &b : g[a]) { if (b == p) continue; //cout << "muchie " << a << " " << b << "\n"; build(b, a); sub[a] += sub[b]; } } bool test(int a, int p = -1) { sub[a] = 1; vector vals; bool good = 1; for (auto &b : g[a]) { if (b == p) continue; good &= test(b, a); sub[a] += sub[b]; vals.push_back(sub[b]); } sort(vals.begin(), vals.end()); int current = 1; for (auto &x : vals) { // cout << x << " "; good &= (x <= current); current += x; } // cout << " and "; // cout << a << " : " << good << "\n"; return good; } bool solvetc() { cin >> n; for (int i = 1; i <= n; i++) g[i].clear(), sub[i] = 0; for (int i = 1; i < n; i++) { int a, b; cin >> a >> b; //cout << "edge " << a << " " << b << "\n"; g[a].push_back(b); g[b].push_back(a); } build(1); // cout << " : " << sub[1] << "\n"; // exit(0); assert(sub[1] == n); vector pot; for (int a = 1; a <= n; a++) { vector vals; vals.push_back(sub[1] - sub[a]); for (auto &b : g[a]) { if (b == par[a]) continue; vals.push_back(sub[b]); } sort(vals.begin(), vals.end()); bool good = 1; int current = 1; for (auto &x : vals) { good &= (x <= current); current += x; } if (good) pot.push_back(a); } for (auto &a : pot) { // cout << " a = " << a << "\n"; if (test(a)) { assert(sub[a] == n); return 1; } } return 0; cout << " --> "; for (auto &x : pot) cout << x << " "; cout << "\n"; return 1; } int main() { ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); int t = 1; // cin >> t; while (t--) { bool ok = solvetc(); if (ok) cout << "YES\n"; else cout << "NO\n"; } return 0; }