답안 #589357

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
589357 2022-07-04T13:51:33 Z Lucpp 슈퍼트리 잇기 (IOI20_supertrees) C++17
100 / 100
211 ms 27372 KB
#include "supertrees.h"
#include <bits/stdc++.h>
using namespace std;
#define sz(x) ((int)(x).size())

vector<vector<int>> g;
vector<vector<bool>> adj;
vector<vector<int>> groups;

bool findGroups(){
	vector<bool> vis(sz(g));
	for(int u = 0; u < sz(g); u++){
		if(vis[u]) continue;
		vis[u] = true;
		groups.push_back({u});
		for(int v : g[u]){
			vis[v] = true;
			groups.back().push_back(v);
			if(adj[u] != adj[v]) return false;
		}
	}
	return true;
}

int construct(vector<vector<int>> p) {
	int n = sz(p);
	g.resize(n);
	adj.resize(n, vector<bool>(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] > 0) adj[i][j] = 1, g[i].push_back(j);
		}
	}
	if(!findGroups()) return 0;
	g.clear();
	g.resize(n);
	groups.clear();
	adj.assign(n, vector<bool>(n));
	for(int i = 0; i < n; i++){
		for(int j = 0; j < n; j++){
			if(p[i][j] == 1){
				adj[i][j] = 1;
				if(i != j) g[i].push_back(j);
			}
		}
	}
	if(!findGroups()) return 0;
	vector<vector<int>> ans(n, vector<int>(n));
	int m = sz(groups);
	vector<int> head(m), comp(n);
	for(int i = 0; i < m; i++) {
		vector<int> gr = groups[i];
		comp[gr[0]] = i;
		head[i] = gr[0];
		for(int j = 1; j < sz(gr); j++){
			ans[gr[j]][gr[j-1]] = ans[gr[j-1]][gr[j]] = 1;
			comp[gr[j]] = i;
		}
	}
	g.clear();
	g.resize(m);
	groups.clear();
	adj.assign(m, vector<bool>(m));
	for(int i = 0; i < m; i++) adj[i][i] = true;
	for(int i = 0; i < n; i++){
		for(int j = 0; j < n; j++){
			if(comp[i] != comp[j] && p[i][j] == 2 && !adj[comp[i]][comp[j]]){
				adj[comp[i]][comp[j]] = true;
				g[comp[i]].push_back(comp[j]);
			}
		}
	}
	if(!findGroups()) return 0;
	int k = sz(groups);
	for(int i = 0; i < k; i++){
		vector<int> gr = groups[i];
		if(sz(gr) == 2) return 0;
		if(sz(gr) != 1)
		for(int j = 0; j < sz(gr); j++){
			ans[head[gr[j]]][head[gr[(j+1)%sz(gr)]]] = ans[head[gr[(j+1)%sz(gr)]]][head[gr[j]]] = 1;
		}
	}
	build(ans);
	return 1;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 0 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 8 ms 1208 KB Output is correct
7 Correct 188 ms 22604 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 0 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 8 ms 1208 KB Output is correct
7 Correct 188 ms 22604 KB Output is correct
8 Correct 0 ms 212 KB Output is correct
9 Correct 1 ms 212 KB Output is correct
10 Correct 0 ms 300 KB Output is correct
11 Correct 1 ms 212 KB Output is correct
12 Correct 8 ms 1236 KB Output is correct
13 Correct 176 ms 22740 KB Output is correct
14 Correct 0 ms 212 KB Output is correct
15 Correct 1 ms 212 KB Output is correct
16 Correct 4 ms 724 KB Output is correct
17 Correct 85 ms 11300 KB Output is correct
18 Correct 0 ms 212 KB Output is correct
19 Correct 0 ms 212 KB Output is correct
20 Correct 45 ms 6060 KB Output is correct
21 Correct 205 ms 22552 KB Output is correct
22 Correct 172 ms 22476 KB Output is correct
23 Correct 192 ms 22440 KB Output is correct
24 Correct 194 ms 22616 KB Output is correct
25 Correct 77 ms 9360 KB Output is correct
26 Correct 71 ms 8836 KB Output is correct
27 Correct 190 ms 22416 KB Output is correct
28 Correct 175 ms 22600 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 1 ms 304 KB Output is correct
6 Correct 1 ms 212 KB Output is correct
7 Correct 0 ms 212 KB Output is correct
8 Correct 8 ms 1312 KB Output is correct
9 Correct 179 ms 22712 KB Output is correct
10 Correct 1 ms 212 KB Output is correct
11 Correct 0 ms 212 KB Output is correct
12 Correct 8 ms 1492 KB Output is correct
13 Correct 191 ms 26652 KB Output is correct
14 Correct 1 ms 212 KB Output is correct
15 Correct 1 ms 212 KB Output is correct
16 Correct 5 ms 820 KB Output is correct
17 Correct 85 ms 11284 KB Output is correct
18 Correct 1 ms 212 KB Output is correct
19 Correct 0 ms 212 KB Output is correct
20 Correct 0 ms 212 KB Output is correct
21 Correct 46 ms 6108 KB Output is correct
22 Correct 207 ms 24832 KB Output is correct
23 Correct 174 ms 24188 KB Output is correct
24 Correct 194 ms 27372 KB Output is correct
25 Correct 94 ms 14332 KB Output is correct
26 Correct 73 ms 10740 KB Output is correct
27 Correct 210 ms 24236 KB Output is correct
28 Correct 192 ms 26152 KB Output is correct
29 Correct 75 ms 14328 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 1 ms 232 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 46 ms 6056 KB Output is correct
5 Correct 183 ms 22472 KB Output is correct
6 Correct 205 ms 22564 KB Output is correct
7 Correct 186 ms 22532 KB Output is correct
8 Correct 0 ms 212 KB Output is correct
9 Correct 49 ms 6092 KB Output is correct
10 Correct 178 ms 24736 KB Output is correct
11 Correct 193 ms 24360 KB Output is correct
12 Correct 188 ms 27252 KB Output is correct
13 Correct 0 ms 212 KB Output is correct
14 Correct 0 ms 212 KB Output is correct
15 Correct 1 ms 212 KB Output is correct
16 Correct 45 ms 6320 KB Output is correct
17 Correct 179 ms 24740 KB Output is correct
18 Correct 211 ms 24324 KB Output is correct
19 Correct 173 ms 24308 KB Output is correct
20 Correct 184 ms 24272 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 0 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 8 ms 1208 KB Output is correct
7 Correct 188 ms 22604 KB Output is correct
8 Correct 0 ms 212 KB Output is correct
9 Correct 1 ms 212 KB Output is correct
10 Correct 0 ms 300 KB Output is correct
11 Correct 1 ms 212 KB Output is correct
12 Correct 8 ms 1236 KB Output is correct
13 Correct 176 ms 22740 KB Output is correct
14 Correct 0 ms 212 KB Output is correct
15 Correct 1 ms 212 KB Output is correct
16 Correct 4 ms 724 KB Output is correct
17 Correct 85 ms 11300 KB Output is correct
18 Correct 0 ms 212 KB Output is correct
19 Correct 0 ms 212 KB Output is correct
20 Correct 45 ms 6060 KB Output is correct
21 Correct 205 ms 22552 KB Output is correct
22 Correct 172 ms 22476 KB Output is correct
23 Correct 192 ms 22440 KB Output is correct
24 Correct 194 ms 22616 KB Output is correct
25 Correct 77 ms 9360 KB Output is correct
26 Correct 71 ms 8836 KB Output is correct
27 Correct 190 ms 22416 KB Output is correct
28 Correct 175 ms 22600 KB Output is correct
29 Correct 0 ms 212 KB Output is correct
30 Correct 1 ms 212 KB Output is correct
31 Correct 1 ms 212 KB Output is correct
32 Correct 0 ms 212 KB Output is correct
33 Correct 1 ms 304 KB Output is correct
34 Correct 1 ms 212 KB Output is correct
35 Correct 0 ms 212 KB Output is correct
36 Correct 8 ms 1312 KB Output is correct
37 Correct 179 ms 22712 KB Output is correct
38 Correct 1 ms 212 KB Output is correct
39 Correct 0 ms 212 KB Output is correct
40 Correct 8 ms 1492 KB Output is correct
41 Correct 191 ms 26652 KB Output is correct
42 Correct 1 ms 212 KB Output is correct
43 Correct 1 ms 212 KB Output is correct
44 Correct 5 ms 820 KB Output is correct
45 Correct 85 ms 11284 KB Output is correct
46 Correct 1 ms 212 KB Output is correct
47 Correct 0 ms 212 KB Output is correct
48 Correct 0 ms 212 KB Output is correct
49 Correct 46 ms 6108 KB Output is correct
50 Correct 207 ms 24832 KB Output is correct
51 Correct 174 ms 24188 KB Output is correct
52 Correct 194 ms 27372 KB Output is correct
53 Correct 94 ms 14332 KB Output is correct
54 Correct 73 ms 10740 KB Output is correct
55 Correct 210 ms 24236 KB Output is correct
56 Correct 192 ms 26152 KB Output is correct
57 Correct 75 ms 14328 KB Output is correct
58 Correct 1 ms 212 KB Output is correct
59 Correct 1 ms 212 KB Output is correct
60 Correct 4 ms 852 KB Output is correct
61 Correct 82 ms 14324 KB Output is correct
62 Correct 0 ms 212 KB Output is correct
63 Correct 1 ms 212 KB Output is correct
64 Correct 0 ms 212 KB Output is correct
65 Correct 60 ms 6264 KB Output is correct
66 Correct 75 ms 10800 KB Output is correct
67 Correct 76 ms 10788 KB Output is correct
68 Correct 70 ms 10484 KB Output is correct
69 Correct 76 ms 14324 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 0 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 8 ms 1208 KB Output is correct
7 Correct 188 ms 22604 KB Output is correct
8 Correct 0 ms 212 KB Output is correct
9 Correct 1 ms 212 KB Output is correct
10 Correct 0 ms 300 KB Output is correct
11 Correct 1 ms 212 KB Output is correct
12 Correct 8 ms 1236 KB Output is correct
13 Correct 176 ms 22740 KB Output is correct
14 Correct 0 ms 212 KB Output is correct
15 Correct 1 ms 212 KB Output is correct
16 Correct 4 ms 724 KB Output is correct
17 Correct 85 ms 11300 KB Output is correct
18 Correct 0 ms 212 KB Output is correct
19 Correct 0 ms 212 KB Output is correct
20 Correct 45 ms 6060 KB Output is correct
21 Correct 205 ms 22552 KB Output is correct
22 Correct 172 ms 22476 KB Output is correct
23 Correct 192 ms 22440 KB Output is correct
24 Correct 194 ms 22616 KB Output is correct
25 Correct 77 ms 9360 KB Output is correct
26 Correct 71 ms 8836 KB Output is correct
27 Correct 190 ms 22416 KB Output is correct
28 Correct 175 ms 22600 KB Output is correct
29 Correct 0 ms 212 KB Output is correct
30 Correct 1 ms 212 KB Output is correct
31 Correct 1 ms 212 KB Output is correct
32 Correct 0 ms 212 KB Output is correct
33 Correct 1 ms 304 KB Output is correct
34 Correct 1 ms 212 KB Output is correct
35 Correct 0 ms 212 KB Output is correct
36 Correct 8 ms 1312 KB Output is correct
37 Correct 179 ms 22712 KB Output is correct
38 Correct 1 ms 212 KB Output is correct
39 Correct 0 ms 212 KB Output is correct
40 Correct 8 ms 1492 KB Output is correct
41 Correct 191 ms 26652 KB Output is correct
42 Correct 1 ms 212 KB Output is correct
43 Correct 1 ms 212 KB Output is correct
44 Correct 5 ms 820 KB Output is correct
45 Correct 85 ms 11284 KB Output is correct
46 Correct 1 ms 212 KB Output is correct
47 Correct 0 ms 212 KB Output is correct
48 Correct 0 ms 212 KB Output is correct
49 Correct 46 ms 6108 KB Output is correct
50 Correct 207 ms 24832 KB Output is correct
51 Correct 174 ms 24188 KB Output is correct
52 Correct 194 ms 27372 KB Output is correct
53 Correct 94 ms 14332 KB Output is correct
54 Correct 73 ms 10740 KB Output is correct
55 Correct 210 ms 24236 KB Output is correct
56 Correct 192 ms 26152 KB Output is correct
57 Correct 75 ms 14328 KB Output is correct
58 Correct 0 ms 212 KB Output is correct
59 Correct 1 ms 232 KB Output is correct
60 Correct 1 ms 212 KB Output is correct
61 Correct 46 ms 6056 KB Output is correct
62 Correct 183 ms 22472 KB Output is correct
63 Correct 205 ms 22564 KB Output is correct
64 Correct 186 ms 22532 KB Output is correct
65 Correct 0 ms 212 KB Output is correct
66 Correct 49 ms 6092 KB Output is correct
67 Correct 178 ms 24736 KB Output is correct
68 Correct 193 ms 24360 KB Output is correct
69 Correct 188 ms 27252 KB Output is correct
70 Correct 0 ms 212 KB Output is correct
71 Correct 0 ms 212 KB Output is correct
72 Correct 1 ms 212 KB Output is correct
73 Correct 45 ms 6320 KB Output is correct
74 Correct 179 ms 24740 KB Output is correct
75 Correct 211 ms 24324 KB Output is correct
76 Correct 173 ms 24308 KB Output is correct
77 Correct 184 ms 24272 KB Output is correct
78 Correct 1 ms 212 KB Output is correct
79 Correct 1 ms 212 KB Output is correct
80 Correct 4 ms 852 KB Output is correct
81 Correct 82 ms 14324 KB Output is correct
82 Correct 0 ms 212 KB Output is correct
83 Correct 1 ms 212 KB Output is correct
84 Correct 0 ms 212 KB Output is correct
85 Correct 60 ms 6264 KB Output is correct
86 Correct 75 ms 10800 KB Output is correct
87 Correct 76 ms 10788 KB Output is correct
88 Correct 70 ms 10484 KB Output is correct
89 Correct 76 ms 14324 KB Output is correct
90 Correct 0 ms 212 KB Output is correct
91 Correct 1 ms 212 KB Output is correct
92 Correct 4 ms 724 KB Output is correct
93 Correct 69 ms 10240 KB Output is correct
94 Correct 0 ms 212 KB Output is correct
95 Correct 1 ms 212 KB Output is correct
96 Correct 0 ms 212 KB Output is correct
97 Correct 17 ms 2812 KB Output is correct
98 Correct 67 ms 10364 KB Output is correct
99 Correct 72 ms 10352 KB Output is correct
100 Correct 66 ms 10240 KB Output is correct
101 Correct 93 ms 10236 KB Output is correct
102 Correct 64 ms 10224 KB Output is correct
103 Correct 62 ms 10228 KB Output is correct
104 Correct 63 ms 10240 KB Output is correct
105 Correct 78 ms 10228 KB Output is correct