Submission #1014144

#TimeUsernameProblemLanguageResultExecution timeMemory
1014144AlmontherTriumphal arch (POI13_luk)C++98
100 / 100
269 ms65144 KiB
#include <bits/stdc++.h> #define suiii ios::sync_with_stdio(0);cin.tie(0);cout.tie(0); #define ll long long #define co cout<< //#pragma GCC optimize("O3,Ofast,unroll-loops") //#pragma GCC target("avx2,sse3,sse4,avx") using namespace std; //stuff ll n; vector<ll>v[1000001]; ll dp[1000001]; ll dep[1000001]; vector<pair<ll,ll>>v1; ll par[1000001]; void make_dp(ll x){ for(auto i:v1){ ll sum=v[i.second].size()-1; if(i.second==1) sum++; for(auto j:v[i.second]){ if(j==par[j]) continue; sum+=dp[j]; } dp[i.second]=max(0ll,sum-x); } } void dfs(ll x,ll last){ par[x]=last; v1.push_back({dep[last]+1,x}); dep[x]=dep[last]+1; for(auto i:v[x]){ if(i==last) continue; dfs(i,x); } } void solve(){ cin>>n; for(int i=0;i<n-1;i++){ ll a,b; cin>>a>>b; v[a].push_back(b); v[b].push_back(a); } dfs(1,-1); sort(v1.begin(),v1.end()); reverse(v1.begin(),v1.end()); ll l,r,ans=0; l=0,r=1e6; while(l<=r){ memset(dp,0,sizeof(dp)); ll mid=(l+r)/2; make_dp(mid); if(dp[1]==0){ r=mid-1; ans=mid; } else l=mid+1; } co ans; } int main() { suiii int tt=1; // cin>>tt; while(tt--){ solve(); } return 0; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...