답안 #680219

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
680219 2023-01-10T09:30:59 Z flappybird Magic Tree (CEOI19_magictree) C++17
100 / 100
125 ms 34612 KB
#include <bits/stdc++.h>
#include <cassert>
#pragma GCC optimize("O3")
#pragma GCC optimize("Ofast")
#pragma GCC optimize("unroll-loops")
#pragma GCC target("avx,avx2,fma")
using namespace std;
typedef long long ll;
typedef pair<ll, ll> pll;
typedef pair<int, int> pii;
#define MAX 101010
#define MAXS 20
#define INF 1000000000000000001
#define bb ' '
#define ln '\n'
#define Ln '\n'
#define rev(x) ((x<N*2)?(x+N*2):(x-N*2))
#ifdef _MSC_VER
#  include <intrin.h>
#  define __builtin_popcount __popcnt
#endif
map<int, ll> mp[MAX];
vector<int> adj[MAX];
int D[MAX];
int W[MAX];
void dfs(int x) {
	for (auto v : adj[x]) {
		dfs(v);
		if (mp[v].size() > mp[x].size()) swap(mp[v], mp[x]);
		for (auto& [t, val] : mp[v]) mp[x][t] += val;
	}
	if (D[x]) {
		mp[x][D[x]] += W[x];
		ll sum = W[x];
		while (sum) {
			auto it = mp[x].upper_bound(D[x]);
			if (it == mp[x].end()) break;
			ll val = it->second;
			ll m = min(sum, val);
			it->second -= m;
			sum -= m;
			if (!it->second) mp[x].erase(it);
		}
	}
}
signed main() {
	ios::sync_with_stdio(false), cin.tie(0);
	int N, M, K;
	cin >> N >> M >> K;
	int i, p, a, b;
	for (i = 2; i <= N; i++) cin >> p, adj[p].push_back(i);
	while (M--) {
		cin >> p >> a >> b;
		D[p] = a;
		W[p] = b;
	}
	dfs(1);
	ll ans = 0;
	for (auto& [_, v] : mp[1]) ans += v;
	cout << ans << ln;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 7380 KB Output is correct
2 Correct 3 ms 7380 KB Output is correct
3 Correct 4 ms 7380 KB Output is correct
4 Correct 4 ms 7380 KB Output is correct
5 Correct 4 ms 7380 KB Output is correct
6 Correct 4 ms 7380 KB Output is correct
7 Correct 4 ms 7440 KB Output is correct
8 Correct 4 ms 7440 KB Output is correct
9 Correct 4 ms 7380 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 58 ms 17440 KB Output is correct
2 Correct 39 ms 17380 KB Output is correct
3 Correct 125 ms 34612 KB Output is correct
4 Correct 70 ms 17844 KB Output is correct
5 Correct 103 ms 19332 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 7588 KB Output is correct
2 Correct 4 ms 7576 KB Output is correct
3 Correct 4 ms 7584 KB Output is correct
4 Correct 44 ms 24236 KB Output is correct
5 Correct 76 ms 28100 KB Output is correct
6 Correct 57 ms 24144 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 58 ms 13516 KB Output is correct
2 Correct 63 ms 14828 KB Output is correct
3 Correct 52 ms 18328 KB Output is correct
4 Correct 38 ms 15912 KB Output is correct
5 Correct 49 ms 24424 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 7380 KB Output is correct
2 Correct 3 ms 7380 KB Output is correct
3 Correct 4 ms 7380 KB Output is correct
4 Correct 4 ms 7380 KB Output is correct
5 Correct 4 ms 7380 KB Output is correct
6 Correct 4 ms 7380 KB Output is correct
7 Correct 4 ms 7440 KB Output is correct
8 Correct 4 ms 7440 KB Output is correct
9 Correct 4 ms 7380 KB Output is correct
10 Correct 73 ms 17760 KB Output is correct
11 Correct 61 ms 16712 KB Output is correct
12 Correct 45 ms 17612 KB Output is correct
13 Correct 34 ms 15308 KB Output is correct
14 Correct 42 ms 23800 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 7 ms 8020 KB Output is correct
2 Correct 26 ms 10528 KB Output is correct
3 Correct 24 ms 10508 KB Output is correct
4 Correct 25 ms 10572 KB Output is correct
5 Correct 10 ms 8968 KB Output is correct
6 Correct 24 ms 12432 KB Output is correct
7 Correct 27 ms 15656 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 7380 KB Output is correct
2 Correct 3 ms 7380 KB Output is correct
3 Correct 4 ms 7380 KB Output is correct
4 Correct 4 ms 7380 KB Output is correct
5 Correct 4 ms 7380 KB Output is correct
6 Correct 4 ms 7380 KB Output is correct
7 Correct 4 ms 7440 KB Output is correct
8 Correct 4 ms 7440 KB Output is correct
9 Correct 4 ms 7380 KB Output is correct
10 Correct 4 ms 7588 KB Output is correct
11 Correct 4 ms 7576 KB Output is correct
12 Correct 4 ms 7584 KB Output is correct
13 Correct 44 ms 24236 KB Output is correct
14 Correct 76 ms 28100 KB Output is correct
15 Correct 57 ms 24144 KB Output is correct
16 Correct 73 ms 17760 KB Output is correct
17 Correct 61 ms 16712 KB Output is correct
18 Correct 45 ms 17612 KB Output is correct
19 Correct 34 ms 15308 KB Output is correct
20 Correct 42 ms 23800 KB Output is correct
21 Correct 19 ms 10720 KB Output is correct
22 Correct 63 ms 18780 KB Output is correct
23 Correct 70 ms 21988 KB Output is correct
24 Correct 110 ms 30416 KB Output is correct
25 Correct 71 ms 19488 KB Output is correct
26 Correct 85 ms 20812 KB Output is correct
27 Correct 72 ms 19576 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 7380 KB Output is correct
2 Correct 3 ms 7380 KB Output is correct
3 Correct 4 ms 7380 KB Output is correct
4 Correct 4 ms 7380 KB Output is correct
5 Correct 4 ms 7380 KB Output is correct
6 Correct 4 ms 7380 KB Output is correct
7 Correct 4 ms 7440 KB Output is correct
8 Correct 4 ms 7440 KB Output is correct
9 Correct 4 ms 7380 KB Output is correct
10 Correct 58 ms 17440 KB Output is correct
11 Correct 39 ms 17380 KB Output is correct
12 Correct 125 ms 34612 KB Output is correct
13 Correct 70 ms 17844 KB Output is correct
14 Correct 103 ms 19332 KB Output is correct
15 Correct 4 ms 7588 KB Output is correct
16 Correct 4 ms 7576 KB Output is correct
17 Correct 4 ms 7584 KB Output is correct
18 Correct 44 ms 24236 KB Output is correct
19 Correct 76 ms 28100 KB Output is correct
20 Correct 57 ms 24144 KB Output is correct
21 Correct 58 ms 13516 KB Output is correct
22 Correct 63 ms 14828 KB Output is correct
23 Correct 52 ms 18328 KB Output is correct
24 Correct 38 ms 15912 KB Output is correct
25 Correct 49 ms 24424 KB Output is correct
26 Correct 73 ms 17760 KB Output is correct
27 Correct 61 ms 16712 KB Output is correct
28 Correct 45 ms 17612 KB Output is correct
29 Correct 34 ms 15308 KB Output is correct
30 Correct 42 ms 23800 KB Output is correct
31 Correct 7 ms 8020 KB Output is correct
32 Correct 26 ms 10528 KB Output is correct
33 Correct 24 ms 10508 KB Output is correct
34 Correct 25 ms 10572 KB Output is correct
35 Correct 10 ms 8968 KB Output is correct
36 Correct 24 ms 12432 KB Output is correct
37 Correct 27 ms 15656 KB Output is correct
38 Correct 19 ms 10720 KB Output is correct
39 Correct 63 ms 18780 KB Output is correct
40 Correct 70 ms 21988 KB Output is correct
41 Correct 110 ms 30416 KB Output is correct
42 Correct 71 ms 19488 KB Output is correct
43 Correct 85 ms 20812 KB Output is correct
44 Correct 72 ms 19576 KB Output is correct
45 Correct 22 ms 11216 KB Output is correct
46 Correct 71 ms 19836 KB Output is correct
47 Correct 84 ms 23348 KB Output is correct
48 Correct 125 ms 33376 KB Output is correct
49 Correct 69 ms 20128 KB Output is correct
50 Correct 98 ms 21812 KB Output is correct
51 Correct 78 ms 20404 KB Output is correct