답안 #1005216

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1005216 2024-06-22T09:00:07 Z thinknoexit 슈퍼트리 잇기 (IOI20_supertrees) C++17
100 / 100
144 ms 22284 KB
#include "supertrees.h"
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const int N = 1010;
int p[N], p2[N];
int fr(int i) {
	return p[i] == i ? i : p[i] = fr(p[i]);
}
int fr2(int i) {
	return p2[i] == i ? i : p2[i] = fr2(p2[i]);
}
int construct(vector<vector<int>> B) {
	int n = B.size();
	vector<vector<int>> ans(n, vector<int>(n, 0));
	// Calculate for p[i][j] = 1
	iota(p, p + n, 0);
	for (int i = 0;i < n;i++) {
		for (int j = i + 1;j < n;j++) {
			if (B[i][j] == 1) {
				p[fr(i)] = fr(j);
			}
			if (B[i][j] == 3) return 0;
		}
	}
	vector<vector<int>> g(n);
	for (int i = 0;i < n;i++) {
		g[fr(i)].push_back(i);
	}
	vector<int> node;
	for (int G = 0;G < n;G++) {
		if (g[G].empty()) continue;
		node.push_back(G);
		auto& v = g[G];
		int m = v.size();
		int cnt = 0;
		for (int i = 0;i < m;i++) {
			for (int j = i + 1;j < m;j++) {
				if (B[v[i]][v[j]] != 1) return 0;
			}
		}
		for (int i = 1;i < m;i++) {
			ans[v[0]][v[i]] = ans[v[i]][v[0]] = 1;
		}
	}
	iota(p2, p2 + n, 0);
	int k = node.size();
	for (int i = 0;i < k;i++) {
		for (int j = i + 1;j < k;j++) {
			if (B[node[i]][node[j]] == 2) {
				p2[fr2(node[i])] = fr2(node[j]);
			}
		}
	}
	vector<vector<int>> g2(n);
	for (int i = 0;i < k;i++) {
		g2[fr2(node[i])].push_back(node[i]);
	}
	for (int G = 0;G < n;G++) {
		if (g2[G].empty() || (int)g2[G].size() == 1) continue;
		if ((int)g2[G].size() == 2) return 0;
		auto& v = g2[G];
		int m = v.size();
		int cnt = 0;
		for (int i = 0;i < m;i++) {
			for (int j = i + 1;j < m;j++) {
				if (B[v[i]][v[j]] != 2) return 0;
			}
		}
		for (int i = 0;i < m;i++) {
			ans[v[(i + 1) % m]][v[i]] = ans[v[i]][v[(i + 1) % m]] = 1;
		}
	}
	build(ans);
	return 1;
}

Compilation message

supertrees.cpp: In function 'int construct(std::vector<std::vector<int> >)':
supertrees.cpp:36:7: warning: unused variable 'cnt' [-Wunused-variable]
   36 |   int cnt = 0;
      |       ^~~
supertrees.cpp:64:7: warning: unused variable 'cnt' [-Wunused-variable]
   64 |   int cnt = 0;
      |       ^~~
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 344 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 7 ms 1116 KB Output is correct
7 Correct 103 ms 22100 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 344 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 7 ms 1116 KB Output is correct
7 Correct 103 ms 22100 KB Output is correct
8 Correct 0 ms 344 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 0 ms 348 KB Output is correct
12 Correct 5 ms 1112 KB Output is correct
13 Correct 114 ms 22176 KB Output is correct
14 Correct 1 ms 344 KB Output is correct
15 Correct 0 ms 348 KB Output is correct
16 Correct 3 ms 856 KB Output is correct
17 Correct 56 ms 12300 KB Output is correct
18 Correct 0 ms 348 KB Output is correct
19 Correct 0 ms 348 KB Output is correct
20 Correct 28 ms 5724 KB Output is correct
21 Correct 107 ms 22096 KB Output is correct
22 Correct 130 ms 22100 KB Output is correct
23 Correct 115 ms 22044 KB Output is correct
24 Correct 108 ms 22076 KB Output is correct
25 Correct 48 ms 12060 KB Output is correct
26 Correct 59 ms 12300 KB Output is correct
27 Correct 144 ms 22040 KB Output is correct
28 Correct 107 ms 22096 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 344 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 7 ms 1116 KB Output is correct
9 Correct 108 ms 22232 KB Output is correct
10 Correct 0 ms 344 KB Output is correct
11 Correct 0 ms 348 KB Output is correct
12 Correct 5 ms 1116 KB Output is correct
13 Correct 114 ms 22284 KB Output is correct
14 Correct 0 ms 348 KB Output is correct
15 Correct 0 ms 348 KB Output is correct
16 Correct 3 ms 860 KB Output is correct
17 Correct 58 ms 12304 KB Output is correct
18 Correct 0 ms 348 KB Output is correct
19 Correct 0 ms 348 KB Output is correct
20 Correct 0 ms 348 KB Output is correct
21 Correct 27 ms 5732 KB Output is correct
22 Correct 110 ms 22100 KB Output is correct
23 Correct 110 ms 22100 KB Output is correct
24 Correct 124 ms 22100 KB Output is correct
25 Correct 48 ms 12372 KB Output is correct
26 Correct 49 ms 12300 KB Output is correct
27 Correct 113 ms 22196 KB Output is correct
28 Correct 114 ms 22148 KB Output is correct
29 Correct 44 ms 12368 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 27 ms 5712 KB Output is correct
5 Correct 113 ms 22100 KB Output is correct
6 Correct 110 ms 22044 KB Output is correct
7 Correct 123 ms 22100 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 27 ms 5936 KB Output is correct
10 Correct 110 ms 22252 KB Output is correct
11 Correct 115 ms 22100 KB Output is correct
12 Correct 116 ms 22284 KB Output is correct
13 Correct 0 ms 348 KB Output is correct
14 Correct 1 ms 344 KB Output is correct
15 Correct 0 ms 348 KB Output is correct
16 Correct 37 ms 5936 KB Output is correct
17 Correct 110 ms 22160 KB Output is correct
18 Correct 108 ms 22032 KB Output is correct
19 Correct 114 ms 22100 KB Output is correct
20 Correct 110 ms 22100 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 344 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 7 ms 1116 KB Output is correct
7 Correct 103 ms 22100 KB Output is correct
8 Correct 0 ms 344 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 0 ms 348 KB Output is correct
12 Correct 5 ms 1112 KB Output is correct
13 Correct 114 ms 22176 KB Output is correct
14 Correct 1 ms 344 KB Output is correct
15 Correct 0 ms 348 KB Output is correct
16 Correct 3 ms 856 KB Output is correct
17 Correct 56 ms 12300 KB Output is correct
18 Correct 0 ms 348 KB Output is correct
19 Correct 0 ms 348 KB Output is correct
20 Correct 28 ms 5724 KB Output is correct
21 Correct 107 ms 22096 KB Output is correct
22 Correct 130 ms 22100 KB Output is correct
23 Correct 115 ms 22044 KB Output is correct
24 Correct 108 ms 22076 KB Output is correct
25 Correct 48 ms 12060 KB Output is correct
26 Correct 59 ms 12300 KB Output is correct
27 Correct 144 ms 22040 KB Output is correct
28 Correct 107 ms 22096 KB Output is correct
29 Correct 0 ms 348 KB Output is correct
30 Correct 0 ms 348 KB Output is correct
31 Correct 0 ms 348 KB Output is correct
32 Correct 0 ms 348 KB Output is correct
33 Correct 0 ms 344 KB Output is correct
34 Correct 0 ms 348 KB Output is correct
35 Correct 0 ms 348 KB Output is correct
36 Correct 7 ms 1116 KB Output is correct
37 Correct 108 ms 22232 KB Output is correct
38 Correct 0 ms 344 KB Output is correct
39 Correct 0 ms 348 KB Output is correct
40 Correct 5 ms 1116 KB Output is correct
41 Correct 114 ms 22284 KB Output is correct
42 Correct 0 ms 348 KB Output is correct
43 Correct 0 ms 348 KB Output is correct
44 Correct 3 ms 860 KB Output is correct
45 Correct 58 ms 12304 KB Output is correct
46 Correct 0 ms 348 KB Output is correct
47 Correct 0 ms 348 KB Output is correct
48 Correct 0 ms 348 KB Output is correct
49 Correct 27 ms 5732 KB Output is correct
50 Correct 110 ms 22100 KB Output is correct
51 Correct 110 ms 22100 KB Output is correct
52 Correct 124 ms 22100 KB Output is correct
53 Correct 48 ms 12372 KB Output is correct
54 Correct 49 ms 12300 KB Output is correct
55 Correct 113 ms 22196 KB Output is correct
56 Correct 114 ms 22148 KB Output is correct
57 Correct 44 ms 12368 KB Output is correct
58 Correct 0 ms 348 KB Output is correct
59 Correct 0 ms 348 KB Output is correct
60 Correct 2 ms 860 KB Output is correct
61 Correct 54 ms 12296 KB Output is correct
62 Correct 0 ms 348 KB Output is correct
63 Correct 0 ms 348 KB Output is correct
64 Correct 0 ms 348 KB Output is correct
65 Correct 27 ms 5784 KB Output is correct
66 Correct 51 ms 12368 KB Output is correct
67 Correct 109 ms 12112 KB Output is correct
68 Correct 46 ms 12316 KB Output is correct
69 Correct 44 ms 12368 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 344 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 7 ms 1116 KB Output is correct
7 Correct 103 ms 22100 KB Output is correct
8 Correct 0 ms 344 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 0 ms 348 KB Output is correct
12 Correct 5 ms 1112 KB Output is correct
13 Correct 114 ms 22176 KB Output is correct
14 Correct 1 ms 344 KB Output is correct
15 Correct 0 ms 348 KB Output is correct
16 Correct 3 ms 856 KB Output is correct
17 Correct 56 ms 12300 KB Output is correct
18 Correct 0 ms 348 KB Output is correct
19 Correct 0 ms 348 KB Output is correct
20 Correct 28 ms 5724 KB Output is correct
21 Correct 107 ms 22096 KB Output is correct
22 Correct 130 ms 22100 KB Output is correct
23 Correct 115 ms 22044 KB Output is correct
24 Correct 108 ms 22076 KB Output is correct
25 Correct 48 ms 12060 KB Output is correct
26 Correct 59 ms 12300 KB Output is correct
27 Correct 144 ms 22040 KB Output is correct
28 Correct 107 ms 22096 KB Output is correct
29 Correct 0 ms 348 KB Output is correct
30 Correct 0 ms 348 KB Output is correct
31 Correct 0 ms 348 KB Output is correct
32 Correct 0 ms 348 KB Output is correct
33 Correct 0 ms 344 KB Output is correct
34 Correct 0 ms 348 KB Output is correct
35 Correct 0 ms 348 KB Output is correct
36 Correct 7 ms 1116 KB Output is correct
37 Correct 108 ms 22232 KB Output is correct
38 Correct 0 ms 344 KB Output is correct
39 Correct 0 ms 348 KB Output is correct
40 Correct 5 ms 1116 KB Output is correct
41 Correct 114 ms 22284 KB Output is correct
42 Correct 0 ms 348 KB Output is correct
43 Correct 0 ms 348 KB Output is correct
44 Correct 3 ms 860 KB Output is correct
45 Correct 58 ms 12304 KB Output is correct
46 Correct 0 ms 348 KB Output is correct
47 Correct 0 ms 348 KB Output is correct
48 Correct 0 ms 348 KB Output is correct
49 Correct 27 ms 5732 KB Output is correct
50 Correct 110 ms 22100 KB Output is correct
51 Correct 110 ms 22100 KB Output is correct
52 Correct 124 ms 22100 KB Output is correct
53 Correct 48 ms 12372 KB Output is correct
54 Correct 49 ms 12300 KB Output is correct
55 Correct 113 ms 22196 KB Output is correct
56 Correct 114 ms 22148 KB Output is correct
57 Correct 44 ms 12368 KB Output is correct
58 Correct 0 ms 348 KB Output is correct
59 Correct 0 ms 348 KB Output is correct
60 Correct 0 ms 348 KB Output is correct
61 Correct 27 ms 5712 KB Output is correct
62 Correct 113 ms 22100 KB Output is correct
63 Correct 110 ms 22044 KB Output is correct
64 Correct 123 ms 22100 KB Output is correct
65 Correct 0 ms 348 KB Output is correct
66 Correct 27 ms 5936 KB Output is correct
67 Correct 110 ms 22252 KB Output is correct
68 Correct 115 ms 22100 KB Output is correct
69 Correct 116 ms 22284 KB Output is correct
70 Correct 0 ms 348 KB Output is correct
71 Correct 1 ms 344 KB Output is correct
72 Correct 0 ms 348 KB Output is correct
73 Correct 37 ms 5936 KB Output is correct
74 Correct 110 ms 22160 KB Output is correct
75 Correct 108 ms 22032 KB Output is correct
76 Correct 114 ms 22100 KB Output is correct
77 Correct 110 ms 22100 KB Output is correct
78 Correct 0 ms 348 KB Output is correct
79 Correct 0 ms 348 KB Output is correct
80 Correct 2 ms 860 KB Output is correct
81 Correct 54 ms 12296 KB Output is correct
82 Correct 0 ms 348 KB Output is correct
83 Correct 0 ms 348 KB Output is correct
84 Correct 0 ms 348 KB Output is correct
85 Correct 27 ms 5784 KB Output is correct
86 Correct 51 ms 12368 KB Output is correct
87 Correct 109 ms 12112 KB Output is correct
88 Correct 46 ms 12316 KB Output is correct
89 Correct 44 ms 12368 KB Output is correct
90 Correct 0 ms 344 KB Output is correct
91 Correct 0 ms 348 KB Output is correct
92 Correct 2 ms 860 KB Output is correct
93 Correct 59 ms 12056 KB Output is correct
94 Correct 0 ms 348 KB Output is correct
95 Correct 0 ms 348 KB Output is correct
96 Correct 0 ms 348 KB Output is correct
97 Correct 12 ms 3720 KB Output is correct
98 Correct 48 ms 14224 KB Output is correct
99 Correct 47 ms 14088 KB Output is correct
100 Correct 47 ms 14160 KB Output is correct
101 Correct 51 ms 14208 KB Output is correct
102 Correct 43 ms 14088 KB Output is correct
103 Correct 47 ms 14168 KB Output is correct
104 Correct 46 ms 14228 KB Output is correct
105 Correct 53 ms 14220 KB Output is correct