답안 #885270

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
885270 2023-12-09T11:51:26 Z 42kangaroo 참나무 (IOI23_beechtree) C++17
22 / 100
181 ms 151808 KB
//  D. Beech Tree

#include<bits/stdc++.h>
#include "beechtree.h"

using namespace std;

using g_t = vector<vector<int>>;
using dVal = tuple<map<int, int>, list<set<pair<int, int>>>, int>;

dVal dfs(int n, g_t &g, vector<bool> &po, vector<int> &c) {
	map<int, int> r;
	map<int, vector<pair<int, int>>> ve;
	list<set<pair<int, int>>> se;
	int seSi = 0;
	for (auto e: g[n]) {
		if (r.find(c[e]) != r.end()) po[n] = false;
		r[c[e]] = 1;
		ve[c[e]] = {};
	}
	for (auto e: g[n]) {
		auto [re, li, si] = dfs(e, g, po, c);
		if (!po[e]) {
			po[n] = false;
		}
		if (po[n]) {
			for (auto &[co, d]: re) {
				if (r.find(co) == r.end()) {
					po[n] = false;
					break;
				}
				if (co == c[e]) r[c[e]] = d + 1;
				ve[co].emplace_back(d, e);
			}
			if (po[n]) {
				if (si > seSi) {
					swap(se, li);
					swap(si, seSi);
				}
				auto itS = se.begin();
				for (auto &it: li) {
					assert(!it.empty() && !itS->empty());
					while (itS != se.end() && itS->size() <= it.size()) {
						for (auto cos: *itS) {
							if (it.erase(cos) == 0) {
								po[n] = false;
								break;
							}
						}
						if (!po[n]) break;
						itS++;
					}
					if (po[n]) {
						if (!it.empty()) {
							auto act = itS;
							itS = se.insert(itS, set<pair<int, int>>());
							for (auto cos: it) {
								if (act->erase(cos) == 0) {
									po[n] = false;
									break;
								}
								assert(itS->insert(cos).second);
							}
						}
					}
				}
			}
		}
	}
	if (!po[n]) return {};
	se.emplace_back();
	for (auto &[co, vec]: ve) {
		bool dD = true;
		for (auto [d, e]: vec) {
			if (d > r[co]) {
				po[n] = false;
				return {};
			} else if (d == r[co]) {
				dD = false;
				break;
			}
		}
		if (dD) {
			se.back().insert({co, r[co]});
			seSi++;
		}
	}
	if (se.back().empty()) se.pop_back();
	return {std::move(r), std::move(se), seSi};
}

vector<int> beechtree(int N, int M, vector<int> P, vector<int> C) {
	g_t g(N);
	for (int i = 1; i < N; ++i) {
		g[P[i]].push_back(i);
	}
	vector<bool> po(N, true);
	dfs(0, g, po, C);
	return {po.begin(), po.end()};
}

# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 1 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 1 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 0 ms 432 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 1 ms 348 KB Output is correct
12 Correct 0 ms 344 KB Output is correct
13 Correct 0 ms 348 KB Output is correct
14 Correct 0 ms 348 KB Output is correct
15 Correct 1 ms 344 KB Output is correct
16 Correct 0 ms 348 KB Output is correct
17 Correct 0 ms 344 KB Output is correct
18 Correct 1 ms 604 KB Output is correct
19 Correct 0 ms 348 KB Output is correct
20 Correct 0 ms 348 KB Output is correct
21 Correct 1 ms 348 KB Output is correct
22 Correct 0 ms 348 KB Output is correct
23 Correct 0 ms 436 KB Output is correct
24 Correct 0 ms 436 KB Output is correct
25 Correct 0 ms 344 KB Output is correct
26 Correct 0 ms 348 KB Output is correct
27 Correct 0 ms 348 KB Output is correct
28 Correct 0 ms 344 KB Output is correct
29 Correct 0 ms 360 KB Output is correct
30 Correct 0 ms 552 KB Output is correct
31 Correct 0 ms 348 KB Output is correct
32 Correct 0 ms 348 KB Output is correct
33 Correct 0 ms 436 KB Output is correct
34 Correct 0 ms 432 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 1 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 1 ms 348 KB Output is correct
7 Correct 169 ms 151636 KB Output is correct
8 Correct 171 ms 151636 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 1 ms 348 KB Output is correct
11 Correct 0 ms 348 KB Output is correct
12 Correct 0 ms 348 KB Output is correct
13 Correct 2 ms 1884 KB Output is correct
14 Correct 2 ms 1884 KB Output is correct
15 Correct 2 ms 1884 KB Output is correct
16 Correct 2 ms 1884 KB Output is correct
17 Correct 181 ms 151304 KB Output is correct
18 Correct 176 ms 151376 KB Output is correct
19 Correct 177 ms 151808 KB Output is correct
20 Correct 169 ms 151676 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 344 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 360 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 1 ms 436 KB Output is correct
8 Correct 1 ms 348 KB Output is correct
9 Runtime error 1 ms 600 KB Execution killed with signal 6
10 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 169 ms 151636 KB Output is correct
6 Correct 171 ms 151636 KB Output is correct
7 Correct 1 ms 344 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 1 ms 604 KB Output is correct
10 Correct 1 ms 348 KB Output is correct
11 Correct 96 ms 23520 KB Output is correct
12 Correct 156 ms 14164 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 1 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 1 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 1 ms 348 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 0 ms 348 KB Output is correct
12 Correct 0 ms 432 KB Output is correct
13 Correct 0 ms 348 KB Output is correct
14 Correct 1 ms 348 KB Output is correct
15 Correct 0 ms 344 KB Output is correct
16 Correct 0 ms 348 KB Output is correct
17 Correct 0 ms 348 KB Output is correct
18 Correct 1 ms 344 KB Output is correct
19 Correct 0 ms 348 KB Output is correct
20 Correct 0 ms 344 KB Output is correct
21 Correct 1 ms 604 KB Output is correct
22 Correct 0 ms 348 KB Output is correct
23 Correct 0 ms 348 KB Output is correct
24 Correct 1 ms 348 KB Output is correct
25 Correct 0 ms 348 KB Output is correct
26 Correct 0 ms 436 KB Output is correct
27 Correct 0 ms 436 KB Output is correct
28 Correct 0 ms 344 KB Output is correct
29 Correct 0 ms 348 KB Output is correct
30 Correct 0 ms 348 KB Output is correct
31 Correct 0 ms 344 KB Output is correct
32 Correct 0 ms 360 KB Output is correct
33 Correct 0 ms 552 KB Output is correct
34 Correct 0 ms 348 KB Output is correct
35 Correct 0 ms 348 KB Output is correct
36 Correct 0 ms 436 KB Output is correct
37 Correct 0 ms 432 KB Output is correct
38 Correct 0 ms 348 KB Output is correct
39 Correct 1 ms 348 KB Output is correct
40 Correct 0 ms 348 KB Output is correct
41 Correct 0 ms 348 KB Output is correct
42 Correct 1 ms 344 KB Output is correct
43 Correct 0 ms 348 KB Output is correct
44 Correct 0 ms 348 KB Output is correct
45 Correct 0 ms 348 KB Output is correct
46 Correct 0 ms 360 KB Output is correct
47 Correct 0 ms 348 KB Output is correct
48 Correct 1 ms 436 KB Output is correct
49 Correct 1 ms 348 KB Output is correct
50 Runtime error 1 ms 600 KB Execution killed with signal 6
51 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 432 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 1 ms 348 KB Output is correct
8 Correct 0 ms 344 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 1 ms 344 KB Output is correct
12 Correct 0 ms 348 KB Output is correct
13 Correct 0 ms 344 KB Output is correct
14 Correct 1 ms 604 KB Output is correct
15 Correct 0 ms 348 KB Output is correct
16 Correct 0 ms 348 KB Output is correct
17 Correct 1 ms 348 KB Output is correct
18 Correct 0 ms 348 KB Output is correct
19 Correct 0 ms 436 KB Output is correct
20 Correct 0 ms 436 KB Output is correct
21 Correct 0 ms 344 KB Output is correct
22 Correct 0 ms 348 KB Output is correct
23 Correct 0 ms 348 KB Output is correct
24 Correct 0 ms 344 KB Output is correct
25 Correct 2 ms 1896 KB Output is correct
26 Correct 2 ms 1896 KB Output is correct
27 Correct 2 ms 1896 KB Output is correct
28 Correct 2 ms 1892 KB Output is correct
29 Correct 2 ms 1896 KB Output is correct
30 Correct 1 ms 616 KB Output is correct
31 Incorrect 1 ms 460 KB 2nd lines differ - on the 1st token, expected: '1', found: '0'
32 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 1 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 1 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 1 ms 348 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 0 ms 348 KB Output is correct
12 Correct 0 ms 432 KB Output is correct
13 Correct 0 ms 348 KB Output is correct
14 Correct 1 ms 348 KB Output is correct
15 Correct 0 ms 344 KB Output is correct
16 Correct 0 ms 348 KB Output is correct
17 Correct 0 ms 348 KB Output is correct
18 Correct 1 ms 344 KB Output is correct
19 Correct 0 ms 348 KB Output is correct
20 Correct 0 ms 344 KB Output is correct
21 Correct 1 ms 604 KB Output is correct
22 Correct 0 ms 348 KB Output is correct
23 Correct 0 ms 348 KB Output is correct
24 Correct 1 ms 348 KB Output is correct
25 Correct 0 ms 348 KB Output is correct
26 Correct 0 ms 436 KB Output is correct
27 Correct 0 ms 436 KB Output is correct
28 Correct 0 ms 344 KB Output is correct
29 Correct 0 ms 348 KB Output is correct
30 Correct 0 ms 348 KB Output is correct
31 Correct 0 ms 344 KB Output is correct
32 Correct 0 ms 360 KB Output is correct
33 Correct 0 ms 552 KB Output is correct
34 Correct 0 ms 348 KB Output is correct
35 Correct 0 ms 348 KB Output is correct
36 Correct 0 ms 436 KB Output is correct
37 Correct 0 ms 432 KB Output is correct
38 Correct 0 ms 348 KB Output is correct
39 Correct 1 ms 348 KB Output is correct
40 Correct 0 ms 348 KB Output is correct
41 Correct 0 ms 348 KB Output is correct
42 Correct 2 ms 1884 KB Output is correct
43 Correct 2 ms 1884 KB Output is correct
44 Correct 2 ms 1884 KB Output is correct
45 Correct 2 ms 1884 KB Output is correct
46 Correct 1 ms 344 KB Output is correct
47 Correct 0 ms 348 KB Output is correct
48 Correct 0 ms 348 KB Output is correct
49 Correct 0 ms 348 KB Output is correct
50 Correct 0 ms 360 KB Output is correct
51 Correct 0 ms 348 KB Output is correct
52 Correct 1 ms 436 KB Output is correct
53 Correct 1 ms 348 KB Output is correct
54 Runtime error 1 ms 600 KB Execution killed with signal 6
55 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 432 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 1 ms 348 KB Output is correct
8 Correct 0 ms 344 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 1 ms 344 KB Output is correct
12 Correct 0 ms 348 KB Output is correct
13 Correct 0 ms 344 KB Output is correct
14 Correct 1 ms 604 KB Output is correct
15 Correct 0 ms 348 KB Output is correct
16 Correct 0 ms 348 KB Output is correct
17 Correct 1 ms 348 KB Output is correct
18 Correct 0 ms 348 KB Output is correct
19 Correct 0 ms 436 KB Output is correct
20 Correct 0 ms 436 KB Output is correct
21 Correct 0 ms 344 KB Output is correct
22 Correct 0 ms 348 KB Output is correct
23 Correct 0 ms 348 KB Output is correct
24 Correct 0 ms 344 KB Output is correct
25 Correct 2 ms 1896 KB Output is correct
26 Correct 2 ms 1896 KB Output is correct
27 Correct 2 ms 1896 KB Output is correct
28 Correct 2 ms 1892 KB Output is correct
29 Correct 2 ms 1896 KB Output is correct
30 Correct 1 ms 616 KB Output is correct
31 Incorrect 1 ms 460 KB 2nd lines differ - on the 1st token, expected: '1', found: '0'
32 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 1 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 1 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 1 ms 348 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 0 ms 348 KB Output is correct
12 Correct 0 ms 432 KB Output is correct
13 Correct 0 ms 348 KB Output is correct
14 Correct 1 ms 348 KB Output is correct
15 Correct 0 ms 344 KB Output is correct
16 Correct 0 ms 348 KB Output is correct
17 Correct 0 ms 348 KB Output is correct
18 Correct 1 ms 344 KB Output is correct
19 Correct 0 ms 348 KB Output is correct
20 Correct 0 ms 344 KB Output is correct
21 Correct 1 ms 604 KB Output is correct
22 Correct 0 ms 348 KB Output is correct
23 Correct 0 ms 348 KB Output is correct
24 Correct 1 ms 348 KB Output is correct
25 Correct 0 ms 348 KB Output is correct
26 Correct 0 ms 436 KB Output is correct
27 Correct 0 ms 436 KB Output is correct
28 Correct 0 ms 344 KB Output is correct
29 Correct 0 ms 348 KB Output is correct
30 Correct 0 ms 348 KB Output is correct
31 Correct 0 ms 344 KB Output is correct
32 Correct 0 ms 360 KB Output is correct
33 Correct 0 ms 552 KB Output is correct
34 Correct 0 ms 348 KB Output is correct
35 Correct 0 ms 348 KB Output is correct
36 Correct 0 ms 436 KB Output is correct
37 Correct 0 ms 432 KB Output is correct
38 Correct 169 ms 151636 KB Output is correct
39 Correct 171 ms 151636 KB Output is correct
40 Correct 0 ms 348 KB Output is correct
41 Correct 1 ms 348 KB Output is correct
42 Correct 0 ms 348 KB Output is correct
43 Correct 0 ms 348 KB Output is correct
44 Correct 2 ms 1884 KB Output is correct
45 Correct 2 ms 1884 KB Output is correct
46 Correct 2 ms 1884 KB Output is correct
47 Correct 2 ms 1884 KB Output is correct
48 Correct 181 ms 151304 KB Output is correct
49 Correct 176 ms 151376 KB Output is correct
50 Correct 177 ms 151808 KB Output is correct
51 Correct 169 ms 151676 KB Output is correct
52 Correct 1 ms 344 KB Output is correct
53 Correct 0 ms 348 KB Output is correct
54 Correct 0 ms 348 KB Output is correct
55 Correct 0 ms 348 KB Output is correct
56 Correct 0 ms 360 KB Output is correct
57 Correct 0 ms 348 KB Output is correct
58 Correct 1 ms 436 KB Output is correct
59 Correct 1 ms 348 KB Output is correct
60 Runtime error 1 ms 600 KB Execution killed with signal 6
61 Halted 0 ms 0 KB -