#include <bits/stdc++.h>
using namespace std;
#define pb push_back
#define mp make_pair
typedef long long ll;
typedef pair<long long, long long> pll;
typedef pair<int,int> pii;
typedef vector<long long> vl;
typedef vector<int> vi;
int n, m, k;
vi G[100100];
vector<pll> fruits;
map<int, int> dp[100100];
void dfs(int node, int p){
// cout<<"AT: "<<node<<endl;
for(auto next : G[node]){
if(next !=p){
dfs(next, node);
if(dp[node].size() < dp[next].size()) swap(dp[node], dp[next]);
for(auto t : dp[next]) dp[node][t.first] += t.second;
}
}
if(fruits[node].first != -1){
ll hold = fruits[node].second;
while(hold > 0){
auto rem = dp[node].upper_bound(fruits[node].first);
if(rem == dp[node].end()) break;
if(rem->second <= hold){
hold -= rem->second;
dp[node].erase(rem);
}
else{
rem->second -= hold;
break;
}
}
dp[node][fruits[node].first] += fruits[node].second;
}
}
int main(){
ios_base::sync_with_stdio(false);
cin.tie(0);
cin>>n>>m>>k;
for(int i = 2; i <= n; i++){
int a;
cin>>a;
G[a-1].pb(i-1);
G[i-1].pb(a-1);
}
fruits.resize(n);
for(int i = 0; i < n; i++)
fruits[i] = mp(-1, -1);
for(int i = 0; i < m; i++){
int node, day, add;
cin>>node>>day>>add;
fruits[node] = mp(day, add);
}
ll ans = 0;
dfs(0, -1);
// cout<<dp[0].size()<<endl;
for(auto t : dp[0]) ans += t.second;
cout<<ans<<endl;
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
9 ms |
14676 KB |
Execution killed with signal 6 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
58 ms |
17292 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
9 ms |
15116 KB |
Execution killed with signal 6 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
62 ms |
14736 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
9 ms |
14676 KB |
Execution killed with signal 6 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
8 ms |
8404 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
9 ms |
14676 KB |
Execution killed with signal 6 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
9 ms |
14676 KB |
Execution killed with signal 6 |
2 |
Halted |
0 ms |
0 KB |
- |