답안 #417543

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
417543 2021-06-03T22:18:21 Z ja_kingy 슈퍼트리 잇기 (IOI20_supertrees) C++14
100 / 100
252 ms 23060 KB
#include "supertrees.h"
#include <bits/stdc++.h>
using namespace std;

const int mxN = 1000;
struct DSU {
	int dsu[mxN];
	DSU () {iota(dsu, end(dsu), 0);}
	int f(int x) {return dsu[x] == x ? x : dsu[x] = f(dsu[x]);}
	void merge(int a, int b) {
		a = f(a), b = f(b);
		if (a!=b) dsu[a] = b;
	}
} ldsu, cdsu;

int construct(std::vector<std::vector<int>> p) {
	int n = p.size();
	std::vector<std::vector<int>> answer(n, vector<int>(n));
	for (int i = 0; i < n; i++) for (int j = 0; j < n; ++j) {
		if (p[i][j] == 3) return 0;
		if (p[i][j]) {
			cdsu.merge(i,j);
		}
		if (p[i][j] == 1) {
			ldsu.merge(i,j);	
		}
	}

	for (int i = 0; i < n; i++) for (int j = 0; j < n; ++j) {
		if (p[i][j] == 0 && cdsu.f(i) == cdsu.f(j)) {
			return 0;
		}
		if (p[i][j] == 2 && ldsu.f(i) == ldsu.f(j)) {
			return 0;
		}
	}

	vector<vector<int>> ls(n), cs(n);
	for (int i = 0; i < n; ++i) {
		int l = ldsu.f(i);
		if (ls[l].size()) answer[ls[l].back()][i] = answer[i][ls[l].back()] = 1;
		ls[l].push_back(i);
	}

	for (int j = 0; j < n; ++j) if (ls[j].size()) {
		int i = ls[j].back();
		int c = cdsu.f(i);
		if (cs[c].size()) answer[cs[c].back()][i] = answer[i][cs[c].back()] = 1;
		cs[c].push_back(i);
	}

	for (int i = 0; i < n; ++i) if (cs[i].size()) {
		if (cs[i].size() == 2) return 0;
		if (cs[i].size() > 2) {
			answer[cs[i].back()][cs[i].front()] = answer[cs[i].front()][cs[i].back()] = 1;
		}
	}

	build(answer);
	return 1;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 1 ms 296 KB Output is correct
3 Correct 1 ms 204 KB Output is correct
4 Correct 1 ms 204 KB Output is correct
5 Correct 1 ms 204 KB Output is correct
6 Correct 10 ms 1188 KB Output is correct
7 Correct 231 ms 23040 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 1 ms 296 KB Output is correct
3 Correct 1 ms 204 KB Output is correct
4 Correct 1 ms 204 KB Output is correct
5 Correct 1 ms 204 KB Output is correct
6 Correct 10 ms 1188 KB Output is correct
7 Correct 231 ms 23040 KB Output is correct
8 Correct 1 ms 204 KB Output is correct
9 Correct 1 ms 204 KB Output is correct
10 Correct 1 ms 204 KB Output is correct
11 Correct 1 ms 296 KB Output is correct
12 Correct 10 ms 1228 KB Output is correct
13 Correct 227 ms 23036 KB Output is correct
14 Correct 1 ms 204 KB Output is correct
15 Correct 1 ms 296 KB Output is correct
16 Correct 6 ms 796 KB Output is correct
17 Correct 113 ms 12700 KB Output is correct
18 Correct 1 ms 204 KB Output is correct
19 Correct 1 ms 204 KB Output is correct
20 Correct 58 ms 6172 KB Output is correct
21 Correct 240 ms 22724 KB Output is correct
22 Correct 230 ms 22644 KB Output is correct
23 Correct 244 ms 22632 KB Output is correct
24 Correct 225 ms 22724 KB Output is correct
25 Correct 96 ms 12740 KB Output is correct
26 Correct 93 ms 12684 KB Output is correct
27 Correct 247 ms 22648 KB Output is correct
28 Correct 228 ms 22852 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 1 ms 204 KB Output is correct
4 Correct 1 ms 204 KB Output is correct
5 Correct 1 ms 204 KB Output is correct
6 Correct 0 ms 304 KB Output is correct
7 Correct 1 ms 204 KB Output is correct
8 Correct 10 ms 1216 KB Output is correct
9 Correct 226 ms 22596 KB Output is correct
10 Correct 1 ms 204 KB Output is correct
11 Correct 1 ms 332 KB Output is correct
12 Correct 10 ms 1268 KB Output is correct
13 Correct 235 ms 22800 KB Output is correct
14 Correct 1 ms 296 KB Output is correct
15 Correct 1 ms 296 KB Output is correct
16 Correct 5 ms 844 KB Output is correct
17 Correct 110 ms 12608 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 204 KB Output is correct
21 Correct 58 ms 6192 KB Output is correct
22 Correct 236 ms 22536 KB Output is correct
23 Correct 231 ms 22660 KB Output is correct
24 Correct 252 ms 22664 KB Output is correct
25 Correct 97 ms 12740 KB Output is correct
26 Correct 96 ms 12580 KB Output is correct
27 Correct 231 ms 22648 KB Output is correct
28 Correct 250 ms 22596 KB Output is correct
29 Correct 101 ms 12712 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 1 ms 296 KB Output is correct
3 Correct 1 ms 204 KB Output is correct
4 Correct 58 ms 6260 KB Output is correct
5 Correct 234 ms 22984 KB Output is correct
6 Correct 228 ms 22944 KB Output is correct
7 Correct 242 ms 22968 KB Output is correct
8 Correct 1 ms 204 KB Output is correct
9 Correct 58 ms 6188 KB Output is correct
10 Correct 235 ms 23016 KB Output is correct
11 Correct 226 ms 22984 KB Output is correct
12 Correct 249 ms 23060 KB Output is correct
13 Correct 1 ms 204 KB Output is correct
14 Correct 1 ms 204 KB Output is correct
15 Correct 1 ms 204 KB Output is correct
16 Correct 58 ms 6212 KB Output is correct
17 Correct 233 ms 22408 KB Output is correct
18 Correct 242 ms 22468 KB Output is correct
19 Correct 228 ms 22404 KB Output is correct
20 Correct 228 ms 22440 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 1 ms 296 KB Output is correct
3 Correct 1 ms 204 KB Output is correct
4 Correct 1 ms 204 KB Output is correct
5 Correct 1 ms 204 KB Output is correct
6 Correct 10 ms 1188 KB Output is correct
7 Correct 231 ms 23040 KB Output is correct
8 Correct 1 ms 204 KB Output is correct
9 Correct 1 ms 204 KB Output is correct
10 Correct 1 ms 204 KB Output is correct
11 Correct 1 ms 296 KB Output is correct
12 Correct 10 ms 1228 KB Output is correct
13 Correct 227 ms 23036 KB Output is correct
14 Correct 1 ms 204 KB Output is correct
15 Correct 1 ms 296 KB Output is correct
16 Correct 6 ms 796 KB Output is correct
17 Correct 113 ms 12700 KB Output is correct
18 Correct 1 ms 204 KB Output is correct
19 Correct 1 ms 204 KB Output is correct
20 Correct 58 ms 6172 KB Output is correct
21 Correct 240 ms 22724 KB Output is correct
22 Correct 230 ms 22644 KB Output is correct
23 Correct 244 ms 22632 KB Output is correct
24 Correct 225 ms 22724 KB Output is correct
25 Correct 96 ms 12740 KB Output is correct
26 Correct 93 ms 12684 KB Output is correct
27 Correct 247 ms 22648 KB Output is correct
28 Correct 228 ms 22852 KB Output is correct
29 Correct 1 ms 204 KB Output is correct
30 Correct 1 ms 204 KB Output is correct
31 Correct 1 ms 204 KB Output is correct
32 Correct 1 ms 204 KB Output is correct
33 Correct 1 ms 204 KB Output is correct
34 Correct 0 ms 304 KB Output is correct
35 Correct 1 ms 204 KB Output is correct
36 Correct 10 ms 1216 KB Output is correct
37 Correct 226 ms 22596 KB Output is correct
38 Correct 1 ms 204 KB Output is correct
39 Correct 1 ms 332 KB Output is correct
40 Correct 10 ms 1268 KB Output is correct
41 Correct 235 ms 22800 KB Output is correct
42 Correct 1 ms 296 KB Output is correct
43 Correct 1 ms 296 KB Output is correct
44 Correct 5 ms 844 KB Output is correct
45 Correct 110 ms 12608 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 204 KB Output is correct
49 Correct 58 ms 6192 KB Output is correct
50 Correct 236 ms 22536 KB Output is correct
51 Correct 231 ms 22660 KB Output is correct
52 Correct 252 ms 22664 KB Output is correct
53 Correct 97 ms 12740 KB Output is correct
54 Correct 96 ms 12580 KB Output is correct
55 Correct 231 ms 22648 KB Output is correct
56 Correct 250 ms 22596 KB Output is correct
57 Correct 101 ms 12712 KB Output is correct
58 Correct 1 ms 204 KB Output is correct
59 Correct 1 ms 204 KB Output is correct
60 Correct 5 ms 844 KB Output is correct
61 Correct 114 ms 12552 KB Output is correct
62 Correct 1 ms 204 KB Output is correct
63 Correct 1 ms 204 KB Output is correct
64 Correct 1 ms 204 KB Output is correct
65 Correct 58 ms 6188 KB Output is correct
66 Correct 100 ms 12580 KB Output is correct
67 Correct 96 ms 12608 KB Output is correct
68 Correct 94 ms 12608 KB Output is correct
69 Correct 98 ms 12712 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 1 ms 296 KB Output is correct
3 Correct 1 ms 204 KB Output is correct
4 Correct 1 ms 204 KB Output is correct
5 Correct 1 ms 204 KB Output is correct
6 Correct 10 ms 1188 KB Output is correct
7 Correct 231 ms 23040 KB Output is correct
8 Correct 1 ms 204 KB Output is correct
9 Correct 1 ms 204 KB Output is correct
10 Correct 1 ms 204 KB Output is correct
11 Correct 1 ms 296 KB Output is correct
12 Correct 10 ms 1228 KB Output is correct
13 Correct 227 ms 23036 KB Output is correct
14 Correct 1 ms 204 KB Output is correct
15 Correct 1 ms 296 KB Output is correct
16 Correct 6 ms 796 KB Output is correct
17 Correct 113 ms 12700 KB Output is correct
18 Correct 1 ms 204 KB Output is correct
19 Correct 1 ms 204 KB Output is correct
20 Correct 58 ms 6172 KB Output is correct
21 Correct 240 ms 22724 KB Output is correct
22 Correct 230 ms 22644 KB Output is correct
23 Correct 244 ms 22632 KB Output is correct
24 Correct 225 ms 22724 KB Output is correct
25 Correct 96 ms 12740 KB Output is correct
26 Correct 93 ms 12684 KB Output is correct
27 Correct 247 ms 22648 KB Output is correct
28 Correct 228 ms 22852 KB Output is correct
29 Correct 1 ms 204 KB Output is correct
30 Correct 1 ms 204 KB Output is correct
31 Correct 1 ms 204 KB Output is correct
32 Correct 1 ms 204 KB Output is correct
33 Correct 1 ms 204 KB Output is correct
34 Correct 0 ms 304 KB Output is correct
35 Correct 1 ms 204 KB Output is correct
36 Correct 10 ms 1216 KB Output is correct
37 Correct 226 ms 22596 KB Output is correct
38 Correct 1 ms 204 KB Output is correct
39 Correct 1 ms 332 KB Output is correct
40 Correct 10 ms 1268 KB Output is correct
41 Correct 235 ms 22800 KB Output is correct
42 Correct 1 ms 296 KB Output is correct
43 Correct 1 ms 296 KB Output is correct
44 Correct 5 ms 844 KB Output is correct
45 Correct 110 ms 12608 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 204 KB Output is correct
49 Correct 58 ms 6192 KB Output is correct
50 Correct 236 ms 22536 KB Output is correct
51 Correct 231 ms 22660 KB Output is correct
52 Correct 252 ms 22664 KB Output is correct
53 Correct 97 ms 12740 KB Output is correct
54 Correct 96 ms 12580 KB Output is correct
55 Correct 231 ms 22648 KB Output is correct
56 Correct 250 ms 22596 KB Output is correct
57 Correct 101 ms 12712 KB Output is correct
58 Correct 1 ms 204 KB Output is correct
59 Correct 1 ms 296 KB Output is correct
60 Correct 1 ms 204 KB Output is correct
61 Correct 58 ms 6260 KB Output is correct
62 Correct 234 ms 22984 KB Output is correct
63 Correct 228 ms 22944 KB Output is correct
64 Correct 242 ms 22968 KB Output is correct
65 Correct 1 ms 204 KB Output is correct
66 Correct 58 ms 6188 KB Output is correct
67 Correct 235 ms 23016 KB Output is correct
68 Correct 226 ms 22984 KB Output is correct
69 Correct 249 ms 23060 KB Output is correct
70 Correct 1 ms 204 KB Output is correct
71 Correct 1 ms 204 KB Output is correct
72 Correct 1 ms 204 KB Output is correct
73 Correct 58 ms 6212 KB Output is correct
74 Correct 233 ms 22408 KB Output is correct
75 Correct 242 ms 22468 KB Output is correct
76 Correct 228 ms 22404 KB Output is correct
77 Correct 228 ms 22440 KB Output is correct
78 Correct 1 ms 204 KB Output is correct
79 Correct 1 ms 204 KB Output is correct
80 Correct 5 ms 844 KB Output is correct
81 Correct 114 ms 12552 KB Output is correct
82 Correct 1 ms 204 KB Output is correct
83 Correct 1 ms 204 KB Output is correct
84 Correct 1 ms 204 KB Output is correct
85 Correct 58 ms 6188 KB Output is correct
86 Correct 100 ms 12580 KB Output is correct
87 Correct 96 ms 12608 KB Output is correct
88 Correct 94 ms 12608 KB Output is correct
89 Correct 98 ms 12712 KB Output is correct
90 Correct 1 ms 204 KB Output is correct
91 Correct 1 ms 204 KB Output is correct
92 Correct 6 ms 844 KB Output is correct
93 Correct 103 ms 12556 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 24 ms 3612 KB Output is correct
98 Correct 96 ms 12544 KB Output is correct
99 Correct 94 ms 12608 KB Output is correct
100 Correct 94 ms 12612 KB Output is correct
101 Correct 92 ms 12572 KB Output is correct
102 Correct 93 ms 12612 KB Output is correct
103 Correct 94 ms 12588 KB Output is correct
104 Correct 94 ms 12724 KB Output is correct
105 Correct 101 ms 12580 KB Output is correct