이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
using namespace std;
#define LL long long
#define ULL unsigned long long
#define LD long double
const int N = 3e5 + 2137;
vector<int> V[N];
int spr(int v, int k, int oj) {
int n = V[v].size();
LL w = 0;
for(int i=0; i<n; i++) {
int u = V[v][i];
if(u!=oj) {
w+=spr(u, k, v)+1;
}
}
return max((LL)0, w-k);
}
int main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
int n;
cin>>n;
int a, b;
for(int i=1; i<n; i++) {
cin>>a>>b;
V[a].push_back(b);
V[b].push_back(a);
}
int poc = 0;
int kon = n;
while(poc<kon) {
int sr = (poc+kon) / 2;
if(!spr(1, sr, -1))
kon = sr;
else
poc = sr + 1;
}
cout<<poc;
}
# | 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... |