Submission #508241

#TimeUsernameProblemLanguageResultExecution timeMemory
508241sidonBiochips (IZhO12_biochips)C++17
100 / 100
498 ms395164 KiB
#include <bits/stdc++.h> using namespace std; const int Z = 2e5+1; int N, M, S[Z], rt, dp[Z][501], r; vector<int> g[Z]; #define pull for(int i = M + 1; --i; ) dp[r][i] = max(dp[r][i], dp void dfs(int u) { int l = r; if(empty(g[u])) { ++r; pull [r-1][i]); } for(int v : g[u]) dfs(v); pull [l][i-1] + S[u]); } int main() { cin >> N >> M; for(int i=1; i<=N; ++i) { int p; cin >> p >> S[i]; if(p) g[p].push_back(i); else S[rt = i] = 0; } dfs(rt); cout << *max_element(dp[r], dp[r] + M + 1); }
#Verdict Execution timeMemoryGrader output
Fetching results...