# | Submission time | Handle | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
313815 | 2020-10-17T06:21:30 Z | BeanZ | Dynamite (POI11_dyn) | C++14 | 3000 ms | 42848 KB |
// I_Love_LPL #include <bits/stdc++.h> using namespace std; #define ll long long #define endl '\n' const int N = 3e5 + 5; ll cnt = 0, mid; ll dp[N], hp[N], a[N], farcry[N]; vector<ll> node[N]; void dfs(ll u, ll p){ hp[u] = 0; for (auto j : node[u]){ if (j == p) continue; dfs(j, u); farcry[u] = min(farcry[u], farcry[j] + 1); } if (a[u] == 1 && farcry[u] > mid) hp[u] = 1, dp[u] = 0; for (auto j : node[u]){ if (j == p) continue; if (hp[j]){ if ((farcry[u] + dp[j] + 1) <= mid) continue; else dp[u] = max(dp[u], dp[j] + 1), hp[u] = 1; } } if (dp[u] == mid){ cnt++; dp[u] = -1e18; farcry[u] = 0; hp[u] = 0; } if (u == 1){ if (dp[u] == 0 && a[u] && farcry[u] > mid) cnt++; else if (dp[u] >= 1) cnt++; } } int main(){ ios_base::sync_with_stdio(false); cin.tie(0); if (fopen("A.inp", "r")){ freopen("test.inp", "r", stdin); freopen("test.out", "w", stdout); } ll n, m; cin >> n >> m; ll res = 0; for (int i = 1; i <= n; i++){ cin >> a[i]; if (a[i] == 1) res++; } for (int i = 1; i < n; i++){ ll u, v; cin >> u >> v; node[u].push_back(v); node[v].push_back(u); } if (res <= m) return cout << 0, 0; ll l = 1, h = 1e9; while (l <= h){ mid = (l + h) >> 1; cnt = 0; memset(hp, 0, sizeof(hp)); for (int i = 1; i <= n; i++) farcry[i] = 1e18, dp[i] = -1e18; dfs(1, 1); if (cnt > m) l = mid + 1; else h = mid - 1; } cout << l; } /* */
Compilation message
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 5 ms | 7424 KB | Output is correct |
2 | Correct | 5 ms | 7424 KB | Output is correct |
3 | Correct | 9 ms | 9728 KB | Output is correct |
4 | Correct | 10 ms | 9728 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 10 ms | 9728 KB | Output is correct |
2 | Correct | 10 ms | 9728 KB | Output is correct |
3 | Correct | 10 ms | 9728 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 11 ms | 9856 KB | Output is correct |
2 | Correct | 11 ms | 9796 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 11 ms | 9856 KB | Output is correct |
2 | Correct | 10 ms | 9856 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 26 ms | 10496 KB | Output is correct |
2 | Correct | 69 ms | 11392 KB | Output is correct |
3 | Correct | 75 ms | 12152 KB | Output is correct |
4 | Correct | 102 ms | 13568 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 157 ms | 13816 KB | Output is correct |
2 | Correct | 358 ms | 14968 KB | Output is correct |
3 | Correct | 525 ms | 15224 KB | Output is correct |
4 | Correct | 539 ms | 18428 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 550 ms | 17452 KB | Output is correct |
2 | Correct | 606 ms | 17144 KB | Output is correct |
3 | Correct | 800 ms | 16768 KB | Output is correct |
4 | Correct | 930 ms | 22624 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 1484 ms | 25028 KB | Output is correct |
2 | Correct | 1736 ms | 26988 KB | Output is correct |
3 | Correct | 2654 ms | 36516 KB | Output is correct |
4 | Correct | 2729 ms | 36512 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Execution timed out | 3064 ms | 34120 KB | Time limit exceeded |
2 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Execution timed out | 3057 ms | 42848 KB | Time limit exceeded |
2 | Halted | 0 ms | 0 KB | - |