답안 #654103

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
654103 2022-10-30T00:08:00 Z dutinmeow Magic Tree (CEOI19_magictree) C++17
100 / 100
247 ms 40220 KB
#include <bits/stdc++.h>

int main() {
	using namespace std;

	int N, M, K;
	cin >> N >> M >> K;
	vector<int> P(N + 1);
	for (int i = 2; i <= N; i++) 
		cin >> P[i];
	vector<int> D(N + 1, -1);
	vector<long long> W(N + 1);
	for (int i = 0; i < M; i++) {
		int u, d;
		long long w;
		cin >> u >> d >> w;
		tie(D[u], W[u]) = make_pair(d, w);
	}

	vector<map<int, long long>> A(N + 1);
	for (int i = N; i > 1; i--) {
		if (D[i] != -1) {
			auto it = A[i].emplace(D[i], 0).first;
			it->second += W[i];
			for (it = next(it); 
				it != A[i].end() && W[i] >= it->second; 
				W[i] -= it->second, it = A[i].erase(it)
			);
			if (it != A[i].end())
				it->second -= W[i];
		}
		if (A[i].size() > A[P[i]].size())
			swap(A[i], A[P[i]]);
		for (auto [k, v] : A[i])
			A[P[i]][k] += v;
	}	
	long long ans = 0;
	for (auto [k, v] : A[1])
		ans += v;
	cout << ans << '\n';
}
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 1 ms 296 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Correct 0 ms 212 KB Output is correct
7 Correct 0 ms 212 KB Output is correct
8 Correct 1 ms 212 KB Output is correct
9 Correct 1 ms 212 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 77 ms 17252 KB Output is correct
2 Correct 59 ms 10672 KB Output is correct
3 Correct 247 ms 40220 KB Output is correct
4 Correct 140 ms 18032 KB Output is correct
5 Correct 172 ms 23220 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 340 KB Output is correct
2 Correct 1 ms 340 KB Output is correct
3 Correct 1 ms 340 KB Output is correct
4 Correct 106 ms 8368 KB Output is correct
5 Correct 119 ms 12448 KB Output is correct
6 Correct 119 ms 8612 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 112 ms 12448 KB Output is correct
2 Correct 108 ms 11580 KB Output is correct
3 Correct 122 ms 9896 KB Output is correct
4 Correct 107 ms 13992 KB Output is correct
5 Correct 97 ms 8616 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 1 ms 296 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Correct 0 ms 212 KB Output is correct
7 Correct 0 ms 212 KB Output is correct
8 Correct 1 ms 212 KB Output is correct
9 Correct 1 ms 212 KB Output is correct
10 Correct 114 ms 15484 KB Output is correct
11 Correct 137 ms 14136 KB Output is correct
12 Correct 95 ms 9364 KB Output is correct
13 Correct 77 ms 13236 KB Output is correct
14 Correct 88 ms 7960 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 7 ms 1876 KB Output is correct
2 Correct 32 ms 7320 KB Output is correct
3 Correct 33 ms 7280 KB Output is correct
4 Correct 32 ms 7332 KB Output is correct
5 Correct 18 ms 6808 KB Output is correct
6 Correct 31 ms 7120 KB Output is correct
7 Correct 31 ms 7160 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 1 ms 296 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Correct 0 ms 212 KB Output is correct
7 Correct 0 ms 212 KB Output is correct
8 Correct 1 ms 212 KB Output is correct
9 Correct 1 ms 212 KB Output is correct
10 Correct 1 ms 340 KB Output is correct
11 Correct 1 ms 340 KB Output is correct
12 Correct 1 ms 340 KB Output is correct
13 Correct 106 ms 8368 KB Output is correct
14 Correct 119 ms 12448 KB Output is correct
15 Correct 119 ms 8612 KB Output is correct
16 Correct 114 ms 15484 KB Output is correct
17 Correct 137 ms 14136 KB Output is correct
18 Correct 95 ms 9364 KB Output is correct
19 Correct 77 ms 13236 KB Output is correct
20 Correct 88 ms 7960 KB Output is correct
21 Correct 25 ms 5024 KB Output is correct
22 Correct 89 ms 17180 KB Output is correct
23 Correct 110 ms 20836 KB Output is correct
24 Correct 169 ms 31460 KB Output is correct
25 Correct 122 ms 17208 KB Output is correct
26 Correct 153 ms 17636 KB Output is correct
27 Correct 120 ms 11164 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 1 ms 296 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Correct 0 ms 212 KB Output is correct
7 Correct 0 ms 212 KB Output is correct
8 Correct 1 ms 212 KB Output is correct
9 Correct 1 ms 212 KB Output is correct
10 Correct 77 ms 17252 KB Output is correct
11 Correct 59 ms 10672 KB Output is correct
12 Correct 247 ms 40220 KB Output is correct
13 Correct 140 ms 18032 KB Output is correct
14 Correct 172 ms 23220 KB Output is correct
15 Correct 1 ms 340 KB Output is correct
16 Correct 1 ms 340 KB Output is correct
17 Correct 1 ms 340 KB Output is correct
18 Correct 106 ms 8368 KB Output is correct
19 Correct 119 ms 12448 KB Output is correct
20 Correct 119 ms 8612 KB Output is correct
21 Correct 112 ms 12448 KB Output is correct
22 Correct 108 ms 11580 KB Output is correct
23 Correct 122 ms 9896 KB Output is correct
24 Correct 107 ms 13992 KB Output is correct
25 Correct 97 ms 8616 KB Output is correct
26 Correct 114 ms 15484 KB Output is correct
27 Correct 137 ms 14136 KB Output is correct
28 Correct 95 ms 9364 KB Output is correct
29 Correct 77 ms 13236 KB Output is correct
30 Correct 88 ms 7960 KB Output is correct
31 Correct 7 ms 1876 KB Output is correct
32 Correct 32 ms 7320 KB Output is correct
33 Correct 33 ms 7280 KB Output is correct
34 Correct 32 ms 7332 KB Output is correct
35 Correct 18 ms 6808 KB Output is correct
36 Correct 31 ms 7120 KB Output is correct
37 Correct 31 ms 7160 KB Output is correct
38 Correct 25 ms 5024 KB Output is correct
39 Correct 89 ms 17180 KB Output is correct
40 Correct 110 ms 20836 KB Output is correct
41 Correct 169 ms 31460 KB Output is correct
42 Correct 122 ms 17208 KB Output is correct
43 Correct 153 ms 17636 KB Output is correct
44 Correct 120 ms 11164 KB Output is correct
45 Correct 31 ms 5532 KB Output is correct
46 Correct 103 ms 18460 KB Output is correct
47 Correct 132 ms 22520 KB Output is correct
48 Correct 204 ms 34764 KB Output is correct
49 Correct 145 ms 18000 KB Output is correct
50 Correct 191 ms 18508 KB Output is correct
51 Correct 150 ms 12108 KB Output is correct