Submission #913980

#TimeUsernameProblemLanguageResultExecution timeMemory
913980trashaccountBiochips (IZhO12_biochips)C++11
90 / 100
202 ms402044 KiB
#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 timeMemoryGrader output
Fetching results...