# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
38455 | 14kg | Biochips (IZhO12_biochips) | C++11 | 209 ms | 399104 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 <stdio.h>
#include <vector>
#define N 200002
#define INF 2000000000
#define max2(x,y) (x>y?x:y)
using namespace std;
int n, m, dp_lev;
int dp[N][501], in[N];
vector<int> r[N];
void f(int x) {
int temp = dp_lev;
for (auto i : r[x]) f(i);
dp_lev++;
for (int i = 1; i <= m; i++) dp[dp_lev][i] = max2(dp[dp_lev - 1][i], dp[temp][i - 1] + in[x]);
}
int main() {
int x;
scanf("%d %d", &n, &m);
for (int i = 1; i <= n; i++) {
scanf("%d %d", &x, &in[i]);
r[x].push_back(i);
}
for (int i = 1; i <= m; i++) dp[0][i] = -INF;
f(0), printf("%d", dp[dp_lev][m]);
}
Compilation message (stderr)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |