#include <bits/stdc++.h>
using namespace std;
#define ll long long
const int nx=1e5+5;
ll n, m, k, t[nx], w[nx], p, l, res;
vector<int> d[nx];
map<ll, ll> dp[nx];
void dfs(int u)
{
for (auto v:d[u])
{
dfs(v);
if (dp[v].size()>dp[u].size()) swap(dp[u], dp[v]);
for (auto [x, y]:dp[v]) dp[u][x]+=y;
dp[v].clear();
}
int vl=w[u];
dp[u][t[u]]+=w[u];
for (auto itr=next(dp[u].find(t[u])); itr!=dp[u].end();)
{
if (vl>=itr->second)
{
vl-=itr->second;
itr=dp[u].erase(itr);
}
else {
itr->second-=vl;
break;
}
}
}
int main()
{
cin.tie(NULL)->sync_with_stdio(false);
cin>>n>>m>>k;
for (int i=2; i<=n; i++) cin>>p, d[p].push_back(i);
for (int i=1; i<=m; i++) cin>>l>>t[l]>>w[l];
dfs(1);
for (auto [x, y]:dp[1]) res+=y;
cout<<res<<'\n';
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
8800 KB |
Output is correct |
2 |
Correct |
3 ms |
9052 KB |
Output is correct |
3 |
Correct |
2 ms |
8796 KB |
Output is correct |
4 |
Correct |
2 ms |
8608 KB |
Output is correct |
5 |
Correct |
2 ms |
8792 KB |
Output is correct |
6 |
Correct |
2 ms |
8792 KB |
Output is correct |
7 |
Correct |
2 ms |
8796 KB |
Output is correct |
8 |
Correct |
2 ms |
8844 KB |
Output is correct |
9 |
Correct |
2 ms |
8792 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
47 ms |
13536 KB |
Output is correct |
2 |
Correct |
38 ms |
20308 KB |
Output is correct |
3 |
Correct |
93 ms |
16756 KB |
Output is correct |
4 |
Correct |
55 ms |
15076 KB |
Output is correct |
5 |
Correct |
69 ms |
17284 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
8792 KB |
Output is correct |
2 |
Correct |
3 ms |
8796 KB |
Output is correct |
3 |
Correct |
2 ms |
9052 KB |
Output is correct |
4 |
Correct |
39 ms |
29524 KB |
Output is correct |
5 |
Correct |
64 ms |
33588 KB |
Output is correct |
6 |
Correct |
64 ms |
29776 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
44 ms |
12804 KB |
Output is correct |
2 |
Correct |
49 ms |
12636 KB |
Output is correct |
3 |
Correct |
44 ms |
19960 KB |
Output is correct |
4 |
Correct |
25 ms |
11228 KB |
Output is correct |
5 |
Correct |
53 ms |
29780 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
8800 KB |
Output is correct |
2 |
Correct |
3 ms |
9052 KB |
Output is correct |
3 |
Correct |
2 ms |
8796 KB |
Output is correct |
4 |
Correct |
2 ms |
8608 KB |
Output is correct |
5 |
Correct |
2 ms |
8792 KB |
Output is correct |
6 |
Correct |
2 ms |
8792 KB |
Output is correct |
7 |
Correct |
2 ms |
8796 KB |
Output is correct |
8 |
Correct |
2 ms |
8844 KB |
Output is correct |
9 |
Correct |
2 ms |
8792 KB |
Output is correct |
10 |
Correct |
52 ms |
12148 KB |
Output is correct |
11 |
Correct |
38 ms |
12116 KB |
Output is correct |
12 |
Correct |
36 ms |
19248 KB |
Output is correct |
13 |
Correct |
30 ms |
10684 KB |
Output is correct |
14 |
Correct |
37 ms |
29252 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
5 ms |
9308 KB |
Output is correct |
2 |
Correct |
27 ms |
11092 KB |
Output is correct |
3 |
Correct |
19 ms |
11260 KB |
Output is correct |
4 |
Correct |
20 ms |
11508 KB |
Output is correct |
5 |
Correct |
11 ms |
9696 KB |
Output is correct |
6 |
Correct |
21 ms |
14168 KB |
Output is correct |
7 |
Correct |
29 ms |
18268 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
8800 KB |
Output is correct |
2 |
Correct |
3 ms |
9052 KB |
Output is correct |
3 |
Correct |
2 ms |
8796 KB |
Output is correct |
4 |
Correct |
2 ms |
8608 KB |
Output is correct |
5 |
Correct |
2 ms |
8792 KB |
Output is correct |
6 |
Correct |
2 ms |
8792 KB |
Output is correct |
7 |
Correct |
2 ms |
8796 KB |
Output is correct |
8 |
Correct |
2 ms |
8844 KB |
Output is correct |
9 |
Correct |
2 ms |
8792 KB |
Output is correct |
10 |
Correct |
2 ms |
8792 KB |
Output is correct |
11 |
Correct |
3 ms |
8796 KB |
Output is correct |
12 |
Correct |
2 ms |
9052 KB |
Output is correct |
13 |
Correct |
39 ms |
29524 KB |
Output is correct |
14 |
Correct |
64 ms |
33588 KB |
Output is correct |
15 |
Correct |
64 ms |
29776 KB |
Output is correct |
16 |
Correct |
52 ms |
12148 KB |
Output is correct |
17 |
Correct |
38 ms |
12116 KB |
Output is correct |
18 |
Correct |
36 ms |
19248 KB |
Output is correct |
19 |
Correct |
30 ms |
10684 KB |
Output is correct |
20 |
Correct |
37 ms |
29252 KB |
Output is correct |
21 |
Correct |
12 ms |
9560 KB |
Output is correct |
22 |
Correct |
55 ms |
12260 KB |
Output is correct |
23 |
Correct |
60 ms |
14128 KB |
Output is correct |
24 |
Correct |
77 ms |
15696 KB |
Output is correct |
25 |
Correct |
49 ms |
14324 KB |
Output is correct |
26 |
Correct |
62 ms |
19280 KB |
Output is correct |
27 |
Correct |
55 ms |
21024 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
8800 KB |
Output is correct |
2 |
Correct |
3 ms |
9052 KB |
Output is correct |
3 |
Correct |
2 ms |
8796 KB |
Output is correct |
4 |
Correct |
2 ms |
8608 KB |
Output is correct |
5 |
Correct |
2 ms |
8792 KB |
Output is correct |
6 |
Correct |
2 ms |
8792 KB |
Output is correct |
7 |
Correct |
2 ms |
8796 KB |
Output is correct |
8 |
Correct |
2 ms |
8844 KB |
Output is correct |
9 |
Correct |
2 ms |
8792 KB |
Output is correct |
10 |
Correct |
47 ms |
13536 KB |
Output is correct |
11 |
Correct |
38 ms |
20308 KB |
Output is correct |
12 |
Correct |
93 ms |
16756 KB |
Output is correct |
13 |
Correct |
55 ms |
15076 KB |
Output is correct |
14 |
Correct |
69 ms |
17284 KB |
Output is correct |
15 |
Correct |
2 ms |
8792 KB |
Output is correct |
16 |
Correct |
3 ms |
8796 KB |
Output is correct |
17 |
Correct |
2 ms |
9052 KB |
Output is correct |
18 |
Correct |
39 ms |
29524 KB |
Output is correct |
19 |
Correct |
64 ms |
33588 KB |
Output is correct |
20 |
Correct |
64 ms |
29776 KB |
Output is correct |
21 |
Correct |
44 ms |
12804 KB |
Output is correct |
22 |
Correct |
49 ms |
12636 KB |
Output is correct |
23 |
Correct |
44 ms |
19960 KB |
Output is correct |
24 |
Correct |
25 ms |
11228 KB |
Output is correct |
25 |
Correct |
53 ms |
29780 KB |
Output is correct |
26 |
Correct |
52 ms |
12148 KB |
Output is correct |
27 |
Correct |
38 ms |
12116 KB |
Output is correct |
28 |
Correct |
36 ms |
19248 KB |
Output is correct |
29 |
Correct |
30 ms |
10684 KB |
Output is correct |
30 |
Correct |
37 ms |
29252 KB |
Output is correct |
31 |
Correct |
5 ms |
9308 KB |
Output is correct |
32 |
Correct |
27 ms |
11092 KB |
Output is correct |
33 |
Correct |
19 ms |
11260 KB |
Output is correct |
34 |
Correct |
20 ms |
11508 KB |
Output is correct |
35 |
Correct |
11 ms |
9696 KB |
Output is correct |
36 |
Correct |
21 ms |
14168 KB |
Output is correct |
37 |
Correct |
29 ms |
18268 KB |
Output is correct |
38 |
Correct |
12 ms |
9560 KB |
Output is correct |
39 |
Correct |
55 ms |
12260 KB |
Output is correct |
40 |
Correct |
60 ms |
14128 KB |
Output is correct |
41 |
Correct |
77 ms |
15696 KB |
Output is correct |
42 |
Correct |
49 ms |
14324 KB |
Output is correct |
43 |
Correct |
62 ms |
19280 KB |
Output is correct |
44 |
Correct |
55 ms |
21024 KB |
Output is correct |
45 |
Correct |
14 ms |
9820 KB |
Output is correct |
46 |
Correct |
47 ms |
12468 KB |
Output is correct |
47 |
Correct |
56 ms |
14168 KB |
Output is correct |
48 |
Correct |
81 ms |
16736 KB |
Output is correct |
49 |
Correct |
46 ms |
15060 KB |
Output is correct |
50 |
Correct |
64 ms |
20256 KB |
Output is correct |
51 |
Correct |
74 ms |
21844 KB |
Output is correct |