# | Submission time | Handle | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
856603 | 2023-10-04T03:36:15 Z | vjudge1 | Dynamite (POI11_dyn) | C++17 | 125 ms | 48040 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 8 * 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(0); int l = 1, r = 2*n, z = -1; while (l <= r) { int y = (l+r)/2; ok(y) ? z = y, r = y - 1 : l = y + 1; } printf("%d", z); return 0; }
Compilation message
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Runtime error | 2 ms | 10844 KB | Execution failed because the return code was nonzero |
2 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Runtime error | 9 ms | 21748 KB | Execution killed with signal 6 |
2 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Runtime error | 9 ms | 21596 KB | Execution killed with signal 6 |
2 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Runtime error | 9 ms | 21848 KB | Execution killed with signal 6 |
2 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Runtime error | 12 ms | 22620 KB | Execution killed with signal 6 |
2 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Runtime error | 25 ms | 26460 KB | Execution killed with signal 6 |
2 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Runtime error | 47 ms | 30636 KB | Execution killed with signal 11 |
2 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Runtime error | 72 ms | 39296 KB | Execution killed with signal 11 |
2 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Runtime error | 123 ms | 48040 KB | Execution killed with signal 6 |
2 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Runtime error | 125 ms | 47956 KB | Execution killed with signal 6 |
2 | Halted | 0 ms | 0 KB | - |