# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
913980 | trashaccount | Biochips (IZhO12_biochips) | C++11 | 202 ms | 402044 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 <bits/stdc++.h>
using namespace std;
int N, M, p[200005], x[200005], rt;
vector <int> son[200005];
int timer = 0, dp[200005][505];
void dfs(int u){
int pre = timer;
for (int v : son[u]) dfs(v);
timer++;
for (int i = 1; i <= M; i++)
dp[timer][i] = max(dp[pre][i-1]+x[u], dp[timer-1][i]);
}
int main(){
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
cin >> N >> M;
for (int i = 1; i <= N; i++){
cin >> p[i] >> x[i];
if (!p[i]) rt = i;
son[p[i]].push_back(i);
}
for (int i = 1; i <= M; i++) dp[0][i] = -1e9;
dfs(rt);
cout << dp[timer][M];
return 0;
}
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |