제출 #654062

#제출 시각아이디문제언어결과실행 시간메모리
654062MasterTaster새로운 문제 (POI13_luk)C++14
100 / 100
991 ms27800 KiB
#include <bits/stdc++.h> #define pb push_back #define ll long long #define pii pair<int, int> #define xx first #define yy second #define MAXN 300010 using namespace std; int k, n, dp[MAXN]; bool bio[MAXN]; vector<int> g[MAXN]; void dfs(int u) { bio[u]=true; for (auto v:g[u]) { if (!bio[v]) { dfs(v); dp[u]+=(dp[v]+1); } } dp[u]-=k; dp[u]=max(dp[u], 0); } bool check(int x) { k=x; for (int i=1; i<=n; i++) { bio[i]=false; dp[i]=0; } dfs(1); if (dp[1]<=0) return true; else return false; } void bs() { int l=1, r=n-1, ress=n-1; while (l<=r) { int mid=l+(r-l)/2; if (check(mid)) { ress=mid; r=mid-1; } else l=mid+1; } cout<<ress; } int main() { cin>>n; for (int i=1; i<n; i++) { int u, v; cin>>u>>v; g[u].pb(v); g[v].pb(u); } bs(); }
#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...