답안 #424925

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
424925 2021-06-12T11:41:48 Z Mlxa 슈퍼트리 잇기 (IOI20_supertrees) C++14
100 / 100
305 ms 31988 KB
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define all(x) x.begin(), x.end()
#define mp make_pair
#define mt make_tuple
#define x first
#define y second
#include "supertrees.h"

namespace my {

const int N = 1010;
int n, g[N][N], res[N][N];

void edge(int v, int u) {
	res[v][u] = true;
	res[u][v] = true;
}

vector<int> get_comp(int v, int msk) {
	static int lst[N], timer = 0;
	++timer;
	lst[v] = timer;
	queue<int> q;
	vector<int> ret;
	q.push(v);
	while (q.size()) {
		v = q.front(); q.pop();
		ret.push_back(v);
		for (int u = 0; u < n; ++u) {
			if (lst[u] == timer) {
				continue;
			}
			if ((msk >> g[v][u]) & 1) {
				lst[u] = timer;
				q.push(u);
			}
		}
	}
	return ret;
}

bool u1[N], u12[N];
}

int construct(vector<vector<int>> _g) {
	using namespace my;
	n = (int)_g.size();
	for (int i = 0; i < n; ++i) {
		for (int j = 0; j < n; ++j) {
			g[i][j] = _g[i][j];
			if (g[i][j] == 3) {
				return 0;
			}
		}
	}
	for (int i = 0; i < n; ++i) {
		if (u12[i]) {
			continue;
		}
		vector<int> c12 = get_comp(i, (1 << 1) | (1 << 2));
		// cout << "! " << c12.size() << endl;
		vector<int> cycle;
		for (int v : c12) {
			u12[v] = true;
			if (u1[v]) {
				continue;
			}
			vector<int> c1 = get_comp(v, 1 << 1);
			// cout << "? " << c1.size() << " " << c1[0] << endl;
			for (int u : c1) {
				for (int uu : c1) {
					if (g[u][uu] != 1) {
						return 0;
					}
				}
				u1[u] = true;
			}
			for (int u : c1) {
				for (int uu : c12) {
					if (u1[uu]) {
						continue;
					}
					if (g[u][uu] != 2) {
						return 0;
					}
				}
			}
			for (int idx = 0; idx + 1 < (int)c1.size(); ++idx) {
				edge(c1[idx], c1[idx + 1]);
			}
			cycle.push_back(c1.front());
		}
		if (cycle.size() == 1) {
			continue;
		}
		if (cycle.size() == 2) {
			return 0;
		}
		for (int idx = 0; idx < (int)cycle.size(); ++idx) {
			edge(cycle[idx], cycle[(idx + 1) % cycle.size()]);
		}
	}
	vector<vector<int>> answer;
	for (int i = 0; i < n; ++i) {
		answer.push_back(vector<int>(res[i], res[i] + n));
	}
	build(answer);
	return 1;
}

#ifdef LC
#include "grader.cpp"
#endif
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 300 KB Output is correct
2 Correct 1 ms 288 KB Output is correct
3 Correct 1 ms 204 KB Output is correct
4 Correct 1 ms 332 KB Output is correct
5 Correct 1 ms 332 KB Output is correct
6 Correct 11 ms 2740 KB Output is correct
7 Correct 246 ms 31876 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 300 KB Output is correct
2 Correct 1 ms 288 KB Output is correct
3 Correct 1 ms 204 KB Output is correct
4 Correct 1 ms 332 KB Output is correct
5 Correct 1 ms 332 KB Output is correct
6 Correct 11 ms 2740 KB Output is correct
7 Correct 246 ms 31876 KB Output is correct
8 Correct 1 ms 296 KB Output is correct
9 Correct 1 ms 292 KB Output is correct
10 Correct 1 ms 288 KB Output is correct
11 Correct 1 ms 332 KB Output is correct
12 Correct 11 ms 2072 KB Output is correct
13 Correct 239 ms 27864 KB Output is correct
14 Correct 1 ms 204 KB Output is correct
15 Correct 1 ms 324 KB Output is correct
16 Correct 5 ms 1440 KB Output is correct
17 Correct 112 ms 13988 KB Output is correct
18 Correct 1 ms 204 KB Output is correct
19 Correct 1 ms 204 KB Output is correct
20 Correct 60 ms 9976 KB Output is correct
21 Correct 247 ms 31872 KB Output is correct
22 Correct 238 ms 31296 KB Output is correct
23 Correct 258 ms 31868 KB Output is correct
24 Correct 237 ms 28200 KB Output is correct
25 Correct 104 ms 16068 KB Output is correct
26 Correct 103 ms 14304 KB Output is correct
27 Correct 250 ms 31860 KB Output is correct
28 Correct 251 ms 28132 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 0 ms 204 KB Output is correct
3 Correct 0 ms 204 KB Output is correct
4 Correct 1 ms 356 KB Output is correct
5 Correct 1 ms 332 KB Output is correct
6 Correct 0 ms 332 KB Output is correct
7 Correct 1 ms 332 KB Output is correct
8 Correct 13 ms 1996 KB Output is correct
9 Correct 250 ms 27948 KB Output is correct
10 Correct 1 ms 332 KB Output is correct
11 Correct 1 ms 332 KB Output is correct
12 Correct 12 ms 2848 KB Output is correct
13 Correct 294 ms 31940 KB Output is correct
14 Correct 1 ms 432 KB Output is correct
15 Correct 1 ms 332 KB Output is correct
16 Correct 5 ms 1484 KB Output is correct
17 Correct 134 ms 14072 KB Output is correct
18 Correct 1 ms 204 KB Output is correct
19 Correct 1 ms 204 KB Output is correct
20 Correct 1 ms 332 KB Output is correct
21 Correct 64 ms 9972 KB Output is correct
22 Correct 260 ms 31868 KB Output is correct
23 Correct 254 ms 31780 KB Output is correct
24 Correct 260 ms 31940 KB Output is correct
25 Correct 101 ms 14252 KB Output is correct
26 Correct 99 ms 14836 KB Output is correct
27 Correct 256 ms 31912 KB Output is correct
28 Correct 255 ms 31864 KB Output is correct
29 Correct 104 ms 14276 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 1 ms 204 KB Output is correct
3 Correct 0 ms 332 KB Output is correct
4 Correct 61 ms 10044 KB Output is correct
5 Correct 260 ms 31924 KB Output is correct
6 Correct 239 ms 31348 KB Output is correct
7 Correct 272 ms 31988 KB Output is correct
8 Correct 1 ms 332 KB Output is correct
9 Correct 67 ms 10024 KB Output is correct
10 Correct 252 ms 31920 KB Output is correct
11 Correct 236 ms 31744 KB Output is correct
12 Correct 274 ms 31856 KB Output is correct
13 Correct 1 ms 332 KB Output is correct
14 Correct 1 ms 332 KB Output is correct
15 Correct 1 ms 300 KB Output is correct
16 Correct 69 ms 9972 KB Output is correct
17 Correct 264 ms 31868 KB Output is correct
18 Correct 269 ms 31728 KB Output is correct
19 Correct 305 ms 31856 KB Output is correct
20 Correct 234 ms 28172 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 300 KB Output is correct
2 Correct 1 ms 288 KB Output is correct
3 Correct 1 ms 204 KB Output is correct
4 Correct 1 ms 332 KB Output is correct
5 Correct 1 ms 332 KB Output is correct
6 Correct 11 ms 2740 KB Output is correct
7 Correct 246 ms 31876 KB Output is correct
8 Correct 1 ms 296 KB Output is correct
9 Correct 1 ms 292 KB Output is correct
10 Correct 1 ms 288 KB Output is correct
11 Correct 1 ms 332 KB Output is correct
12 Correct 11 ms 2072 KB Output is correct
13 Correct 239 ms 27864 KB Output is correct
14 Correct 1 ms 204 KB Output is correct
15 Correct 1 ms 324 KB Output is correct
16 Correct 5 ms 1440 KB Output is correct
17 Correct 112 ms 13988 KB Output is correct
18 Correct 1 ms 204 KB Output is correct
19 Correct 1 ms 204 KB Output is correct
20 Correct 60 ms 9976 KB Output is correct
21 Correct 247 ms 31872 KB Output is correct
22 Correct 238 ms 31296 KB Output is correct
23 Correct 258 ms 31868 KB Output is correct
24 Correct 237 ms 28200 KB Output is correct
25 Correct 104 ms 16068 KB Output is correct
26 Correct 103 ms 14304 KB Output is correct
27 Correct 250 ms 31860 KB Output is correct
28 Correct 251 ms 28132 KB Output is correct
29 Correct 1 ms 204 KB Output is correct
30 Correct 0 ms 204 KB Output is correct
31 Correct 0 ms 204 KB Output is correct
32 Correct 1 ms 356 KB Output is correct
33 Correct 1 ms 332 KB Output is correct
34 Correct 0 ms 332 KB Output is correct
35 Correct 1 ms 332 KB Output is correct
36 Correct 13 ms 1996 KB Output is correct
37 Correct 250 ms 27948 KB Output is correct
38 Correct 1 ms 332 KB Output is correct
39 Correct 1 ms 332 KB Output is correct
40 Correct 12 ms 2848 KB Output is correct
41 Correct 294 ms 31940 KB Output is correct
42 Correct 1 ms 432 KB Output is correct
43 Correct 1 ms 332 KB Output is correct
44 Correct 5 ms 1484 KB Output is correct
45 Correct 134 ms 14072 KB Output is correct
46 Correct 1 ms 204 KB Output is correct
47 Correct 1 ms 204 KB Output is correct
48 Correct 1 ms 332 KB Output is correct
49 Correct 64 ms 9972 KB Output is correct
50 Correct 260 ms 31868 KB Output is correct
51 Correct 254 ms 31780 KB Output is correct
52 Correct 260 ms 31940 KB Output is correct
53 Correct 101 ms 14252 KB Output is correct
54 Correct 99 ms 14836 KB Output is correct
55 Correct 256 ms 31912 KB Output is correct
56 Correct 255 ms 31864 KB Output is correct
57 Correct 104 ms 14276 KB Output is correct
58 Correct 1 ms 204 KB Output is correct
59 Correct 1 ms 332 KB Output is correct
60 Correct 5 ms 1484 KB Output is correct
61 Correct 152 ms 14100 KB Output is correct
62 Correct 1 ms 332 KB Output is correct
63 Correct 1 ms 296 KB Output is correct
64 Correct 1 ms 332 KB Output is correct
65 Correct 85 ms 10052 KB Output is correct
66 Correct 119 ms 14448 KB Output is correct
67 Correct 111 ms 15744 KB Output is correct
68 Correct 104 ms 14464 KB Output is correct
69 Correct 94 ms 14072 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 300 KB Output is correct
2 Correct 1 ms 288 KB Output is correct
3 Correct 1 ms 204 KB Output is correct
4 Correct 1 ms 332 KB Output is correct
5 Correct 1 ms 332 KB Output is correct
6 Correct 11 ms 2740 KB Output is correct
7 Correct 246 ms 31876 KB Output is correct
8 Correct 1 ms 296 KB Output is correct
9 Correct 1 ms 292 KB Output is correct
10 Correct 1 ms 288 KB Output is correct
11 Correct 1 ms 332 KB Output is correct
12 Correct 11 ms 2072 KB Output is correct
13 Correct 239 ms 27864 KB Output is correct
14 Correct 1 ms 204 KB Output is correct
15 Correct 1 ms 324 KB Output is correct
16 Correct 5 ms 1440 KB Output is correct
17 Correct 112 ms 13988 KB Output is correct
18 Correct 1 ms 204 KB Output is correct
19 Correct 1 ms 204 KB Output is correct
20 Correct 60 ms 9976 KB Output is correct
21 Correct 247 ms 31872 KB Output is correct
22 Correct 238 ms 31296 KB Output is correct
23 Correct 258 ms 31868 KB Output is correct
24 Correct 237 ms 28200 KB Output is correct
25 Correct 104 ms 16068 KB Output is correct
26 Correct 103 ms 14304 KB Output is correct
27 Correct 250 ms 31860 KB Output is correct
28 Correct 251 ms 28132 KB Output is correct
29 Correct 1 ms 204 KB Output is correct
30 Correct 0 ms 204 KB Output is correct
31 Correct 0 ms 204 KB Output is correct
32 Correct 1 ms 356 KB Output is correct
33 Correct 1 ms 332 KB Output is correct
34 Correct 0 ms 332 KB Output is correct
35 Correct 1 ms 332 KB Output is correct
36 Correct 13 ms 1996 KB Output is correct
37 Correct 250 ms 27948 KB Output is correct
38 Correct 1 ms 332 KB Output is correct
39 Correct 1 ms 332 KB Output is correct
40 Correct 12 ms 2848 KB Output is correct
41 Correct 294 ms 31940 KB Output is correct
42 Correct 1 ms 432 KB Output is correct
43 Correct 1 ms 332 KB Output is correct
44 Correct 5 ms 1484 KB Output is correct
45 Correct 134 ms 14072 KB Output is correct
46 Correct 1 ms 204 KB Output is correct
47 Correct 1 ms 204 KB Output is correct
48 Correct 1 ms 332 KB Output is correct
49 Correct 64 ms 9972 KB Output is correct
50 Correct 260 ms 31868 KB Output is correct
51 Correct 254 ms 31780 KB Output is correct
52 Correct 260 ms 31940 KB Output is correct
53 Correct 101 ms 14252 KB Output is correct
54 Correct 99 ms 14836 KB Output is correct
55 Correct 256 ms 31912 KB Output is correct
56 Correct 255 ms 31864 KB Output is correct
57 Correct 104 ms 14276 KB Output is correct
58 Correct 1 ms 204 KB Output is correct
59 Correct 1 ms 204 KB Output is correct
60 Correct 0 ms 332 KB Output is correct
61 Correct 61 ms 10044 KB Output is correct
62 Correct 260 ms 31924 KB Output is correct
63 Correct 239 ms 31348 KB Output is correct
64 Correct 272 ms 31988 KB Output is correct
65 Correct 1 ms 332 KB Output is correct
66 Correct 67 ms 10024 KB Output is correct
67 Correct 252 ms 31920 KB Output is correct
68 Correct 236 ms 31744 KB Output is correct
69 Correct 274 ms 31856 KB Output is correct
70 Correct 1 ms 332 KB Output is correct
71 Correct 1 ms 332 KB Output is correct
72 Correct 1 ms 300 KB Output is correct
73 Correct 69 ms 9972 KB Output is correct
74 Correct 264 ms 31868 KB Output is correct
75 Correct 269 ms 31728 KB Output is correct
76 Correct 305 ms 31856 KB Output is correct
77 Correct 234 ms 28172 KB Output is correct
78 Correct 1 ms 204 KB Output is correct
79 Correct 1 ms 332 KB Output is correct
80 Correct 5 ms 1484 KB Output is correct
81 Correct 152 ms 14100 KB Output is correct
82 Correct 1 ms 332 KB Output is correct
83 Correct 1 ms 296 KB Output is correct
84 Correct 1 ms 332 KB Output is correct
85 Correct 85 ms 10052 KB Output is correct
86 Correct 119 ms 14448 KB Output is correct
87 Correct 111 ms 15744 KB Output is correct
88 Correct 104 ms 14464 KB Output is correct
89 Correct 94 ms 14072 KB Output is correct
90 Correct 1 ms 204 KB Output is correct
91 Correct 1 ms 204 KB Output is correct
92 Correct 7 ms 636 KB Output is correct
93 Correct 100 ms 10052 KB Output is correct
94 Correct 1 ms 204 KB Output is correct
95 Correct 1 ms 204 KB Output is correct
96 Correct 1 ms 204 KB Output is correct
97 Correct 23 ms 2808 KB Output is correct
98 Correct 96 ms 10372 KB Output is correct
99 Correct 115 ms 10612 KB Output is correct
100 Correct 94 ms 10436 KB Output is correct
101 Correct 114 ms 11376 KB Output is correct
102 Correct 105 ms 10108 KB Output is correct
103 Correct 93 ms 10052 KB Output is correct
104 Correct 93 ms 10104 KB Output is correct
105 Correct 102 ms 10020 KB Output is correct