Submission #934274

# Submission time Handle Problem Language Result Execution time Memory
934274 2024-02-27T04:46:59 Z tamir1 Magic Tree (CEOI19_magictree) C++14
100 / 100
84 ms 29332 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;
void dfs(ll a){
	map<ll,ll> mp2;
	for(ll i:v[a]){
		dfs(i);
		if(mp2.size()<mp.size()) swap(mp2,mp);
		for(auto [p,q]:mp){
			mp2[p]+=q;
		}
	}
	if(day[a]>0){
		mp2[day[a]]+=x[a];
		while(true){
			auto it=mp2.upper_bound(day[a]);
			if(it==mp2.end()) break;
			if(it->second<=x[a]){
				x[a]-=it->second;
				mp2.erase(it);
				continue;
			}
			it->second-=x[a];
			break;
		}
	}
	swap(mp2,mp);
}
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(auto [a,b]:mp) ans+=b;
	cout << ans;
}

Compilation message

magictree.cpp: In function 'void dfs(long long int)':
magictree.cpp:12:12: warning: structured bindings only available with '-std=c++17' or '-std=gnu++17'
   12 |   for(auto [p,q]:mp){
      |            ^
magictree.cpp: In function 'int main()':
magictree.cpp:47:11: warning: structured bindings only available with '-std=c++17' or '-std=gnu++17'
   47 |  for(auto [a,b]:mp) ans+=b;
      |           ^
# Verdict Execution time Memory Grader output
1 Correct 1 ms 4700 KB Output is correct
2 Correct 1 ms 4524 KB Output is correct
3 Correct 1 ms 4700 KB Output is correct
4 Correct 1 ms 4700 KB Output is correct
5 Correct 1 ms 4700 KB Output is correct
6 Correct 1 ms 4696 KB Output is correct
7 Correct 2 ms 4700 KB Output is correct
8 Correct 1 ms 4700 KB Output is correct
9 Correct 1 ms 4700 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 35 ms 8796 KB Output is correct
2 Correct 28 ms 15964 KB Output is correct
3 Correct 77 ms 11088 KB Output is correct
4 Correct 47 ms 9408 KB Output is correct
5 Correct 60 ms 11744 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 4700 KB Output is correct
2 Correct 1 ms 4700 KB Output is correct
3 Correct 1 ms 4952 KB Output is correct
4 Correct 44 ms 25424 KB Output is correct
5 Correct 66 ms 29332 KB Output is correct
6 Correct 61 ms 25424 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 34 ms 7020 KB Output is correct
2 Correct 32 ms 7004 KB Output is correct
3 Correct 34 ms 14364 KB Output is correct
4 Correct 24 ms 5852 KB Output is correct
5 Correct 48 ms 25412 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 4700 KB Output is correct
2 Correct 1 ms 4524 KB Output is correct
3 Correct 1 ms 4700 KB Output is correct
4 Correct 1 ms 4700 KB Output is correct
5 Correct 1 ms 4700 KB Output is correct
6 Correct 1 ms 4696 KB Output is correct
7 Correct 2 ms 4700 KB Output is correct
8 Correct 1 ms 4700 KB Output is correct
9 Correct 1 ms 4700 KB Output is correct
10 Correct 41 ms 7004 KB Output is correct
11 Correct 46 ms 7000 KB Output is correct
12 Correct 47 ms 14420 KB Output is correct
13 Correct 23 ms 5848 KB Output is correct
14 Correct 40 ms 25424 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 4 ms 4956 KB Output is correct
2 Correct 15 ms 7004 KB Output is correct
3 Correct 15 ms 7072 KB Output is correct
4 Correct 15 ms 6876 KB Output is correct
5 Correct 7 ms 5852 KB Output is correct
6 Correct 16 ms 10332 KB Output is correct
7 Correct 20 ms 14552 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 4700 KB Output is correct
2 Correct 1 ms 4524 KB Output is correct
3 Correct 1 ms 4700 KB Output is correct
4 Correct 1 ms 4700 KB Output is correct
5 Correct 1 ms 4700 KB Output is correct
6 Correct 1 ms 4696 KB Output is correct
7 Correct 2 ms 4700 KB Output is correct
8 Correct 1 ms 4700 KB Output is correct
9 Correct 1 ms 4700 KB Output is correct
10 Correct 1 ms 4700 KB Output is correct
11 Correct 1 ms 4700 KB Output is correct
12 Correct 1 ms 4952 KB Output is correct
13 Correct 44 ms 25424 KB Output is correct
14 Correct 66 ms 29332 KB Output is correct
15 Correct 61 ms 25424 KB Output is correct
16 Correct 41 ms 7004 KB Output is correct
17 Correct 46 ms 7000 KB Output is correct
18 Correct 47 ms 14420 KB Output is correct
19 Correct 23 ms 5848 KB Output is correct
20 Correct 40 ms 25424 KB Output is correct
21 Correct 11 ms 5212 KB Output is correct
22 Correct 38 ms 7252 KB Output is correct
23 Correct 44 ms 9176 KB Output is correct
24 Correct 84 ms 10320 KB Output is correct
25 Correct 43 ms 9596 KB Output is correct
26 Correct 56 ms 14160 KB Output is correct
27 Correct 56 ms 15952 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 4700 KB Output is correct
2 Correct 1 ms 4524 KB Output is correct
3 Correct 1 ms 4700 KB Output is correct
4 Correct 1 ms 4700 KB Output is correct
5 Correct 1 ms 4700 KB Output is correct
6 Correct 1 ms 4696 KB Output is correct
7 Correct 2 ms 4700 KB Output is correct
8 Correct 1 ms 4700 KB Output is correct
9 Correct 1 ms 4700 KB Output is correct
10 Correct 35 ms 8796 KB Output is correct
11 Correct 28 ms 15964 KB Output is correct
12 Correct 77 ms 11088 KB Output is correct
13 Correct 47 ms 9408 KB Output is correct
14 Correct 60 ms 11744 KB Output is correct
15 Correct 1 ms 4700 KB Output is correct
16 Correct 1 ms 4700 KB Output is correct
17 Correct 1 ms 4952 KB Output is correct
18 Correct 44 ms 25424 KB Output is correct
19 Correct 66 ms 29332 KB Output is correct
20 Correct 61 ms 25424 KB Output is correct
21 Correct 34 ms 7020 KB Output is correct
22 Correct 32 ms 7004 KB Output is correct
23 Correct 34 ms 14364 KB Output is correct
24 Correct 24 ms 5852 KB Output is correct
25 Correct 48 ms 25412 KB Output is correct
26 Correct 41 ms 7004 KB Output is correct
27 Correct 46 ms 7000 KB Output is correct
28 Correct 47 ms 14420 KB Output is correct
29 Correct 23 ms 5848 KB Output is correct
30 Correct 40 ms 25424 KB Output is correct
31 Correct 4 ms 4956 KB Output is correct
32 Correct 15 ms 7004 KB Output is correct
33 Correct 15 ms 7072 KB Output is correct
34 Correct 15 ms 6876 KB Output is correct
35 Correct 7 ms 5852 KB Output is correct
36 Correct 16 ms 10332 KB Output is correct
37 Correct 20 ms 14552 KB Output is correct
38 Correct 11 ms 5212 KB Output is correct
39 Correct 38 ms 7252 KB Output is correct
40 Correct 44 ms 9176 KB Output is correct
41 Correct 84 ms 10320 KB Output is correct
42 Correct 43 ms 9596 KB Output is correct
43 Correct 56 ms 14160 KB Output is correct
44 Correct 56 ms 15952 KB Output is correct
45 Correct 13 ms 5208 KB Output is correct
46 Correct 41 ms 7260 KB Output is correct
47 Correct 50 ms 9048 KB Output is correct
48 Correct 76 ms 10576 KB Output is correct
49 Correct 46 ms 9416 KB Output is correct
50 Correct 62 ms 14420 KB Output is correct
51 Correct 66 ms 16332 KB Output is correct