#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 |
1 |
Incorrect |
1 ms |
4440 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
66 ms |
25684 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
4 ms |
6744 KB |
Output is correct |
2 |
Incorrect |
3 ms |
6748 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
84 ms |
26368 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
1 ms |
4440 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
1955 ms |
11324 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
1 ms |
4440 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
1 ms |
4440 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |