답안 #721485

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
721485 2023-04-11T02:29:18 Z joelgun14 슈퍼트리 잇기 (IOI20_supertrees) C++17
100 / 100
282 ms 24016 KB
#include "supertrees.h"
#include <bits/stdc++.h>
using namespace std;
const int lim = 1e3 + 5;
struct disjoint_set {
	int h[lim], sz[lim];
	disjoint_set() {
		fill(sz, sz + lim, 1);
		memset(h, -1, sizeof(h));
	}
	int fh(int nd) {
		return h[nd] == -1 ? nd : h[nd] = fh(h[nd]);
	}
	bool merge(int x, int y) {
		x = fh(x), y =fh(y);
		if(x != y) {
			if(sz[x] < sz[y])
				swap(x, y);
			h[y] = x;
			sz[x] += sz[y];
		}
		return x != y;
	}
};
int construct(std::vector<std::vector<int>> p) {
	int n = p.size();
	std::vector<std::vector<int>> answer(n, vector<int>(n, 0));
	bool ans = 1;
	disjoint_set one, two;
	for (int i = 0; i < n; i++) {
		for(int j = 0; j < n; ++j) {
			if(p[i][j] == 3) {
				return 0;
			}
			else if(p[i][j] == 2) {
				two.merge(i, j);
			}	
			else if(p[i][j] == 1) {
				// jadiin 1 group
				one.merge(i, j);
				two.merge(i, j);
			}
		}
	}
	// harus exactly one
	// yg path 1 jadiin 1 grup, tempel ke 1 node
	// nanti jadiin groups banyak
	// group 2 -> harus connected component ish style
	// nanti cek tiap grup yg ter konek bs atau ngga
	for(int i = 0; i < n; ++i) {
		for(int j = i + 1; j < n; ++j) {
			if(p[i][j] == 1) {

			}
			else if(p[i][j] == 2) {
				if(one.fh(i) == one.fh(j)) {
					return 0;
				}
			}
			else {
				if(one.fh(i) == one.fh(j) || two.fh(i) == two.fh(j))
					return 0;
			}
		}		
	}
	// every one group connect ke 1, inside two group nanti buat cycle
	// minimal one group inside 2 harus ada 3
	bool vis[n];
	memset(vis, 0, sizeof(vis));
	for(int i = 0; i < n; ++i) {
		//cout << i << " " << one.fh(i) << endl;
		if(i != one.fh(i))
			answer[i][one.fh(i)] = answer[one.fh(i)][i] = 1;
	}
	for(int i = 0; i < n; ++i) {
		if(vis[i])
			continue;
		set<int> onegroup;
		for(int j = i; j < n; ++j) {
			if(two.fh(j) == two.fh(i)) {
				vis[j] = 1;
				onegroup.insert(one.fh(j));
			}
		}
		if(onegroup.size() == 2)
			return 0;
		if(onegroup.size() == 1)
			continue;
		vector<int> tmp;
		for(auto j : onegroup)
			tmp.push_back(j);
		for(int i = 0; i < tmp.size(); ++i) {
			answer[tmp[i]][tmp[(i + 1) % tmp.size()]] = answer[tmp[(i + 1) % tmp.size()]][tmp[i]] = 1;
		}
	}
	build(answer);
	return 1;
}

Compilation message

supertrees.cpp: In function 'int construct(std::vector<std::vector<int> >)':
supertrees.cpp:92:20: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   92 |   for(int i = 0; i < tmp.size(); ++i) {
      |                  ~~^~~~~~~~~~~~
supertrees.cpp:28:7: warning: unused variable 'ans' [-Wunused-variable]
   28 |  bool ans = 1;
      |       ^~~
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 1 ms 304 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 1 ms 296 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Correct 13 ms 1152 KB Output is correct
7 Correct 255 ms 22204 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 1 ms 304 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 1 ms 296 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Correct 13 ms 1152 KB Output is correct
7 Correct 255 ms 22204 KB Output is correct
8 Correct 1 ms 212 KB Output is correct
9 Correct 1 ms 212 KB Output is correct
10 Correct 1 ms 300 KB Output is correct
11 Correct 1 ms 296 KB Output is correct
12 Correct 9 ms 1236 KB Output is correct
13 Correct 188 ms 22216 KB Output is correct
14 Correct 1 ms 212 KB Output is correct
15 Correct 1 ms 300 KB Output is correct
16 Correct 4 ms 772 KB Output is correct
17 Correct 103 ms 12300 KB Output is correct
18 Correct 1 ms 212 KB Output is correct
19 Correct 1 ms 212 KB Output is correct
20 Correct 55 ms 5848 KB Output is correct
21 Correct 212 ms 22252 KB Output is correct
22 Correct 190 ms 22180 KB Output is correct
23 Correct 205 ms 22220 KB Output is correct
24 Correct 185 ms 22220 KB Output is correct
25 Correct 77 ms 12256 KB Output is correct
26 Correct 69 ms 12320 KB Output is correct
27 Correct 189 ms 22200 KB Output is correct
28 Correct 202 ms 22220 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 1 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 1 ms 212 KB Output is correct
7 Correct 1 ms 212 KB Output is correct
8 Correct 8 ms 1204 KB Output is correct
9 Correct 198 ms 22220 KB Output is correct
10 Correct 1 ms 212 KB Output is correct
11 Correct 1 ms 300 KB Output is correct
12 Correct 8 ms 1216 KB Output is correct
13 Correct 182 ms 22280 KB Output is correct
14 Correct 1 ms 212 KB Output is correct
15 Correct 1 ms 212 KB Output is correct
16 Correct 7 ms 828 KB Output is correct
17 Correct 87 ms 12344 KB Output is correct
18 Correct 1 ms 248 KB Output is correct
19 Correct 1 ms 212 KB Output is correct
20 Correct 1 ms 212 KB Output is correct
21 Correct 46 ms 5812 KB Output is correct
22 Correct 188 ms 23960 KB Output is correct
23 Correct 213 ms 23948 KB Output is correct
24 Correct 282 ms 23908 KB Output is correct
25 Correct 107 ms 14084 KB Output is correct
26 Correct 82 ms 14028 KB Output is correct
27 Correct 199 ms 23936 KB Output is correct
28 Correct 265 ms 23992 KB Output is correct
29 Correct 77 ms 14068 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 1 ms 300 KB Output is correct
4 Correct 52 ms 5884 KB Output is correct
5 Correct 186 ms 22240 KB Output is correct
6 Correct 215 ms 22160 KB Output is correct
7 Correct 244 ms 22220 KB Output is correct
8 Correct 1 ms 212 KB Output is correct
9 Correct 47 ms 5880 KB Output is correct
10 Correct 192 ms 23928 KB Output is correct
11 Correct 179 ms 23916 KB Output is correct
12 Correct 217 ms 23924 KB Output is correct
13 Correct 1 ms 212 KB Output is correct
14 Correct 1 ms 212 KB Output is correct
15 Correct 1 ms 300 KB Output is correct
16 Correct 61 ms 6256 KB Output is correct
17 Correct 178 ms 23972 KB Output is correct
18 Correct 204 ms 23908 KB Output is correct
19 Correct 188 ms 24016 KB Output is correct
20 Correct 203 ms 23916 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 1 ms 304 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 1 ms 296 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Correct 13 ms 1152 KB Output is correct
7 Correct 255 ms 22204 KB Output is correct
8 Correct 1 ms 212 KB Output is correct
9 Correct 1 ms 212 KB Output is correct
10 Correct 1 ms 300 KB Output is correct
11 Correct 1 ms 296 KB Output is correct
12 Correct 9 ms 1236 KB Output is correct
13 Correct 188 ms 22216 KB Output is correct
14 Correct 1 ms 212 KB Output is correct
15 Correct 1 ms 300 KB Output is correct
16 Correct 4 ms 772 KB Output is correct
17 Correct 103 ms 12300 KB Output is correct
18 Correct 1 ms 212 KB Output is correct
19 Correct 1 ms 212 KB Output is correct
20 Correct 55 ms 5848 KB Output is correct
21 Correct 212 ms 22252 KB Output is correct
22 Correct 190 ms 22180 KB Output is correct
23 Correct 205 ms 22220 KB Output is correct
24 Correct 185 ms 22220 KB Output is correct
25 Correct 77 ms 12256 KB Output is correct
26 Correct 69 ms 12320 KB Output is correct
27 Correct 189 ms 22200 KB Output is correct
28 Correct 202 ms 22220 KB Output is correct
29 Correct 1 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 1 ms 212 KB Output is correct
33 Correct 1 ms 212 KB Output is correct
34 Correct 1 ms 212 KB Output is correct
35 Correct 1 ms 212 KB Output is correct
36 Correct 8 ms 1204 KB Output is correct
37 Correct 198 ms 22220 KB Output is correct
38 Correct 1 ms 212 KB Output is correct
39 Correct 1 ms 300 KB Output is correct
40 Correct 8 ms 1216 KB Output is correct
41 Correct 182 ms 22280 KB Output is correct
42 Correct 1 ms 212 KB Output is correct
43 Correct 1 ms 212 KB Output is correct
44 Correct 7 ms 828 KB Output is correct
45 Correct 87 ms 12344 KB Output is correct
46 Correct 1 ms 248 KB Output is correct
47 Correct 1 ms 212 KB Output is correct
48 Correct 1 ms 212 KB Output is correct
49 Correct 46 ms 5812 KB Output is correct
50 Correct 188 ms 23960 KB Output is correct
51 Correct 213 ms 23948 KB Output is correct
52 Correct 282 ms 23908 KB Output is correct
53 Correct 107 ms 14084 KB Output is correct
54 Correct 82 ms 14028 KB Output is correct
55 Correct 199 ms 23936 KB Output is correct
56 Correct 265 ms 23992 KB Output is correct
57 Correct 77 ms 14068 KB Output is correct
58 Correct 1 ms 212 KB Output is correct
59 Correct 0 ms 296 KB Output is correct
60 Correct 5 ms 852 KB Output is correct
61 Correct 105 ms 14000 KB Output is correct
62 Correct 1 ms 212 KB Output is correct
63 Correct 1 ms 212 KB Output is correct
64 Correct 1 ms 300 KB Output is correct
65 Correct 60 ms 6192 KB Output is correct
66 Correct 78 ms 14068 KB Output is correct
67 Correct 77 ms 14068 KB Output is correct
68 Correct 113 ms 13992 KB Output is correct
69 Correct 94 ms 14068 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 1 ms 304 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 1 ms 296 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Correct 13 ms 1152 KB Output is correct
7 Correct 255 ms 22204 KB Output is correct
8 Correct 1 ms 212 KB Output is correct
9 Correct 1 ms 212 KB Output is correct
10 Correct 1 ms 300 KB Output is correct
11 Correct 1 ms 296 KB Output is correct
12 Correct 9 ms 1236 KB Output is correct
13 Correct 188 ms 22216 KB Output is correct
14 Correct 1 ms 212 KB Output is correct
15 Correct 1 ms 300 KB Output is correct
16 Correct 4 ms 772 KB Output is correct
17 Correct 103 ms 12300 KB Output is correct
18 Correct 1 ms 212 KB Output is correct
19 Correct 1 ms 212 KB Output is correct
20 Correct 55 ms 5848 KB Output is correct
21 Correct 212 ms 22252 KB Output is correct
22 Correct 190 ms 22180 KB Output is correct
23 Correct 205 ms 22220 KB Output is correct
24 Correct 185 ms 22220 KB Output is correct
25 Correct 77 ms 12256 KB Output is correct
26 Correct 69 ms 12320 KB Output is correct
27 Correct 189 ms 22200 KB Output is correct
28 Correct 202 ms 22220 KB Output is correct
29 Correct 1 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 1 ms 212 KB Output is correct
33 Correct 1 ms 212 KB Output is correct
34 Correct 1 ms 212 KB Output is correct
35 Correct 1 ms 212 KB Output is correct
36 Correct 8 ms 1204 KB Output is correct
37 Correct 198 ms 22220 KB Output is correct
38 Correct 1 ms 212 KB Output is correct
39 Correct 1 ms 300 KB Output is correct
40 Correct 8 ms 1216 KB Output is correct
41 Correct 182 ms 22280 KB Output is correct
42 Correct 1 ms 212 KB Output is correct
43 Correct 1 ms 212 KB Output is correct
44 Correct 7 ms 828 KB Output is correct
45 Correct 87 ms 12344 KB Output is correct
46 Correct 1 ms 248 KB Output is correct
47 Correct 1 ms 212 KB Output is correct
48 Correct 1 ms 212 KB Output is correct
49 Correct 46 ms 5812 KB Output is correct
50 Correct 188 ms 23960 KB Output is correct
51 Correct 213 ms 23948 KB Output is correct
52 Correct 282 ms 23908 KB Output is correct
53 Correct 107 ms 14084 KB Output is correct
54 Correct 82 ms 14028 KB Output is correct
55 Correct 199 ms 23936 KB Output is correct
56 Correct 265 ms 23992 KB Output is correct
57 Correct 77 ms 14068 KB Output is correct
58 Correct 1 ms 212 KB Output is correct
59 Correct 1 ms 212 KB Output is correct
60 Correct 1 ms 300 KB Output is correct
61 Correct 52 ms 5884 KB Output is correct
62 Correct 186 ms 22240 KB Output is correct
63 Correct 215 ms 22160 KB Output is correct
64 Correct 244 ms 22220 KB Output is correct
65 Correct 1 ms 212 KB Output is correct
66 Correct 47 ms 5880 KB Output is correct
67 Correct 192 ms 23928 KB Output is correct
68 Correct 179 ms 23916 KB Output is correct
69 Correct 217 ms 23924 KB Output is correct
70 Correct 1 ms 212 KB Output is correct
71 Correct 1 ms 212 KB Output is correct
72 Correct 1 ms 300 KB Output is correct
73 Correct 61 ms 6256 KB Output is correct
74 Correct 178 ms 23972 KB Output is correct
75 Correct 204 ms 23908 KB Output is correct
76 Correct 188 ms 24016 KB Output is correct
77 Correct 203 ms 23916 KB Output is correct
78 Correct 1 ms 212 KB Output is correct
79 Correct 0 ms 296 KB Output is correct
80 Correct 5 ms 852 KB Output is correct
81 Correct 105 ms 14000 KB Output is correct
82 Correct 1 ms 212 KB Output is correct
83 Correct 1 ms 212 KB Output is correct
84 Correct 1 ms 300 KB Output is correct
85 Correct 60 ms 6192 KB Output is correct
86 Correct 78 ms 14068 KB Output is correct
87 Correct 77 ms 14068 KB Output is correct
88 Correct 113 ms 13992 KB Output is correct
89 Correct 94 ms 14068 KB Output is correct
90 Correct 1 ms 212 KB Output is correct
91 Correct 1 ms 212 KB Output is correct
92 Correct 4 ms 852 KB Output is correct
93 Correct 75 ms 13988 KB Output is correct
94 Correct 1 ms 300 KB Output is correct
95 Correct 1 ms 212 KB Output is correct
96 Correct 1 ms 212 KB Output is correct
97 Correct 19 ms 3696 KB Output is correct
98 Correct 89 ms 14068 KB Output is correct
99 Correct 70 ms 14080 KB Output is correct
100 Correct 69 ms 14072 KB Output is correct
101 Correct 73 ms 14080 KB Output is correct
102 Correct 75 ms 14072 KB Output is correct
103 Correct 73 ms 14000 KB Output is correct
104 Correct 72 ms 14068 KB Output is correct
105 Correct 86 ms 14076 KB Output is correct