# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
29304 | kdh9949 | Untitled (POI11_dyn) | C++14 | 1606 ms | 30400 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>
using namespace std;
int n, m, d[300010], ans;
vector<int> e[300010];
int f(int x, int p, int c){
int t = 0, v = 0;
for(auto &i : e[x]){
if(i != p){
int u = f(i, x, c);
if(!u) continue;
if(u > 0) v = max(v, u);
else t = min(t, u);
}
}
if(abs(t) >= c){
ans++;
return c;
}
if(!v && !t) return -d[x];
if(v > abs(t)) return v - 1;
return t - 1;
}
int can(int k){
ans = 0;
if(f(1, 0, k) < 0) ans++;
return ans <= m;
}
int main(){
scanf("%d%d", &n, &m);
for(int i = 1; i <= n; i++) scanf("%d", d + i);
for(int i = 0, x, y; i < n - 1; i++){
scanf("%d%d", &x, &y);
e[x].push_back(y);
e[y].push_back(x);
}
if(count(d + 1, d + n + 1, 1) <= m){ puts("0"); return 0; }
int st = 1, en = n - 1;
while(st <= en){
int mi = (st + en) / 2;
if(can(mi)) en = mi - 1;
else st = mi + 1;
}
printf("%d\n", st);
}
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... |