답안 #228507

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
228507 2020-05-01T10:03:43 Z oolimry Magic Tree (CEOI19_magictree) C++14
100 / 100
172 ms 37752 KB
#include <bits/stdc++.h>
#define day first
#define value second
using namespace std;

typedef pair<int, long long> ii;
ii fruit[100005];
map<int, long long> dp[100005];
vector<int> adj[100005];

void dfs(int u){
	auto& cur = dp[u]; ///updating cur updates dp[u]
	
	for(int v : adj[u]){
		dfs(v);
		if(cur.size() < dp[v].size()) swap(cur, dp[v]);
		for(ii x : dp[v]) cur[x.day] += x.value;
	}
	
	ii F = fruit[u];
	if(fruit[u] == ii(0,0)) return;
	
	cur[F.day] += F.value;
	long long subtract = F.value;
	while(true){
		auto it = cur.find(F.day); it++;
		if(it == cur.end()) break;
		if(it->second > subtract){
			it->second -= subtract;
			break;
		}
		subtract -= it->second;
		dp[u].erase(it);
	}
}

int main(){
	ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
	
	int n, m, k; cin >> n >> m >> k;
	
	for(int i = 2;i <= n;i++){
		int p; cin >> p;
		adj[p].push_back(i);
	}
	
	while(m--){
		int u; cin >> u;
		cin >> fruit[u].day >> fruit[u].value;
	}
	
	dfs(1);
	long long ans = 0;
	for(ii x : dp[1]) ans += x.value;
	cout << ans;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 9 ms 7424 KB Output is correct
2 Correct 8 ms 7424 KB Output is correct
3 Correct 8 ms 7424 KB Output is correct
4 Correct 8 ms 7424 KB Output is correct
5 Correct 9 ms 7424 KB Output is correct
6 Correct 9 ms 7424 KB Output is correct
7 Correct 9 ms 7424 KB Output is correct
8 Correct 9 ms 7424 KB Output is correct
9 Correct 9 ms 7424 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 82 ms 19320 KB Output is correct
2 Correct 60 ms 19832 KB Output is correct
3 Correct 172 ms 37752 KB Output is correct
4 Correct 106 ms 20724 KB Output is correct
5 Correct 137 ms 22776 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 10 ms 7552 KB Output is correct
2 Correct 9 ms 7552 KB Output is correct
3 Correct 9 ms 7680 KB Output is correct
4 Correct 73 ms 28188 KB Output is correct
5 Correct 100 ms 31992 KB Output is correct
6 Correct 94 ms 28152 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 98 ms 16504 KB Output is correct
2 Correct 87 ms 15608 KB Output is correct
3 Correct 85 ms 20344 KB Output is correct
4 Correct 60 ms 16752 KB Output is correct
5 Correct 64 ms 28280 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 9 ms 7424 KB Output is correct
2 Correct 8 ms 7424 KB Output is correct
3 Correct 8 ms 7424 KB Output is correct
4 Correct 8 ms 7424 KB Output is correct
5 Correct 9 ms 7424 KB Output is correct
6 Correct 9 ms 7424 KB Output is correct
7 Correct 9 ms 7424 KB Output is correct
8 Correct 9 ms 7424 KB Output is correct
9 Correct 9 ms 7424 KB Output is correct
10 Correct 104 ms 18552 KB Output is correct
11 Correct 93 ms 17528 KB Output is correct
12 Correct 76 ms 19704 KB Output is correct
13 Correct 55 ms 16112 KB Output is correct
14 Correct 66 ms 27716 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 14 ms 8320 KB Output is correct
2 Correct 40 ms 11128 KB Output is correct
3 Correct 38 ms 11128 KB Output is correct
4 Correct 39 ms 11256 KB Output is correct
5 Correct 17 ms 9596 KB Output is correct
6 Correct 38 ms 13688 KB Output is correct
7 Correct 38 ms 17528 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 9 ms 7424 KB Output is correct
2 Correct 8 ms 7424 KB Output is correct
3 Correct 8 ms 7424 KB Output is correct
4 Correct 8 ms 7424 KB Output is correct
5 Correct 9 ms 7424 KB Output is correct
6 Correct 9 ms 7424 KB Output is correct
7 Correct 9 ms 7424 KB Output is correct
8 Correct 9 ms 7424 KB Output is correct
9 Correct 9 ms 7424 KB Output is correct
10 Correct 10 ms 7552 KB Output is correct
11 Correct 9 ms 7552 KB Output is correct
12 Correct 9 ms 7680 KB Output is correct
13 Correct 73 ms 28188 KB Output is correct
14 Correct 100 ms 31992 KB Output is correct
15 Correct 94 ms 28152 KB Output is correct
16 Correct 104 ms 18552 KB Output is correct
17 Correct 93 ms 17528 KB Output is correct
18 Correct 76 ms 19704 KB Output is correct
19 Correct 55 ms 16112 KB Output is correct
20 Correct 66 ms 27716 KB Output is correct
21 Correct 28 ms 10880 KB Output is correct
22 Correct 88 ms 19576 KB Output is correct
23 Correct 97 ms 22776 KB Output is correct
24 Correct 152 ms 31096 KB Output is correct
25 Correct 108 ms 19956 KB Output is correct
26 Correct 126 ms 22264 KB Output is correct
27 Correct 110 ms 21496 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 9 ms 7424 KB Output is correct
2 Correct 8 ms 7424 KB Output is correct
3 Correct 8 ms 7424 KB Output is correct
4 Correct 8 ms 7424 KB Output is correct
5 Correct 9 ms 7424 KB Output is correct
6 Correct 9 ms 7424 KB Output is correct
7 Correct 9 ms 7424 KB Output is correct
8 Correct 9 ms 7424 KB Output is correct
9 Correct 9 ms 7424 KB Output is correct
10 Correct 82 ms 19320 KB Output is correct
11 Correct 60 ms 19832 KB Output is correct
12 Correct 172 ms 37752 KB Output is correct
13 Correct 106 ms 20724 KB Output is correct
14 Correct 137 ms 22776 KB Output is correct
15 Correct 10 ms 7552 KB Output is correct
16 Correct 9 ms 7552 KB Output is correct
17 Correct 9 ms 7680 KB Output is correct
18 Correct 73 ms 28188 KB Output is correct
19 Correct 100 ms 31992 KB Output is correct
20 Correct 94 ms 28152 KB Output is correct
21 Correct 98 ms 16504 KB Output is correct
22 Correct 87 ms 15608 KB Output is correct
23 Correct 85 ms 20344 KB Output is correct
24 Correct 60 ms 16752 KB Output is correct
25 Correct 64 ms 28280 KB Output is correct
26 Correct 104 ms 18552 KB Output is correct
27 Correct 93 ms 17528 KB Output is correct
28 Correct 76 ms 19704 KB Output is correct
29 Correct 55 ms 16112 KB Output is correct
30 Correct 66 ms 27716 KB Output is correct
31 Correct 14 ms 8320 KB Output is correct
32 Correct 40 ms 11128 KB Output is correct
33 Correct 38 ms 11128 KB Output is correct
34 Correct 39 ms 11256 KB Output is correct
35 Correct 17 ms 9596 KB Output is correct
36 Correct 38 ms 13688 KB Output is correct
37 Correct 38 ms 17528 KB Output is correct
38 Correct 28 ms 10880 KB Output is correct
39 Correct 88 ms 19576 KB Output is correct
40 Correct 97 ms 22776 KB Output is correct
41 Correct 152 ms 31096 KB Output is correct
42 Correct 108 ms 19956 KB Output is correct
43 Correct 126 ms 22264 KB Output is correct
44 Correct 110 ms 21496 KB Output is correct
45 Correct 31 ms 11392 KB Output is correct
46 Correct 90 ms 20600 KB Output is correct
47 Correct 111 ms 24184 KB Output is correct
48 Correct 161 ms 34172 KB Output is correct
49 Correct 108 ms 20852 KB Output is correct
50 Correct 136 ms 23416 KB Output is correct
51 Correct 120 ms 22392 KB Output is correct