#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define pb push_back
const int mxN = 1e5 + 5;
ll n,m,k;
pair<int,int> a[mxN];
vector<int> v[mxN];
map<int, ll> dp[mxN];
void dfs(ll at, ll p){
for(auto it : v[at]){
if(it == p) continue;
dfs(it, at);
if(dp[it].size() > dp[at].size()) swap(dp[it], dp[at]);
for(auto it1 : dp[it]) dp[at][it1.first] += it1.second;
dp[it].clear();
}
dp[at][a[at].first] += a[at].second;
ll left = a[at].second;
for(auto it = dp[at].upper_bound(a[at].first); it != dp[at].end();){
if((*it).second > left){
(*it).second -= left;
break;
}
left -= (*it).second;
dp[at].erase(it++);
}
}
int main(){
ios::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
cin >> n >> m >> k;
for(int i = 2; i <= n; i++){
ll p;
cin >> p;
v[p].pb(i);
v[i].pb(p);
}
for(int i = 0; i < m; i++){
ll idx,d,w;
cin >> idx >> d >> w;
a[idx] = {d, w};
}
dfs(1, 1);
ll ans = 0;
for(auto it : dp[1]) ans += it.second;
cout << ans;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
7256 KB |
Output is correct |
2 |
Correct |
1 ms |
7256 KB |
Output is correct |
3 |
Correct |
2 ms |
7260 KB |
Output is correct |
4 |
Correct |
1 ms |
7260 KB |
Output is correct |
5 |
Correct |
1 ms |
7260 KB |
Output is correct |
6 |
Correct |
1 ms |
7260 KB |
Output is correct |
7 |
Correct |
1 ms |
7260 KB |
Output is correct |
8 |
Correct |
1 ms |
7260 KB |
Output is correct |
9 |
Correct |
1 ms |
7260 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
47 ms |
13392 KB |
Output is correct |
2 |
Correct |
26 ms |
19280 KB |
Output is correct |
3 |
Correct |
72 ms |
16472 KB |
Output is correct |
4 |
Correct |
55 ms |
15308 KB |
Output is correct |
5 |
Correct |
65 ms |
17232 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
7512 KB |
Output is correct |
2 |
Correct |
2 ms |
7516 KB |
Output is correct |
3 |
Correct |
1 ms |
7516 KB |
Output is correct |
4 |
Correct |
45 ms |
28464 KB |
Output is correct |
5 |
Correct |
46 ms |
32336 KB |
Output is correct |
6 |
Correct |
42 ms |
28480 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
30 ms |
11356 KB |
Output is correct |
2 |
Correct |
46 ms |
11356 KB |
Output is correct |
3 |
Correct |
30 ms |
18064 KB |
Output is correct |
4 |
Correct |
25 ms |
11732 KB |
Output is correct |
5 |
Correct |
33 ms |
28496 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
7256 KB |
Output is correct |
2 |
Correct |
1 ms |
7256 KB |
Output is correct |
3 |
Correct |
2 ms |
7260 KB |
Output is correct |
4 |
Correct |
1 ms |
7260 KB |
Output is correct |
5 |
Correct |
1 ms |
7260 KB |
Output is correct |
6 |
Correct |
1 ms |
7260 KB |
Output is correct |
7 |
Correct |
1 ms |
7260 KB |
Output is correct |
8 |
Correct |
1 ms |
7260 KB |
Output is correct |
9 |
Correct |
1 ms |
7260 KB |
Output is correct |
10 |
Correct |
44 ms |
11356 KB |
Output is correct |
11 |
Correct |
33 ms |
11352 KB |
Output is correct |
12 |
Correct |
31 ms |
18072 KB |
Output is correct |
13 |
Correct |
30 ms |
11732 KB |
Output is correct |
14 |
Correct |
30 ms |
28472 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
7 ms |
8280 KB |
Output is correct |
2 |
Correct |
19 ms |
11416 KB |
Output is correct |
3 |
Correct |
21 ms |
11356 KB |
Output is correct |
4 |
Correct |
27 ms |
11356 KB |
Output is correct |
5 |
Correct |
15 ms |
11868 KB |
Output is correct |
6 |
Correct |
25 ms |
14928 KB |
Output is correct |
7 |
Correct |
28 ms |
18320 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
7256 KB |
Output is correct |
2 |
Correct |
1 ms |
7256 KB |
Output is correct |
3 |
Correct |
2 ms |
7260 KB |
Output is correct |
4 |
Correct |
1 ms |
7260 KB |
Output is correct |
5 |
Correct |
1 ms |
7260 KB |
Output is correct |
6 |
Correct |
1 ms |
7260 KB |
Output is correct |
7 |
Correct |
1 ms |
7260 KB |
Output is correct |
8 |
Correct |
1 ms |
7260 KB |
Output is correct |
9 |
Correct |
1 ms |
7260 KB |
Output is correct |
10 |
Correct |
2 ms |
7512 KB |
Output is correct |
11 |
Correct |
2 ms |
7516 KB |
Output is correct |
12 |
Correct |
1 ms |
7516 KB |
Output is correct |
13 |
Correct |
45 ms |
28464 KB |
Output is correct |
14 |
Correct |
46 ms |
32336 KB |
Output is correct |
15 |
Correct |
42 ms |
28480 KB |
Output is correct |
16 |
Correct |
44 ms |
11356 KB |
Output is correct |
17 |
Correct |
33 ms |
11352 KB |
Output is correct |
18 |
Correct |
31 ms |
18072 KB |
Output is correct |
19 |
Correct |
30 ms |
11732 KB |
Output is correct |
20 |
Correct |
30 ms |
28472 KB |
Output is correct |
21 |
Correct |
10 ms |
8540 KB |
Output is correct |
22 |
Correct |
54 ms |
11800 KB |
Output is correct |
23 |
Correct |
56 ms |
13648 KB |
Output is correct |
24 |
Correct |
82 ms |
14676 KB |
Output is correct |
25 |
Correct |
38 ms |
15496 KB |
Output is correct |
26 |
Correct |
74 ms |
18896 KB |
Output is correct |
27 |
Correct |
56 ms |
19796 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
7256 KB |
Output is correct |
2 |
Correct |
1 ms |
7256 KB |
Output is correct |
3 |
Correct |
2 ms |
7260 KB |
Output is correct |
4 |
Correct |
1 ms |
7260 KB |
Output is correct |
5 |
Correct |
1 ms |
7260 KB |
Output is correct |
6 |
Correct |
1 ms |
7260 KB |
Output is correct |
7 |
Correct |
1 ms |
7260 KB |
Output is correct |
8 |
Correct |
1 ms |
7260 KB |
Output is correct |
9 |
Correct |
1 ms |
7260 KB |
Output is correct |
10 |
Correct |
47 ms |
13392 KB |
Output is correct |
11 |
Correct |
26 ms |
19280 KB |
Output is correct |
12 |
Correct |
72 ms |
16472 KB |
Output is correct |
13 |
Correct |
55 ms |
15308 KB |
Output is correct |
14 |
Correct |
65 ms |
17232 KB |
Output is correct |
15 |
Correct |
2 ms |
7512 KB |
Output is correct |
16 |
Correct |
2 ms |
7516 KB |
Output is correct |
17 |
Correct |
1 ms |
7516 KB |
Output is correct |
18 |
Correct |
45 ms |
28464 KB |
Output is correct |
19 |
Correct |
46 ms |
32336 KB |
Output is correct |
20 |
Correct |
42 ms |
28480 KB |
Output is correct |
21 |
Correct |
30 ms |
11356 KB |
Output is correct |
22 |
Correct |
46 ms |
11356 KB |
Output is correct |
23 |
Correct |
30 ms |
18064 KB |
Output is correct |
24 |
Correct |
25 ms |
11732 KB |
Output is correct |
25 |
Correct |
33 ms |
28496 KB |
Output is correct |
26 |
Correct |
44 ms |
11356 KB |
Output is correct |
27 |
Correct |
33 ms |
11352 KB |
Output is correct |
28 |
Correct |
31 ms |
18072 KB |
Output is correct |
29 |
Correct |
30 ms |
11732 KB |
Output is correct |
30 |
Correct |
30 ms |
28472 KB |
Output is correct |
31 |
Correct |
7 ms |
8280 KB |
Output is correct |
32 |
Correct |
19 ms |
11416 KB |
Output is correct |
33 |
Correct |
21 ms |
11356 KB |
Output is correct |
34 |
Correct |
27 ms |
11356 KB |
Output is correct |
35 |
Correct |
15 ms |
11868 KB |
Output is correct |
36 |
Correct |
25 ms |
14928 KB |
Output is correct |
37 |
Correct |
28 ms |
18320 KB |
Output is correct |
38 |
Correct |
10 ms |
8540 KB |
Output is correct |
39 |
Correct |
54 ms |
11800 KB |
Output is correct |
40 |
Correct |
56 ms |
13648 KB |
Output is correct |
41 |
Correct |
82 ms |
14676 KB |
Output is correct |
42 |
Correct |
38 ms |
15496 KB |
Output is correct |
43 |
Correct |
74 ms |
18896 KB |
Output is correct |
44 |
Correct |
56 ms |
19796 KB |
Output is correct |
45 |
Correct |
10 ms |
8540 KB |
Output is correct |
46 |
Correct |
42 ms |
11812 KB |
Output is correct |
47 |
Correct |
42 ms |
13692 KB |
Output is correct |
48 |
Correct |
68 ms |
15192 KB |
Output is correct |
49 |
Correct |
50 ms |
15316 KB |
Output is correct |
50 |
Correct |
53 ms |
19252 KB |
Output is correct |
51 |
Correct |
48 ms |
20032 KB |
Output is correct |