이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#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... |