# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
856607 | 2023-10-04T03:45:58 Z | vjudge1 | Dynamite (POI11_dyn) | C++17 | 433 ms | 21964 KB |
#include <iostream> #include <vector> #include <algorithm> #include <deque> #include <set> #include <utility> #include <numeric> #include <array> #include <cstring> using namespace std; #define ALL(x) x.begin(), x.end() using ll = long long; #define N 300050 int n, m, d[N], f[N], h[N]; vector<int> g[N], dfn; vector<int> rev_dfn(int src) { vector<int> st = {src}, V(n); for (int i = 0; i < n; ++i) { auto u = st.back(); st.pop_back(); V[i] = u; for (auto v : g[u]) { g[v].erase(find(ALL(g[v]), u)); st.push_back(v); } } reverse(ALL(V)); return V; } int ok(int y) { memset(f, -1, sizeof f); memset(h, 63, sizeof h); int k = m; for (auto u : dfn) { for (auto v : g[u]) { if (f[v] != -1) f[u] = max(f[u], f[v] + 1); h[u] = min(h[u], h[v] + 1); } if (f[u] == -1 && d[u]) f[u] = 0; if (f[u] == y) { if (!k--) return 0; f[u] = -1; h[u] = 0; } else if (f[u] + h[u] <= y) f[u] = -1; } return k || f[0] == -1; } int main() { cin.tie(nullptr)->sync_with_stdio(false); scanf("%d%d", &n, &m); for (int i = 1; i <= n; ++i) scanf("%d", d+i); if (accumulate(d, d+n+1, 0) <= m) return 0 * puts("0"); for (int u, v, i = 1; i < n; ++i) scanf("%d%d", &u, &v), g[u].push_back(v), g[v].push_back(u); dfn = rev_dfn(1); int l = 1, r = 2*n-1, z = -1; while (l < r) { int y = (l+r)/2; ok(y) ? r = y : l = y + 1; } printf("%d", l); return 0; }
Compilation message
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 2 ms | 10844 KB | Output is correct |
2 | Correct | 2 ms | 10844 KB | Output is correct |
3 | Correct | 2 ms | 11096 KB | Output is correct |
4 | Incorrect | 2 ms | 10844 KB | Output isn't correct |
5 | Halted | 0 ms | 0 KB | - |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 2 ms | 10844 KB | Output is correct |
2 | Correct | 2 ms | 10844 KB | Output is correct |
3 | Correct | 3 ms | 10844 KB | Output is correct |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Incorrect | 2 ms | 10844 KB | Output isn't correct |
2 | Halted | 0 ms | 0 KB | - |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 3 ms | 10840 KB | Output is correct |
2 | Correct | 3 ms | 11096 KB | Output is correct |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 8 ms | 11096 KB | Output is correct |
2 | Correct | 13 ms | 11612 KB | Output is correct |
3 | Correct | 15 ms | 11868 KB | Output is correct |
4 | Correct | 15 ms | 11736 KB | Output is correct |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 27 ms | 12892 KB | Output is correct |
2 | Correct | 39 ms | 13392 KB | Output is correct |
3 | Correct | 42 ms | 13648 KB | Output is correct |
4 | Incorrect | 48 ms | 13660 KB | Output isn't correct |
5 | Halted | 0 ms | 0 KB | - |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 61 ms | 14640 KB | Output is correct |
2 | Correct | 52 ms | 14684 KB | Output is correct |
3 | Correct | 64 ms | 14188 KB | Output is correct |
4 | Incorrect | 58 ms | 14936 KB | Output isn't correct |
5 | Halted | 0 ms | 0 KB | - |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 169 ms | 18004 KB | Output is correct |
2 | Correct | 206 ms | 19512 KB | Output is correct |
3 | Incorrect | 236 ms | 19816 KB | Output isn't correct |
4 | Halted | 0 ms | 0 KB | - |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Incorrect | 433 ms | 21964 KB | Output isn't correct |
2 | Halted | 0 ms | 0 KB | - |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Incorrect | 316 ms | 21844 KB | Output isn't correct |
2 | Halted | 0 ms | 0 KB | - |