#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
const int N=1e5;
int n, m, k;
int par[N];
int d[N], w[N];
map<int,ll> mp[N];
int main(){
cin.tie(0)->sync_with_stdio(0);
cin >> n >> m >> k;
for(int i=1; i<n; i++){
cin >> par[i]; --par[i];
}
for(int i=0; i<m; i++){
int v; cin >> v;
v--;
cin >> d[v] >> w[v];
}
auto join=[&](int i, int j){
if(mp[i].size()>mp[j].size()) swap(mp[i], mp[j]);
for(auto p:mp[i]){
mp[j][p.first]+=p.second;
}
};
for(int i=n-1; i>=0; i--){
mp[i][d[i]]+=w[i];
for(auto it=mp[i].upper_bound(d[i]); it!=mp[i].end(); ){
if(it->second>w[i]){
it->second-=w[i];
break;
}
w[i]-=it->second;
mp[i].erase(it);
}
// cout << "mp[" << i << "]\n";
// for(auto p:mp[i]) cout << p.first << " " << p.second << "\n";
if(i) join(i, par[i]);
}
ll ans=0;
for(auto p:mp[0]) ans+=p.second;
cout << ans;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
3 ms |
5028 KB |
Output is correct |
2 |
Correct |
3 ms |
5020 KB |
Output is correct |
3 |
Correct |
3 ms |
4948 KB |
Output is correct |
4 |
Correct |
3 ms |
4948 KB |
Output is correct |
5 |
Correct |
2 ms |
4948 KB |
Output is correct |
6 |
Correct |
3 ms |
4948 KB |
Output is correct |
7 |
Correct |
3 ms |
5024 KB |
Output is correct |
8 |
Correct |
4 ms |
4948 KB |
Output is correct |
9 |
Correct |
3 ms |
4948 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
63 ms |
19704 KB |
Output is correct |
2 |
Correct |
27 ms |
9640 KB |
Output is correct |
3 |
Correct |
152 ms |
40216 KB |
Output is correct |
4 |
Correct |
76 ms |
18228 KB |
Output is correct |
5 |
Correct |
106 ms |
22796 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
4 ms |
4948 KB |
Output is correct |
2 |
Correct |
3 ms |
4948 KB |
Output is correct |
3 |
Correct |
4 ms |
5076 KB |
Output is correct |
4 |
Correct |
40 ms |
8088 KB |
Output is correct |
5 |
Correct |
59 ms |
11992 KB |
Output is correct |
6 |
Correct |
60 ms |
8124 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
36 ms |
14796 KB |
Execution killed with signal 6 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
3 ms |
5028 KB |
Output is correct |
2 |
Correct |
3 ms |
5020 KB |
Output is correct |
3 |
Correct |
3 ms |
4948 KB |
Output is correct |
4 |
Correct |
3 ms |
4948 KB |
Output is correct |
5 |
Correct |
2 ms |
4948 KB |
Output is correct |
6 |
Correct |
3 ms |
4948 KB |
Output is correct |
7 |
Correct |
3 ms |
5024 KB |
Output is correct |
8 |
Correct |
4 ms |
4948 KB |
Output is correct |
9 |
Correct |
3 ms |
4948 KB |
Output is correct |
10 |
Correct |
60 ms |
15892 KB |
Output is correct |
11 |
Correct |
59 ms |
14672 KB |
Output is correct |
12 |
Correct |
35 ms |
9112 KB |
Output is correct |
13 |
Correct |
37 ms |
13464 KB |
Output is correct |
14 |
Correct |
31 ms |
7656 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
9 ms |
11560 KB |
Execution killed with signal 6 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
3 ms |
5028 KB |
Output is correct |
2 |
Correct |
3 ms |
5020 KB |
Output is correct |
3 |
Correct |
3 ms |
4948 KB |
Output is correct |
4 |
Correct |
3 ms |
4948 KB |
Output is correct |
5 |
Correct |
2 ms |
4948 KB |
Output is correct |
6 |
Correct |
3 ms |
4948 KB |
Output is correct |
7 |
Correct |
3 ms |
5024 KB |
Output is correct |
8 |
Correct |
4 ms |
4948 KB |
Output is correct |
9 |
Correct |
3 ms |
4948 KB |
Output is correct |
10 |
Correct |
4 ms |
4948 KB |
Output is correct |
11 |
Correct |
3 ms |
4948 KB |
Output is correct |
12 |
Correct |
4 ms |
5076 KB |
Output is correct |
13 |
Correct |
40 ms |
8088 KB |
Output is correct |
14 |
Correct |
59 ms |
11992 KB |
Output is correct |
15 |
Correct |
60 ms |
8124 KB |
Output is correct |
16 |
Correct |
60 ms |
15892 KB |
Output is correct |
17 |
Correct |
59 ms |
14672 KB |
Output is correct |
18 |
Correct |
35 ms |
9112 KB |
Output is correct |
19 |
Correct |
37 ms |
13464 KB |
Output is correct |
20 |
Correct |
31 ms |
7656 KB |
Output is correct |
21 |
Correct |
17 ms |
8828 KB |
Output is correct |
22 |
Correct |
61 ms |
19212 KB |
Output is correct |
23 |
Correct |
88 ms |
22936 KB |
Output is correct |
24 |
Correct |
122 ms |
32140 KB |
Output is correct |
25 |
Correct |
73 ms |
17436 KB |
Output is correct |
26 |
Correct |
79 ms |
17868 KB |
Output is correct |
27 |
Correct |
59 ms |
10912 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
3 ms |
5028 KB |
Output is correct |
2 |
Correct |
3 ms |
5020 KB |
Output is correct |
3 |
Correct |
3 ms |
4948 KB |
Output is correct |
4 |
Correct |
3 ms |
4948 KB |
Output is correct |
5 |
Correct |
2 ms |
4948 KB |
Output is correct |
6 |
Correct |
3 ms |
4948 KB |
Output is correct |
7 |
Correct |
3 ms |
5024 KB |
Output is correct |
8 |
Correct |
4 ms |
4948 KB |
Output is correct |
9 |
Correct |
3 ms |
4948 KB |
Output is correct |
10 |
Correct |
63 ms |
19704 KB |
Output is correct |
11 |
Correct |
27 ms |
9640 KB |
Output is correct |
12 |
Correct |
152 ms |
40216 KB |
Output is correct |
13 |
Correct |
76 ms |
18228 KB |
Output is correct |
14 |
Correct |
106 ms |
22796 KB |
Output is correct |
15 |
Correct |
4 ms |
4948 KB |
Output is correct |
16 |
Correct |
3 ms |
4948 KB |
Output is correct |
17 |
Correct |
4 ms |
5076 KB |
Output is correct |
18 |
Correct |
40 ms |
8088 KB |
Output is correct |
19 |
Correct |
59 ms |
11992 KB |
Output is correct |
20 |
Correct |
60 ms |
8124 KB |
Output is correct |
21 |
Runtime error |
36 ms |
14796 KB |
Execution killed with signal 6 |
22 |
Halted |
0 ms |
0 KB |
- |