# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
82712 | farukkastamonuda | Triumphal arch (POI13_luk) | C++14 | 1090 ms | 47068 KiB |
This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <bits/stdc++.h>
#define fi first
#define se second
#define lo long long
#define inf 1000000009
#define md 1000000007
#define li 300005
#define mp make_pair
#define pb push_back
using namespace std;
int n,a,b,sz[li],sz2[li];
vector<int> v[li];
lo int dfs(int node,int ata,int val){
lo int D=0;
for(int i=0;i<(int)v[node].size();i++){
int go=v[node][i];
if(go==ata) continue;
D+=dfs(go,node,val)+1;
}
return max(0LL,D-val);
}
bool ok(int val){
return (dfs(1,-1,val)==0);
}
int main(){
scanf("%d",&n);
for(int i=1;i<n;i++){
scanf("%d %d",&a,&b);
v[a].pb(b);
v[b].pb(a);
}
int bas=0,son=n-1;
while(bas<=son){
int mid=(bas+son)/2;
if(ok(mid)) son=mid-1;
else bas=mid+1;
}
printf("%d\n",bas);
return 0;
}
Compilation message (stderr)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |