답안 #823030

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
823030 2023-08-12T07:12:28 Z NothingXD 슈퍼트리 잇기 (IOI20_supertrees) C++17
100 / 100
192 ms 30132 KB
#include "supertrees.h"
#include <bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;

void debug_out(){cerr<<endl;}
template<typename Head, typename... Tail>
void debug_out(Head H, Tail... T){
	cerr << H << ' ';
	debug_out(T...);
}

#define debug(...) cerr << "(" << #__VA_ARGS__ << "): ", debug_out(__VA_ARGS__)
#define F first
#define S second
#define all(x) x.begin() x.end()
#define MP(x, y) make_pair(x, y)

const int maxn = 1e3 + 10;

int n, p[maxn][maxn], dsu[maxn], comp[maxn];
int ans[maxn][maxn];
vector<int> ver[maxn];
int getdsu(int v){
	return (dsu[v] == -1? v: dsu[v] = getdsu(dsu[v]));
}

void merge(int u, int v){
	if ((u = getdsu(u)) == (v = getdsu(v))) return;
	ans[u][v] = ans[v][u] = 1;
	dsu[u] = v;
}

bool merge2(int u, int v){
//	debug(u, v);
	u = comp[u], v = comp[v];
	if (u == v) return true;
	for (auto x: ver[u]){
		for (auto y: ver[v]){
			if (p[x][y] != 2) return false;
		}
	}
	for (auto x: ver[v]){
		if (x == v) continue;
		ver[u].push_back(x);
		comp[x] = u;
	}
	ver[u].push_back(v);
	comp[v] = u;
	return true;
}

int construct(vector<vector<int>> P) {
	n = P.size();
	for (int i = 0; i < n; i++){
		for (int j = 0; j < n; j++){
			p[i][j] = P[i][j];
			if (p[i][j] == 3) return 0;
		}
	}
	memset(dsu, -1, sizeof dsu);
	for (int i = 0; i < n; i++){
		for (int j = 0; j < n; j++){
			if (p[i][j] != p[j][i]) return 0;
			if (p[i][j] == 1) merge(i, j);
		}
	}
//	debug(1);
	for (int i = 0; i < n; i++){
		for (int j = 0; j < n; j++){
			if (p[i][j] != 1 && getdsu(i) == getdsu(j)) return 0;
		}
	}
//	debug(2);
	for (int i = 0; i < n; i++){
		int x = getdsu(i);
//		debug(i, x);
		ver[x].push_back(i);
		comp[i] = x;
	}
	for (int i = 0; i < n; i++){
		for (int j = 0; j < n; j++){
			if (p[i][j] == 2){
				if (!merge2(i, j)) return 0;
			}
		}
	}
//	debug(3);
	for (int i = 0; i < n; i++){
		ver[i].clear();
	}
	for (int i = 0; i < n; i++){
		if (dsu[i] == -1){
//			debug(i, comp[i]);
			ver[comp[i]].push_back(i);
		}
	}
	for (int i = 0; i < n; i++){
//		debug(i, ver[i].size());
		if (ver[i].size() < 2) continue;
		if (ver[i].size() == 2) return 0;
		for (int j = 1; j < ver[i].size(); j++){
			ans[ver[i][j-1]][ver[i][j]] = ans[ver[i][j]][ver[i][j-1]] = 1;
		}
		ans[ver[i][0]][ver[i].back()] = ans[ver[i].back()][ver[i][0]] = 1;
	}
//	debug(4);
	vector<vector<int>> res(n);
	for (int i = 0; i < n; i++){
		res[i].resize(n);
		for (int j = 0; j < n; j++){
			res[i][j] = ans[i][j];
		}
	}
	build(res);
	return 1;
}

Compilation message

supertrees.cpp: In function 'int construct(std::vector<std::vector<int> >)':
supertrees.cpp:106:21: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
  106 |   for (int j = 1; j < ver[i].size(); j++){
      |                   ~~^~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 340 KB Output is correct
2 Correct 0 ms 340 KB Output is correct
3 Correct 0 ms 340 KB Output is correct
4 Correct 0 ms 340 KB Output is correct
5 Correct 0 ms 340 KB Output is correct
6 Correct 9 ms 2772 KB Output is correct
7 Correct 158 ms 29964 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 340 KB Output is correct
2 Correct 0 ms 340 KB Output is correct
3 Correct 0 ms 340 KB Output is correct
4 Correct 0 ms 340 KB Output is correct
5 Correct 0 ms 340 KB Output is correct
6 Correct 9 ms 2772 KB Output is correct
7 Correct 158 ms 29964 KB Output is correct
8 Correct 1 ms 340 KB Output is correct
9 Correct 0 ms 296 KB Output is correct
10 Correct 0 ms 340 KB Output is correct
11 Correct 1 ms 340 KB Output is correct
12 Correct 7 ms 2004 KB Output is correct
13 Correct 160 ms 26020 KB Output is correct
14 Correct 0 ms 340 KB Output is correct
15 Correct 0 ms 340 KB Output is correct
16 Correct 4 ms 2132 KB Output is correct
17 Correct 72 ms 16048 KB Output is correct
18 Correct 0 ms 340 KB Output is correct
19 Correct 0 ms 340 KB Output is correct
20 Correct 44 ms 9544 KB Output is correct
21 Correct 163 ms 29988 KB Output is correct
22 Correct 166 ms 29440 KB Output is correct
23 Correct 178 ms 29972 KB Output is correct
24 Correct 156 ms 26228 KB Output is correct
25 Correct 67 ms 16052 KB Output is correct
26 Correct 65 ms 15668 KB Output is correct
27 Correct 176 ms 29988 KB Output is correct
28 Correct 163 ms 26284 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 340 KB Output is correct
2 Correct 0 ms 340 KB Output is correct
3 Correct 0 ms 340 KB Output is correct
4 Correct 0 ms 340 KB Output is correct
5 Correct 1 ms 340 KB Output is correct
6 Correct 0 ms 340 KB Output is correct
7 Correct 0 ms 340 KB Output is correct
8 Correct 7 ms 2024 KB Output is correct
9 Correct 157 ms 26068 KB Output is correct
10 Correct 0 ms 340 KB Output is correct
11 Correct 0 ms 340 KB Output is correct
12 Correct 7 ms 2832 KB Output is correct
13 Correct 166 ms 29932 KB Output is correct
14 Correct 0 ms 340 KB Output is correct
15 Correct 0 ms 340 KB Output is correct
16 Correct 3 ms 1364 KB Output is correct
17 Correct 69 ms 12196 KB Output is correct
18 Correct 0 ms 340 KB Output is correct
19 Correct 1 ms 340 KB Output is correct
20 Correct 0 ms 340 KB Output is correct
21 Correct 41 ms 9560 KB Output is correct
22 Correct 160 ms 30036 KB Output is correct
23 Correct 156 ms 29900 KB Output is correct
24 Correct 192 ms 29924 KB Output is correct
25 Correct 67 ms 12336 KB Output is correct
26 Correct 68 ms 12204 KB Output is correct
27 Correct 179 ms 29848 KB Output is correct
28 Correct 169 ms 29928 KB Output is correct
29 Correct 67 ms 12328 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 340 KB Output is correct
2 Correct 0 ms 340 KB Output is correct
3 Correct 0 ms 340 KB Output is correct
4 Correct 41 ms 9512 KB Output is correct
5 Correct 160 ms 29992 KB Output is correct
6 Correct 174 ms 29500 KB Output is correct
7 Correct 162 ms 29884 KB Output is correct
8 Correct 1 ms 388 KB Output is correct
9 Correct 41 ms 9640 KB Output is correct
10 Correct 160 ms 29928 KB Output is correct
11 Correct 161 ms 29864 KB Output is correct
12 Correct 164 ms 30012 KB Output is correct
13 Correct 0 ms 340 KB Output is correct
14 Correct 0 ms 340 KB Output is correct
15 Correct 0 ms 340 KB Output is correct
16 Correct 48 ms 9604 KB Output is correct
17 Correct 160 ms 30132 KB Output is correct
18 Correct 163 ms 29836 KB Output is correct
19 Correct 159 ms 29860 KB Output is correct
20 Correct 158 ms 26280 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 340 KB Output is correct
2 Correct 0 ms 340 KB Output is correct
3 Correct 0 ms 340 KB Output is correct
4 Correct 0 ms 340 KB Output is correct
5 Correct 0 ms 340 KB Output is correct
6 Correct 9 ms 2772 KB Output is correct
7 Correct 158 ms 29964 KB Output is correct
8 Correct 1 ms 340 KB Output is correct
9 Correct 0 ms 296 KB Output is correct
10 Correct 0 ms 340 KB Output is correct
11 Correct 1 ms 340 KB Output is correct
12 Correct 7 ms 2004 KB Output is correct
13 Correct 160 ms 26020 KB Output is correct
14 Correct 0 ms 340 KB Output is correct
15 Correct 0 ms 340 KB Output is correct
16 Correct 4 ms 2132 KB Output is correct
17 Correct 72 ms 16048 KB Output is correct
18 Correct 0 ms 340 KB Output is correct
19 Correct 0 ms 340 KB Output is correct
20 Correct 44 ms 9544 KB Output is correct
21 Correct 163 ms 29988 KB Output is correct
22 Correct 166 ms 29440 KB Output is correct
23 Correct 178 ms 29972 KB Output is correct
24 Correct 156 ms 26228 KB Output is correct
25 Correct 67 ms 16052 KB Output is correct
26 Correct 65 ms 15668 KB Output is correct
27 Correct 176 ms 29988 KB Output is correct
28 Correct 163 ms 26284 KB Output is correct
29 Correct 1 ms 340 KB Output is correct
30 Correct 0 ms 340 KB Output is correct
31 Correct 0 ms 340 KB Output is correct
32 Correct 0 ms 340 KB Output is correct
33 Correct 1 ms 340 KB Output is correct
34 Correct 0 ms 340 KB Output is correct
35 Correct 0 ms 340 KB Output is correct
36 Correct 7 ms 2024 KB Output is correct
37 Correct 157 ms 26068 KB Output is correct
38 Correct 0 ms 340 KB Output is correct
39 Correct 0 ms 340 KB Output is correct
40 Correct 7 ms 2832 KB Output is correct
41 Correct 166 ms 29932 KB Output is correct
42 Correct 0 ms 340 KB Output is correct
43 Correct 0 ms 340 KB Output is correct
44 Correct 3 ms 1364 KB Output is correct
45 Correct 69 ms 12196 KB Output is correct
46 Correct 0 ms 340 KB Output is correct
47 Correct 1 ms 340 KB Output is correct
48 Correct 0 ms 340 KB Output is correct
49 Correct 41 ms 9560 KB Output is correct
50 Correct 160 ms 30036 KB Output is correct
51 Correct 156 ms 29900 KB Output is correct
52 Correct 192 ms 29924 KB Output is correct
53 Correct 67 ms 12336 KB Output is correct
54 Correct 68 ms 12204 KB Output is correct
55 Correct 179 ms 29848 KB Output is correct
56 Correct 169 ms 29928 KB Output is correct
57 Correct 67 ms 12328 KB Output is correct
58 Correct 0 ms 340 KB Output is correct
59 Correct 0 ms 340 KB Output is correct
60 Correct 3 ms 2132 KB Output is correct
61 Correct 71 ms 16076 KB Output is correct
62 Correct 0 ms 340 KB Output is correct
63 Correct 1 ms 340 KB Output is correct
64 Correct 0 ms 340 KB Output is correct
65 Correct 40 ms 9548 KB Output is correct
66 Correct 66 ms 12204 KB Output is correct
67 Correct 64 ms 14248 KB Output is correct
68 Correct 69 ms 14260 KB Output is correct
69 Correct 70 ms 12344 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 340 KB Output is correct
2 Correct 0 ms 340 KB Output is correct
3 Correct 0 ms 340 KB Output is correct
4 Correct 0 ms 340 KB Output is correct
5 Correct 0 ms 340 KB Output is correct
6 Correct 9 ms 2772 KB Output is correct
7 Correct 158 ms 29964 KB Output is correct
8 Correct 1 ms 340 KB Output is correct
9 Correct 0 ms 296 KB Output is correct
10 Correct 0 ms 340 KB Output is correct
11 Correct 1 ms 340 KB Output is correct
12 Correct 7 ms 2004 KB Output is correct
13 Correct 160 ms 26020 KB Output is correct
14 Correct 0 ms 340 KB Output is correct
15 Correct 0 ms 340 KB Output is correct
16 Correct 4 ms 2132 KB Output is correct
17 Correct 72 ms 16048 KB Output is correct
18 Correct 0 ms 340 KB Output is correct
19 Correct 0 ms 340 KB Output is correct
20 Correct 44 ms 9544 KB Output is correct
21 Correct 163 ms 29988 KB Output is correct
22 Correct 166 ms 29440 KB Output is correct
23 Correct 178 ms 29972 KB Output is correct
24 Correct 156 ms 26228 KB Output is correct
25 Correct 67 ms 16052 KB Output is correct
26 Correct 65 ms 15668 KB Output is correct
27 Correct 176 ms 29988 KB Output is correct
28 Correct 163 ms 26284 KB Output is correct
29 Correct 1 ms 340 KB Output is correct
30 Correct 0 ms 340 KB Output is correct
31 Correct 0 ms 340 KB Output is correct
32 Correct 0 ms 340 KB Output is correct
33 Correct 1 ms 340 KB Output is correct
34 Correct 0 ms 340 KB Output is correct
35 Correct 0 ms 340 KB Output is correct
36 Correct 7 ms 2024 KB Output is correct
37 Correct 157 ms 26068 KB Output is correct
38 Correct 0 ms 340 KB Output is correct
39 Correct 0 ms 340 KB Output is correct
40 Correct 7 ms 2832 KB Output is correct
41 Correct 166 ms 29932 KB Output is correct
42 Correct 0 ms 340 KB Output is correct
43 Correct 0 ms 340 KB Output is correct
44 Correct 3 ms 1364 KB Output is correct
45 Correct 69 ms 12196 KB Output is correct
46 Correct 0 ms 340 KB Output is correct
47 Correct 1 ms 340 KB Output is correct
48 Correct 0 ms 340 KB Output is correct
49 Correct 41 ms 9560 KB Output is correct
50 Correct 160 ms 30036 KB Output is correct
51 Correct 156 ms 29900 KB Output is correct
52 Correct 192 ms 29924 KB Output is correct
53 Correct 67 ms 12336 KB Output is correct
54 Correct 68 ms 12204 KB Output is correct
55 Correct 179 ms 29848 KB Output is correct
56 Correct 169 ms 29928 KB Output is correct
57 Correct 67 ms 12328 KB Output is correct
58 Correct 1 ms 340 KB Output is correct
59 Correct 0 ms 340 KB Output is correct
60 Correct 0 ms 340 KB Output is correct
61 Correct 41 ms 9512 KB Output is correct
62 Correct 160 ms 29992 KB Output is correct
63 Correct 174 ms 29500 KB Output is correct
64 Correct 162 ms 29884 KB Output is correct
65 Correct 1 ms 388 KB Output is correct
66 Correct 41 ms 9640 KB Output is correct
67 Correct 160 ms 29928 KB Output is correct
68 Correct 161 ms 29864 KB Output is correct
69 Correct 164 ms 30012 KB Output is correct
70 Correct 0 ms 340 KB Output is correct
71 Correct 0 ms 340 KB Output is correct
72 Correct 0 ms 340 KB Output is correct
73 Correct 48 ms 9604 KB Output is correct
74 Correct 160 ms 30132 KB Output is correct
75 Correct 163 ms 29836 KB Output is correct
76 Correct 159 ms 29860 KB Output is correct
77 Correct 158 ms 26280 KB Output is correct
78 Correct 0 ms 340 KB Output is correct
79 Correct 0 ms 340 KB Output is correct
80 Correct 3 ms 2132 KB Output is correct
81 Correct 71 ms 16076 KB Output is correct
82 Correct 0 ms 340 KB Output is correct
83 Correct 1 ms 340 KB Output is correct
84 Correct 0 ms 340 KB Output is correct
85 Correct 40 ms 9548 KB Output is correct
86 Correct 66 ms 12204 KB Output is correct
87 Correct 64 ms 14248 KB Output is correct
88 Correct 69 ms 14260 KB Output is correct
89 Correct 70 ms 12344 KB Output is correct
90 Correct 0 ms 340 KB Output is correct
91 Correct 0 ms 212 KB Output is correct
92 Correct 3 ms 596 KB Output is correct
93 Correct 71 ms 8116 KB Output is correct
94 Correct 0 ms 340 KB Output is correct
95 Correct 0 ms 340 KB Output is correct
96 Correct 0 ms 340 KB Output is correct
97 Correct 15 ms 2348 KB Output is correct
98 Correct 66 ms 8372 KB Output is correct
99 Correct 59 ms 8780 KB Output is correct
100 Correct 59 ms 8488 KB Output is correct
101 Correct 65 ms 9520 KB Output is correct
102 Correct 63 ms 8104 KB Output is correct
103 Correct 69 ms 8104 KB Output is correct
104 Correct 62 ms 8116 KB Output is correct
105 Correct 83 ms 8116 KB Output is correct