# | Submission time | Handle | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
896671 | 2024-01-01T20:42:09 Z | borisAngelov | Biochips (IZhO12_biochips) | C++17 | 283 ms | 14424 KB |
#include <bits/stdc++.h> using namespace std; const int maxn = 200005; const int maxm = 505; const int inf = 1e9; int n, m; int a[maxn]; int root = -1; vector<int> tree[maxn]; vector<int> combine(vector<int>& a, vector<int>& b) { vector<int> c(min(m + 1, int(a.size() + b.size())), 0); for (int i = 0; i < a.size(); ++i) { for (int j = 0; j < min(int(b.size()), m - i + 1); ++j) { c[i + j] = max(c[i + j], a[i] + b[j]); } } return c; } vector<int> dfs(int node, int par) { vector<int> dp; dp.push_back(0); dp.push_back(0); for (int i = 0; i < tree[node].size(); ++i) { if (tree[node][i] != par) { vector<int> child = dfs(tree[node][i], node); dp = combine(dp, child); } } dp[1] = max(dp[1], a[1]); return dp; } void fastIO() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); } int main() { fastIO(); cin >> n >> m; for (int i = 1; i <= n; ++i) { int par; cin >> par >> a[i]; if (par == 0) { root = i; } else { tree[par].push_back(i); tree[i].push_back(par); } } vector<int> dp = dfs(root, -1); cout << dp[m] << endl; return 0; }
Compilation message
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Incorrect | 1 ms | 4956 KB | Output isn't correct |
2 | Incorrect | 2 ms | 4956 KB | Output isn't correct |
3 | Incorrect | 1 ms | 4972 KB | Output isn't correct |
4 | Incorrect | 7 ms | 5720 KB | Output isn't correct |
5 | Incorrect | 5 ms | 5468 KB | Output isn't correct |
6 | Incorrect | 5 ms | 5468 KB | Output isn't correct |
7 | Incorrect | 149 ms | 12452 KB | Output isn't correct |
8 | Incorrect | 169 ms | 12444 KB | Output isn't correct |
9 | Incorrect | 217 ms | 13904 KB | Output isn't correct |
10 | Incorrect | 283 ms | 14424 KB | Output isn't correct |