#include #define all(a) a.begin(),a.end() #define len(a) (int)(a.size()) #define fir first #define sec second #define fi first #define se second #define mp make_pair #define pb push_back using namespace std; typedef pair pii; typedef long long ll; typedef long double ld; template bool umin(T &a, T b) { if (b < a) { a = b; return 1; } return 0; } template bool umax(T &a, T b) { if (a < b) { a = b; return 1; } return 0; } #ifdef KIVI #define DEBUG for (int _____DEBUG=1;_____DEBUG;_____DEBUG=0) #define LOG(...) prnt(#__VA_ARGS__" ::",__VA_ARGS__)< auto &prnt(Ts ...ts) { return ((cerr << ts << " "), ...); } #else #define DEBUG while (false) #define LOG(...) #endif const int max_n = 2e5+10, inf = 1000111222; int n; vector reb[max_n]; vector cands; int sz[max_n]; bool dp[max_n]; template void dfs(int now,int pred) { sz[now]=1; for (auto wh:reb[now]){ if (wh!=pred){ dfs(wh,now); sz[now]+=sz[wh]; } } if (build_cands___or__do_dp){ vector guys; for (auto wh:reb[now]){ if (wh!=pred){ guys.pb(sz[wh]); } } if (pred!=-1){ guys.pb(n-sz[now]); } if (guys.empty() || 2*(*max_element(all(guys)))<=n){ cands.pb(now); } } else{ dp[now]=1; vector s; for (auto wh:reb[now]){ if (wh!=pred){ dp[now]&=dp[wh]; s.pb(sz[wh]); } } sort(all(s)); int pref=1; for (auto i:s){ dp[now]&=(i<=pref); pref+=i; } LOG(now+1,dp[now]); } } int main() { // freopen("input.txt","r",stdin); // freopen("output.txt","w",stdout); ios_base::sync_with_stdio(0); cin.tie(0); cin>>n; for (int i=1;i>u>>v; u--; v--; reb[u].pb(v); reb[v].pb(u); } dfs(0,-1); for (auto c:cands){ dfs(c,-1); LOG("cands",c+1,dp[c]); if (dp[c]){ cout<<"YES"<<"\n"; return 0; } } cout<<"NO"<<"\n"; exit(0); }