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;
#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... |