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>
using namespace std;
//6 42
vector<vector<int> > g;
int check(int x, int cur=0, int par = -1){
int sum = 0;
for(int i: g[cur]){
if(i == par) continue;
sum += check(x, i, cur)+1;
}
sum -= x;
sum = max(sum, 0);
return sum;
}
int main(){
int n; cin>>n;
g.resize(n);
for(int i = 0; i < n-1; i++){
int u, v; cin>>u>>v; u--, v--;
g[u].push_back(v);
g[v].push_back(u);
}
int low = 1, high = n-1, mid;
while(low < high){
mid = (low + high)/2;
if(check(mid) == 0){
high = mid;
}else{
low = mid+1;
}
}
mid = (low + high)/2;
cout<<mid<<endl;
}
# | 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... |