Submission #934264

# Submission time Handle Problem Language Result Execution time Memory
934264 2024-02-27T04:33:31 Z tamir1 Magic Tree (CEOI19_magictree) C++14
100 / 100
116 ms 36688 KB
#include<bits/stdc++.h>
#define ll long long
using namespace std;
ll n,m,k,i,day[100005],x[100005],node,d,w,p[100005],ans;
vector<ll> v[100005];
map<ll,ll> mp[100005];
map<ll,ll> ::iterator it;
void dfs(ll a){
	for(ll i:v[a]){
		dfs(i);
		if(mp[a].size()<mp[i].size()) swap(mp[a],mp[i]);
		for(it=mp[i].begin();it!=mp[i].end();it++){
			mp[a][it->first]+=it->second;
		}
	}
	if(day[a]>0){
		mp[a][day[a]]+=x[a];
		while(true){
			it=mp[a].upper_bound(day[a]);
			if(it==mp[a].end()) break;
			if(it->second<=x[a]){
				x[a]-=it->second;
				mp[a].erase(it);
				continue;
			}
			it->second-=x[a];
			break;
		}
	}
}
int main(){
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
	cin >> n >> m >> k;
	for(i=2;i<=n;i++){
		cin >> p[i];
		v[p[i]].push_back(i);
	}
	for(i=1;i<=m;i++){
		cin >> node >> d >> w;
		day[node]=d;
		x[node]=w;
	}
	dfs(1);
	for(it=mp[1].begin();it!=mp[1].end();it++) ans+=it->second;
	cout << ans;
}
# Verdict Execution time Memory Grader output
1 Correct 2 ms 8796 KB Output is correct
2 Correct 2 ms 8796 KB Output is correct
3 Correct 2 ms 8796 KB Output is correct
4 Correct 2 ms 8624 KB Output is correct
5 Correct 2 ms 8796 KB Output is correct
6 Correct 2 ms 8796 KB Output is correct
7 Correct 2 ms 8796 KB Output is correct
8 Correct 2 ms 8808 KB Output is correct
9 Correct 2 ms 8796 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 42 ms 19352 KB Output is correct
2 Correct 30 ms 19032 KB Output is correct
3 Correct 106 ms 36688 KB Output is correct
4 Correct 57 ms 19816 KB Output is correct
5 Correct 72 ms 21468 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 8796 KB Output is correct
2 Correct 2 ms 8796 KB Output is correct
3 Correct 2 ms 8796 KB Output is correct
4 Correct 48 ms 23912 KB Output is correct
5 Correct 58 ms 27732 KB Output is correct
6 Correct 57 ms 23812 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 46 ms 15168 KB Output is correct
2 Correct 38 ms 14436 KB Output is correct
3 Correct 36 ms 17756 KB Output is correct
4 Correct 32 ms 16076 KB Output is correct
5 Correct 34 ms 23892 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 8796 KB Output is correct
2 Correct 2 ms 8796 KB Output is correct
3 Correct 2 ms 8796 KB Output is correct
4 Correct 2 ms 8624 KB Output is correct
5 Correct 2 ms 8796 KB Output is correct
6 Correct 2 ms 8796 KB Output is correct
7 Correct 2 ms 8796 KB Output is correct
8 Correct 2 ms 8808 KB Output is correct
9 Correct 2 ms 8796 KB Output is correct
10 Correct 65 ms 18116 KB Output is correct
11 Correct 50 ms 17232 KB Output is correct
12 Correct 36 ms 17748 KB Output is correct
13 Correct 27 ms 16080 KB Output is correct
14 Correct 33 ms 23880 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 5 ms 9564 KB Output is correct
2 Correct 19 ms 11708 KB Output is correct
3 Correct 15 ms 11672 KB Output is correct
4 Correct 21 ms 11864 KB Output is correct
5 Correct 7 ms 10712 KB Output is correct
6 Correct 19 ms 13740 KB Output is correct
7 Correct 17 ms 16732 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 8796 KB Output is correct
2 Correct 2 ms 8796 KB Output is correct
3 Correct 2 ms 8796 KB Output is correct
4 Correct 2 ms 8624 KB Output is correct
5 Correct 2 ms 8796 KB Output is correct
6 Correct 2 ms 8796 KB Output is correct
7 Correct 2 ms 8796 KB Output is correct
8 Correct 2 ms 8808 KB Output is correct
9 Correct 2 ms 8796 KB Output is correct
10 Correct 2 ms 8796 KB Output is correct
11 Correct 2 ms 8796 KB Output is correct
12 Correct 2 ms 8796 KB Output is correct
13 Correct 48 ms 23912 KB Output is correct
14 Correct 58 ms 27732 KB Output is correct
15 Correct 57 ms 23812 KB Output is correct
16 Correct 65 ms 18116 KB Output is correct
17 Correct 50 ms 17232 KB Output is correct
18 Correct 36 ms 17748 KB Output is correct
19 Correct 27 ms 16080 KB Output is correct
20 Correct 33 ms 23880 KB Output is correct
21 Correct 14 ms 11868 KB Output is correct
22 Correct 49 ms 19540 KB Output is correct
23 Correct 60 ms 22612 KB Output is correct
24 Correct 89 ms 30464 KB Output is correct
25 Correct 64 ms 19920 KB Output is correct
26 Correct 66 ms 21072 KB Output is correct
27 Correct 57 ms 19284 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 8796 KB Output is correct
2 Correct 2 ms 8796 KB Output is correct
3 Correct 2 ms 8796 KB Output is correct
4 Correct 2 ms 8624 KB Output is correct
5 Correct 2 ms 8796 KB Output is correct
6 Correct 2 ms 8796 KB Output is correct
7 Correct 2 ms 8796 KB Output is correct
8 Correct 2 ms 8808 KB Output is correct
9 Correct 2 ms 8796 KB Output is correct
10 Correct 42 ms 19352 KB Output is correct
11 Correct 30 ms 19032 KB Output is correct
12 Correct 106 ms 36688 KB Output is correct
13 Correct 57 ms 19816 KB Output is correct
14 Correct 72 ms 21468 KB Output is correct
15 Correct 2 ms 8796 KB Output is correct
16 Correct 2 ms 8796 KB Output is correct
17 Correct 2 ms 8796 KB Output is correct
18 Correct 48 ms 23912 KB Output is correct
19 Correct 58 ms 27732 KB Output is correct
20 Correct 57 ms 23812 KB Output is correct
21 Correct 46 ms 15168 KB Output is correct
22 Correct 38 ms 14436 KB Output is correct
23 Correct 36 ms 17756 KB Output is correct
24 Correct 32 ms 16076 KB Output is correct
25 Correct 34 ms 23892 KB Output is correct
26 Correct 65 ms 18116 KB Output is correct
27 Correct 50 ms 17232 KB Output is correct
28 Correct 36 ms 17748 KB Output is correct
29 Correct 27 ms 16080 KB Output is correct
30 Correct 33 ms 23880 KB Output is correct
31 Correct 5 ms 9564 KB Output is correct
32 Correct 19 ms 11708 KB Output is correct
33 Correct 15 ms 11672 KB Output is correct
34 Correct 21 ms 11864 KB Output is correct
35 Correct 7 ms 10712 KB Output is correct
36 Correct 19 ms 13740 KB Output is correct
37 Correct 17 ms 16732 KB Output is correct
38 Correct 14 ms 11868 KB Output is correct
39 Correct 49 ms 19540 KB Output is correct
40 Correct 60 ms 22612 KB Output is correct
41 Correct 89 ms 30464 KB Output is correct
42 Correct 64 ms 19920 KB Output is correct
43 Correct 66 ms 21072 KB Output is correct
44 Correct 57 ms 19284 KB Output is correct
45 Correct 16 ms 12124 KB Output is correct
46 Correct 54 ms 20184 KB Output is correct
47 Correct 79 ms 23572 KB Output is correct
48 Correct 116 ms 32796 KB Output is correct
49 Correct 55 ms 19920 KB Output is correct
50 Correct 78 ms 21236 KB Output is correct
51 Correct 62 ms 19540 KB Output is correct