Submission #925180

#TimeUsernameProblemLanguageResultExecution timeMemory
92518012345678Magic Tree (CEOI19_magictree)C++17
34 / 100
2100 ms33884 KiB
#include <bits/stdc++.h> using namespace std; #define ll long long const int nx=1e5+5, kx=21; ll n, m, k, t[nx], w[nx], p, dp[nx][kx], x, ans, vl; vector<int> d[nx]; void dfs(int u) { for (auto v:d[u]) { dfs(v); for (int i=1; i<=k; i++) dp[u][i]+=dp[v][i]; } dp[u][t[u]]+=w[u]; for (int i=t[u]+1; i<=k; i++) dp[u][i]=max(dp[u][i], dp[u][i-1]); } int main() { cin.tie(NULL)->sync_with_stdio(false); cin>>n>>m>>k; for (int i=2; i<=n; i++) cin>>p, d[p].push_back(i); for (int i=1; i<=m; i++) cin>>x>>t[x]>>w[x]; dfs(1); for (int i=1; i<=k; i++) ans=max(ans, dp[1][i]); cout<<ans<<'\n'; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...