# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
29304 | 2017-07-19T01:59:32 Z | kdh9949 | Dynamite (POI11_dyn) | C++14 | 1606 ms | 30400 KB |
#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
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 0 ms | 10224 KB | Output is correct |
2 | Correct | 3 ms | 10224 KB | Output is correct |
3 | Correct | 0 ms | 10224 KB | Output is correct |
4 | Correct | 0 ms | 10224 KB | Output is correct |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 0 ms | 10224 KB | Output is correct |
2 | Correct | 0 ms | 10224 KB | Output is correct |
3 | Correct | 0 ms | 10224 KB | Output is correct |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 0 ms | 10224 KB | Output is correct |
2 | Correct | 0 ms | 10224 KB | Output is correct |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 6 ms | 10224 KB | Output is correct |
2 | Correct | 3 ms | 10224 KB | Output is correct |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 9 ms | 10620 KB | Output is correct |
2 | Correct | 36 ms | 11016 KB | Output is correct |
3 | Correct | 33 ms | 11148 KB | Output is correct |
4 | Correct | 49 ms | 12756 KB | Output is correct |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 46 ms | 12072 KB | Output is correct |
2 | Correct | 93 ms | 12600 KB | Output is correct |
3 | Correct | 176 ms | 12732 KB | Output is correct |
4 | Correct | 156 ms | 15624 KB | Output is correct |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 196 ms | 13656 KB | Output is correct |
2 | Correct | 219 ms | 13660 KB | Output is correct |
3 | Correct | 466 ms | 13392 KB | Output is correct |
4 | Correct | 493 ms | 18304 KB | Output is correct |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 663 ms | 16692 KB | Output is correct |
2 | Correct | 749 ms | 18156 KB | Output is correct |
3 | Correct | 1029 ms | 25328 KB | Output is correct |
4 | Correct | 1066 ms | 25324 KB | Output is correct |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 1606 ms | 22116 KB | Output is correct |
2 | Correct | 639 ms | 20536 KB | Output is correct |
3 | Correct | 976 ms | 24972 KB | Output is correct |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 1306 ms | 28392 KB | Output is correct |
2 | Correct | 1046 ms | 20540 KB | Output is correct |
3 | Correct | 929 ms | 30400 KB | Output is correct |
4 | Correct | 516 ms | 21680 KB | Output is correct |