# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
954123 | adaawf | Biochips (IZhO12_biochips) | C++17 | 513 ms | 403664 KiB |
This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <iostream>
#include <vector>
using namespace std;
vector<int> g[200005];
int f[200005][505], a[200005], k;
void dfs(int x) {
for (int w : g[x]) {
dfs(w);
for (int i = k; i >= 0; i--) {
for (int j = 0; j <= k - i; j++) {
if (j != 0 && f[w][j] == 0) break;
f[x][i + j] = max(f[x][i + j], f[x][i] + f[w][j]);
}
}
}
f[x][1] = max(f[x][1], a[x]);
}
int main() {
ios::sync_with_stdio(0);
cin.tie(0); cout.tie(0);
int n, r = 0;
cin >> n >> k;
for (int i = 1; i <= n; i++) {
int x, y;
cin >> x >> y;
a[i] = y;
if (x == 0) {
r = i;
}
else {
g[x].push_back(i);
}
}
dfs(r);
cout << f[r][k];
}
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |