답안 #932915

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
932915 2024-02-24T13:58:04 Z beepbeepsheep Magic Tree (CEOI19_magictree) C++17
100 / 100
141 ms 45036 KB
#include <bits/stdc++.h>
using namespace std;

#define ll long long
#define ii pair<ll,ll>

const ll maxn=1e5+5;
const ll inf=1e15; 

vector<ll> adj[maxn];
multiset<ii> s[maxn];
ii arr[maxn];

void dfs(ll x){
	for (auto u:adj[x]){
		dfs(u);
		if (s[u].size()>s[x].size()) swap(s[u],s[x]);
		for (auto [a,b]:s[u]) s[x].emplace(a,b);
	}
	ll pos,cnt;
	tie(pos,cnt)=arr[x];
	while (cnt){
		ll p,c;
		if (s[x].lower_bound(make_pair(pos,inf))==s[x].end()) break;
		tie(p,c)=*s[x].lower_bound(make_pair(pos,inf));
		if (cnt>=c){
			cnt-=c;
			s[x].erase(s[x].find(make_pair(p,c)));
		} else{
			s[x].erase(s[x].find(make_pair(p,c)));
			c-=cnt;
			cnt=0;
			s[x].emplace(p,c);
		}
	}
	s[x].emplace(arr[x]);

}
int main(){
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	ll n,k,m,a,b,c;
	cin>>n>>k>>m;
	for (int i=2;i<=n;i++){
		cin>>a;
		adj[a].emplace_back(i);
	}
	for (int i=1;i<=k;i++){
		cin>>a>>b>>c; //pos, time, value
		arr[a]={b,c};
	}
	dfs(1);
	ll ans=0;
	for (auto [u,v]:s[1]) ans+=v;
	cout<<ans; 
	return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 8796 KB Output is correct
2 Correct 2 ms 8796 KB Output is correct
3 Correct 2 ms 8792 KB Output is correct
4 Correct 2 ms 8796 KB Output is correct
5 Correct 2 ms 8796 KB Output is correct
6 Correct 2 ms 8796 KB Output is correct
7 Correct 3 ms 8796 KB Output is correct
8 Correct 2 ms 8796 KB Output is correct
9 Correct 2 ms 8796 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 97 ms 43112 KB Output is correct
2 Correct 56 ms 28136 KB Output is correct
3 Correct 115 ms 41004 KB Output is correct
4 Correct 79 ms 22240 KB Output is correct
5 Correct 125 ms 23588 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 9052 KB Output is correct
2 Correct 3 ms 9052 KB Output is correct
3 Correct 3 ms 9052 KB Output is correct
4 Correct 41 ms 29584 KB Output is correct
5 Correct 83 ms 36032 KB Output is correct
6 Correct 60 ms 29788 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 114 ms 37660 KB Output is correct
2 Correct 141 ms 45036 KB Output is correct
3 Correct 71 ms 26708 KB Output is correct
4 Correct 65 ms 24080 KB Output is correct
5 Correct 67 ms 33360 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 8796 KB Output is correct
2 Correct 2 ms 8796 KB Output is correct
3 Correct 2 ms 8792 KB Output is correct
4 Correct 2 ms 8796 KB Output is correct
5 Correct 2 ms 8796 KB Output is correct
6 Correct 2 ms 8796 KB Output is correct
7 Correct 3 ms 8796 KB Output is correct
8 Correct 2 ms 8796 KB Output is correct
9 Correct 2 ms 8796 KB Output is correct
10 Correct 91 ms 36000 KB Output is correct
11 Correct 93 ms 36688 KB Output is correct
12 Correct 59 ms 23376 KB Output is correct
13 Correct 50 ms 23244 KB Output is correct
14 Correct 69 ms 30268 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 14 ms 15196 KB Output is correct
2 Correct 92 ms 43220 KB Output is correct
3 Correct 103 ms 42576 KB Output is correct
4 Correct 92 ms 41856 KB Output is correct
5 Correct 28 ms 22232 KB Output is correct
6 Correct 59 ms 26984 KB Output is correct
7 Correct 43 ms 28252 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 8796 KB Output is correct
2 Correct 2 ms 8796 KB Output is correct
3 Correct 2 ms 8792 KB Output is correct
4 Correct 2 ms 8796 KB Output is correct
5 Correct 2 ms 8796 KB Output is correct
6 Correct 2 ms 8796 KB Output is correct
7 Correct 3 ms 8796 KB Output is correct
8 Correct 2 ms 8796 KB Output is correct
9 Correct 2 ms 8796 KB Output is correct
10 Correct 3 ms 9052 KB Output is correct
11 Correct 3 ms 9052 KB Output is correct
12 Correct 3 ms 9052 KB Output is correct
13 Correct 41 ms 29584 KB Output is correct
14 Correct 83 ms 36032 KB Output is correct
15 Correct 60 ms 29788 KB Output is correct
16 Correct 91 ms 36000 KB Output is correct
17 Correct 93 ms 36688 KB Output is correct
18 Correct 59 ms 23376 KB Output is correct
19 Correct 50 ms 23244 KB Output is correct
20 Correct 69 ms 30268 KB Output is correct
21 Correct 15 ms 13656 KB Output is correct
22 Correct 117 ms 40856 KB Output is correct
23 Correct 100 ms 40784 KB Output is correct
24 Correct 109 ms 35784 KB Output is correct
25 Correct 77 ms 23708 KB Output is correct
26 Correct 87 ms 25236 KB Output is correct
27 Correct 69 ms 23380 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 8796 KB Output is correct
2 Correct 2 ms 8796 KB Output is correct
3 Correct 2 ms 8792 KB Output is correct
4 Correct 2 ms 8796 KB Output is correct
5 Correct 2 ms 8796 KB Output is correct
6 Correct 2 ms 8796 KB Output is correct
7 Correct 3 ms 8796 KB Output is correct
8 Correct 2 ms 8796 KB Output is correct
9 Correct 2 ms 8796 KB Output is correct
10 Correct 97 ms 43112 KB Output is correct
11 Correct 56 ms 28136 KB Output is correct
12 Correct 115 ms 41004 KB Output is correct
13 Correct 79 ms 22240 KB Output is correct
14 Correct 125 ms 23588 KB Output is correct
15 Correct 3 ms 9052 KB Output is correct
16 Correct 3 ms 9052 KB Output is correct
17 Correct 3 ms 9052 KB Output is correct
18 Correct 41 ms 29584 KB Output is correct
19 Correct 83 ms 36032 KB Output is correct
20 Correct 60 ms 29788 KB Output is correct
21 Correct 114 ms 37660 KB Output is correct
22 Correct 141 ms 45036 KB Output is correct
23 Correct 71 ms 26708 KB Output is correct
24 Correct 65 ms 24080 KB Output is correct
25 Correct 67 ms 33360 KB Output is correct
26 Correct 91 ms 36000 KB Output is correct
27 Correct 93 ms 36688 KB Output is correct
28 Correct 59 ms 23376 KB Output is correct
29 Correct 50 ms 23244 KB Output is correct
30 Correct 69 ms 30268 KB Output is correct
31 Correct 14 ms 15196 KB Output is correct
32 Correct 92 ms 43220 KB Output is correct
33 Correct 103 ms 42576 KB Output is correct
34 Correct 92 ms 41856 KB Output is correct
35 Correct 28 ms 22232 KB Output is correct
36 Correct 59 ms 26984 KB Output is correct
37 Correct 43 ms 28252 KB Output is correct
38 Correct 15 ms 13656 KB Output is correct
39 Correct 117 ms 40856 KB Output is correct
40 Correct 100 ms 40784 KB Output is correct
41 Correct 109 ms 35784 KB Output is correct
42 Correct 77 ms 23708 KB Output is correct
43 Correct 87 ms 25236 KB Output is correct
44 Correct 69 ms 23380 KB Output is correct
45 Correct 24 ms 14236 KB Output is correct
46 Correct 122 ms 42716 KB Output is correct
47 Correct 108 ms 41772 KB Output is correct
48 Correct 109 ms 39168 KB Output is correct
49 Correct 69 ms 24464 KB Output is correct
50 Correct 102 ms 26192 KB Output is correct
51 Correct 112 ms 24456 KB Output is correct