#include <bits/stdc++.h>
#define DIM 1010
using namespace std;
int dp[DIM][DIM],v[DIM],cost[DIM];
vector <int> L[DIM];
int n,m,k,i,j,x,y,w,d;
void dfs (int nod, int tata){
int ok = 0;
for (auto vecin : L[nod])
if (vecin != tata){
ok = 1;
dfs (vecin,nod);
}
if (!ok){
if (v[nod]){
for (int i=v[nod];i<=k;i++)
dp[nod][i] = cost[nod];
}
} else {
for (auto vecin : L[nod]){
if (vecin == tata)
continue;
for (int i=1;i<=k;i++)
dp[nod][i] += dp[vecin][i];
}
if (v[nod]){
int val = cost[nod];
for (auto vecin : L[nod])
if (vecin != tata)
val += dp[vecin][v[nod]];
dp[nod][v[nod]] = max (dp[nod][v[nod]],val);
}
for (int i=1;i<=k;i++)
dp[nod][i] = max (dp[nod][i],dp[nod][i-1]);
}
}
int main (){
//ifstream cin ("date.in");
//ofstream cout ("date.out");
cin>>n>>m>>k;
for (i=2;i<=n;i++){
cin>>x;
L[x].push_back(i);
L[i].push_back(x);
}
for (i=1;i<=m;i++){
cin>>x>>d>>w;
v[x] = d, cost[x] = w;
}
dfs (1,0);
int sol = 0;
for (i=1;i<=k;i++)
sol = max (sol,dp[1][i]);
cout<<sol;
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
332 KB |
Output is correct |
2 |
Correct |
1 ms |
328 KB |
Output is correct |
3 |
Correct |
1 ms |
332 KB |
Output is correct |
4 |
Correct |
1 ms |
332 KB |
Output is correct |
5 |
Correct |
1 ms |
332 KB |
Output is correct |
6 |
Correct |
1 ms |
332 KB |
Output is correct |
7 |
Correct |
1 ms |
332 KB |
Output is correct |
8 |
Correct |
1 ms |
332 KB |
Output is correct |
9 |
Correct |
1 ms |
332 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
104 ms |
12936 KB |
Execution killed with signal 11 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
8 ms |
4300 KB |
Output is correct |
2 |
Correct |
8 ms |
4300 KB |
Output is correct |
3 |
Correct |
8 ms |
4380 KB |
Output is correct |
4 |
Runtime error |
155 ms |
13552 KB |
Execution killed with signal 11 |
5 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
173 ms |
13788 KB |
Execution killed with signal 11 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
332 KB |
Output is correct |
2 |
Correct |
1 ms |
328 KB |
Output is correct |
3 |
Correct |
1 ms |
332 KB |
Output is correct |
4 |
Correct |
1 ms |
332 KB |
Output is correct |
5 |
Correct |
1 ms |
332 KB |
Output is correct |
6 |
Correct |
1 ms |
332 KB |
Output is correct |
7 |
Correct |
1 ms |
332 KB |
Output is correct |
8 |
Correct |
1 ms |
332 KB |
Output is correct |
9 |
Correct |
1 ms |
332 KB |
Output is correct |
10 |
Runtime error |
154 ms |
13144 KB |
Execution killed with signal 11 |
11 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
12 ms |
2764 KB |
Execution killed with signal 11 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
332 KB |
Output is correct |
2 |
Correct |
1 ms |
328 KB |
Output is correct |
3 |
Correct |
1 ms |
332 KB |
Output is correct |
4 |
Correct |
1 ms |
332 KB |
Output is correct |
5 |
Correct |
1 ms |
332 KB |
Output is correct |
6 |
Correct |
1 ms |
332 KB |
Output is correct |
7 |
Correct |
1 ms |
332 KB |
Output is correct |
8 |
Correct |
1 ms |
332 KB |
Output is correct |
9 |
Correct |
1 ms |
332 KB |
Output is correct |
10 |
Correct |
8 ms |
4300 KB |
Output is correct |
11 |
Correct |
8 ms |
4300 KB |
Output is correct |
12 |
Correct |
8 ms |
4380 KB |
Output is correct |
13 |
Runtime error |
155 ms |
13552 KB |
Execution killed with signal 11 |
14 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
332 KB |
Output is correct |
2 |
Correct |
1 ms |
328 KB |
Output is correct |
3 |
Correct |
1 ms |
332 KB |
Output is correct |
4 |
Correct |
1 ms |
332 KB |
Output is correct |
5 |
Correct |
1 ms |
332 KB |
Output is correct |
6 |
Correct |
1 ms |
332 KB |
Output is correct |
7 |
Correct |
1 ms |
332 KB |
Output is correct |
8 |
Correct |
1 ms |
332 KB |
Output is correct |
9 |
Correct |
1 ms |
332 KB |
Output is correct |
10 |
Runtime error |
104 ms |
12936 KB |
Execution killed with signal 11 |
11 |
Halted |
0 ms |
0 KB |
- |