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;
const int maxn = 1e5;
const int maxk = 20;
int n,m,k;
int parent[maxn+5];
int w[maxn+5];
int day[maxn+5];
vector<int> con[maxn+5];
long long dp[maxn+5][maxk+5];
void dfs(int nod)
{
for(auto adj:con[nod])
{
dfs(adj);
}
for(int j=1;j<=k;j++)
{
dp[nod][j]=0;
for(auto adj:con[nod])
dp[nod][j] += dp[adj][j];
if(j==day[nod])
dp[nod][j] += w[nod];
//dp[nod][j] = max(dp[nod][j], dp[nod][j-1]);
}
}
signed main()
{
cin>>n>>m>>k;
for(int i=2;i<=n;i++)
{
cin>>parent[i];
con[parent[i]].push_back(i);
}
int a;
for(int i=1;i<=m;i++)
{
cin>>a;
cin>>day[a]>>w[a];
}
dfs(1);
long long mxm=0;
for(int j=1;j<=k;j++)
mxm = max(mxm, dp[1][j]);
cout<<mxm;
return 0;
}
/**
dp[i][j] = numarul maxim de suc cules din subarborele lui i a.i. sa taiem edgeul (i,parent[i]) in ziua j
pt j!=zi[i] dp[i][j] = sum(dp[child][orice<=j])
dp[i][zi[i]] = w[i] + sum(dp[child][orice<=j])
*/
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |