#include "bits/stdc++.h"
using namespace std;
#define INF 2000000000
#define INFLL 3000000000000000000LL
#define ll long long
int n,m,k;
vector<int>childs[100000];
vector<long long> fr(100000);
vector<int> dy(100000);
vector<long long> dfs(int v){
vector<long long>cur(k);
for(int i:childs[v]){
vector<long long>vec=dfs(i);
for(int j=0;j<k;j++){
cur[j]+=vec[j];
}
}
if(fr[v]>0){
int sum=0;
for(int i=dy[v]+1;i<k;i++){
sum+=cur[i];
}
if(sum<fr[v]){
cur[dy[v]]+=fr[v];
for(int i=dy[v]+1;i<k;i++){
cur[i]=0;
}
}
}
return cur;
}
int main() {
cin.tie(0)->sync_with_stdio(0);
cin>>n>>m>>k;
int par[n];
par[0]=-1;
for(int i=1;i<n;i++){
cin>>par[i];
par[i]--;
childs[par[i]].push_back(i);
fr[i]=0;
dy[i]=0;
}
for(int i=0;i<m;i++){
int v,d,w;
cin>>v>>d>>w;
v--;
d--;
fr[v]=w;
dy[v]=d;
}
int out=0;
vector<long long>vec=dfs(0);
for(int i:vec)out+=i;
cout<<out;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
3796 KB |
Output is correct |
2 |
Incorrect |
2 ms |
3796 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Execution timed out |
2045 ms |
24480 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
11 ms |
11732 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
58 ms |
5852 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
3796 KB |
Output is correct |
2 |
Incorrect |
2 ms |
3796 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Execution timed out |
2073 ms |
12836 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
3796 KB |
Output is correct |
2 |
Incorrect |
2 ms |
3796 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
3796 KB |
Output is correct |
2 |
Incorrect |
2 ms |
3796 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |