Submission #431192

# Submission time Handle Problem Language Result Execution time Memory
431192 2021-06-17T10:13:51 Z saleh Connecting Supertrees (IOI20_supertrees) C++17
100 / 100
346 ms 22380 KB
#include "supertrees.h"//
#include <bits/stdc++.h>


using namespace std;

const int MAXN = 1000 + 23;

vector<int> v[MAXN], v2[MAXN];
set<int> r, r2;
int n, num1[MAXN], num2[MAXN];// par[MAXN],
bitset<MAXN> b2[MAXN];


int construct(vector<vector<int>> p) {
	n = p.size();
	for (int i = 0; i < n; i++) for (int j = 0; j < n; j++) if (p[i][j] == 3) return 0;
	for (int i = 0; i < n; i++) r.insert(i), v[i].push_back(i);
	for (int i = 0; i < n; i++) for (int j = 0; j < n; j++) if (p[i][j] == 1) num1[i]++;
	for (int i = 0; i < n; i++) if (r.find(i) != r.end()) for (int j = i + 1; j < n; j++) if (r.find(j) != r.end()) if (p[i][j] == 1) {
		while (v[j].size()) {
//			par[v[j].back()] = i;
			v[i].push_back(v[j].back());
			v[j].pop_back();
		}
		r.erase(j);
	}
	vector<vector<int>> ans;
	for (int i = 0; i < n; i++) {
		vector<int> row;
		row.resize(n);
		ans.push_back(row);
	}
	for (auto i : r) r2.insert(i), v2[i].push_back(i);
	for (auto i : r) {
		for (auto j : v[i]) for (auto k : v[i]) if (p[k][j] != 1) return 0;
		for (auto j : v[i]) if (num1[j] != (int)v[i].size()) return 0;
		for (int j = 1; j < (int)v[i].size(); j++) ans[v[i][j - 1]][v[i][j]] = ans[v[i][j]][v[i][j - 1]] = 1;
	}
	for (auto i : r) for (auto j : r) if (i < j) {
		int tmp = 0;
		for (auto a : v[i]) for (auto b : v[j]) tmp |= (1 << p[a][b]);
		if (tmp == 5) return 0;
		if (tmp == 4) {
			b2[i][j] = b2[j][i] = true;
			num2[i]++;
			num2[j]++;
		}
	}//upper is checked
	for (auto i : r) if (r2.find(i) != r2.end()) for (auto j : r) if (i < j && r2.find(j) != r2.end()) if (b2[i][j]) {
		while (v2[j].size()) {
			v2[i].push_back(v2[j].back());
			v2[j].pop_back();
		}
		r2.erase(j);	
	}
	for (auto i : r2) {
		if (v2[i].size() < 2) continue;
		for (auto j : v2[i]) for (auto k : v2[i]) if (j != k && !b2[k][j]) return 0;
		for (auto j : v2[i]) if (num2[j] != (int)v2[i].size() - 1) return 0;
		if (v2[i].size() == 2) return 0;
		for (int j = 1; j < (int)v2[i].size(); j++) ans[v2[i][j - 1]][v2[i][j]] = ans[v2[i][j]][v2[i][j - 1]] = 1;
		ans[v2[i][v2[i].size() - 1]][v2[i][0]] = ans[v2[i][0]][v2[i][v2[i].size() - 1]] = 1;
	}
//	for (int i = 0; i < n; i++) for (int j = i + 1; j < n; j++) if (ans[i][j] == true) cout << i << ' ' << j << endl;//
	build(ans);//
	return 1;
}
//int main() {cout << construct({{1, 2, 2, 0, 0, 0}, {2, 1, 2, 0, 0, 0}, {2, 2, 1, 0, 0, 0}, {0, 0, 0, 1, 2, 2}, {0, 0, 0, 2, 1, 2}, {0, 0, 0, 2, 2, 1}});}//
# Verdict Execution time Memory Grader output
1 Correct 0 ms 332 KB Output is correct
2 Correct 1 ms 332 KB Output is correct
3 Correct 0 ms 332 KB Output is correct
4 Correct 0 ms 332 KB Output is correct
5 Correct 1 ms 332 KB Output is correct
6 Correct 11 ms 1204 KB Output is correct
7 Correct 234 ms 22204 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 332 KB Output is correct
2 Correct 1 ms 332 KB Output is correct
3 Correct 0 ms 332 KB Output is correct
4 Correct 0 ms 332 KB Output is correct
5 Correct 1 ms 332 KB Output is correct
6 Correct 11 ms 1204 KB Output is correct
7 Correct 234 ms 22204 KB Output is correct
8 Correct 1 ms 332 KB Output is correct
9 Correct 1 ms 332 KB Output is correct
10 Correct 1 ms 332 KB Output is correct
11 Correct 1 ms 332 KB Output is correct
12 Correct 14 ms 1276 KB Output is correct
13 Correct 279 ms 22300 KB Output is correct
14 Correct 0 ms 332 KB Output is correct
15 Correct 0 ms 332 KB Output is correct
16 Correct 5 ms 844 KB Output is correct
17 Correct 118 ms 12212 KB Output is correct
18 Correct 1 ms 332 KB Output is correct
19 Correct 1 ms 332 KB Output is correct
20 Correct 73 ms 5812 KB Output is correct
21 Correct 237 ms 22068 KB Output is correct
22 Correct 251 ms 22180 KB Output is correct
23 Correct 259 ms 22112 KB Output is correct
24 Correct 294 ms 22212 KB Output is correct
25 Correct 108 ms 12208 KB Output is correct
26 Correct 123 ms 12276 KB Output is correct
27 Correct 251 ms 22100 KB Output is correct
28 Correct 313 ms 22220 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 332 KB Output is correct
2 Correct 1 ms 332 KB Output is correct
3 Correct 1 ms 332 KB Output is correct
4 Correct 1 ms 332 KB Output is correct
5 Correct 1 ms 332 KB Output is correct
6 Correct 1 ms 332 KB Output is correct
7 Correct 1 ms 332 KB Output is correct
8 Correct 14 ms 1252 KB Output is correct
9 Correct 304 ms 22144 KB Output is correct
10 Correct 1 ms 332 KB Output is correct
11 Correct 1 ms 332 KB Output is correct
12 Correct 11 ms 1200 KB Output is correct
13 Correct 297 ms 22268 KB Output is correct
14 Correct 1 ms 332 KB Output is correct
15 Correct 1 ms 332 KB Output is correct
16 Correct 6 ms 844 KB Output is correct
17 Correct 147 ms 12468 KB Output is correct
18 Correct 1 ms 332 KB Output is correct
19 Correct 1 ms 332 KB Output is correct
20 Correct 1 ms 332 KB Output is correct
21 Correct 75 ms 5896 KB Output is correct
22 Correct 292 ms 22376 KB Output is correct
23 Correct 275 ms 22336 KB Output is correct
24 Correct 299 ms 22368 KB Output is correct
25 Correct 138 ms 12404 KB Output is correct
26 Correct 158 ms 12448 KB Output is correct
27 Correct 319 ms 22308 KB Output is correct
28 Correct 310 ms 22324 KB Output is correct
29 Correct 137 ms 12448 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 332 KB Output is correct
2 Correct 0 ms 332 KB Output is correct
3 Correct 1 ms 332 KB Output is correct
4 Correct 67 ms 5864 KB Output is correct
5 Correct 254 ms 22184 KB Output is correct
6 Correct 307 ms 22176 KB Output is correct
7 Correct 256 ms 22196 KB Output is correct
8 Correct 1 ms 332 KB Output is correct
9 Correct 66 ms 5848 KB Output is correct
10 Correct 306 ms 22320 KB Output is correct
11 Correct 346 ms 22340 KB Output is correct
12 Correct 270 ms 22352 KB Output is correct
13 Correct 0 ms 332 KB Output is correct
14 Correct 0 ms 332 KB Output is correct
15 Correct 1 ms 332 KB Output is correct
16 Correct 63 ms 5884 KB Output is correct
17 Correct 279 ms 22380 KB Output is correct
18 Correct 271 ms 22332 KB Output is correct
19 Correct 295 ms 22348 KB Output is correct
20 Correct 288 ms 22320 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 332 KB Output is correct
2 Correct 1 ms 332 KB Output is correct
3 Correct 0 ms 332 KB Output is correct
4 Correct 0 ms 332 KB Output is correct
5 Correct 1 ms 332 KB Output is correct
6 Correct 11 ms 1204 KB Output is correct
7 Correct 234 ms 22204 KB Output is correct
8 Correct 1 ms 332 KB Output is correct
9 Correct 1 ms 332 KB Output is correct
10 Correct 1 ms 332 KB Output is correct
11 Correct 1 ms 332 KB Output is correct
12 Correct 14 ms 1276 KB Output is correct
13 Correct 279 ms 22300 KB Output is correct
14 Correct 0 ms 332 KB Output is correct
15 Correct 0 ms 332 KB Output is correct
16 Correct 5 ms 844 KB Output is correct
17 Correct 118 ms 12212 KB Output is correct
18 Correct 1 ms 332 KB Output is correct
19 Correct 1 ms 332 KB Output is correct
20 Correct 73 ms 5812 KB Output is correct
21 Correct 237 ms 22068 KB Output is correct
22 Correct 251 ms 22180 KB Output is correct
23 Correct 259 ms 22112 KB Output is correct
24 Correct 294 ms 22212 KB Output is correct
25 Correct 108 ms 12208 KB Output is correct
26 Correct 123 ms 12276 KB Output is correct
27 Correct 251 ms 22100 KB Output is correct
28 Correct 313 ms 22220 KB Output is correct
29 Correct 1 ms 332 KB Output is correct
30 Correct 1 ms 332 KB Output is correct
31 Correct 1 ms 332 KB Output is correct
32 Correct 1 ms 332 KB Output is correct
33 Correct 1 ms 332 KB Output is correct
34 Correct 1 ms 332 KB Output is correct
35 Correct 1 ms 332 KB Output is correct
36 Correct 14 ms 1252 KB Output is correct
37 Correct 304 ms 22144 KB Output is correct
38 Correct 1 ms 332 KB Output is correct
39 Correct 1 ms 332 KB Output is correct
40 Correct 11 ms 1200 KB Output is correct
41 Correct 297 ms 22268 KB Output is correct
42 Correct 1 ms 332 KB Output is correct
43 Correct 1 ms 332 KB Output is correct
44 Correct 6 ms 844 KB Output is correct
45 Correct 147 ms 12468 KB Output is correct
46 Correct 1 ms 332 KB Output is correct
47 Correct 1 ms 332 KB Output is correct
48 Correct 1 ms 332 KB Output is correct
49 Correct 75 ms 5896 KB Output is correct
50 Correct 292 ms 22376 KB Output is correct
51 Correct 275 ms 22336 KB Output is correct
52 Correct 299 ms 22368 KB Output is correct
53 Correct 138 ms 12404 KB Output is correct
54 Correct 158 ms 12448 KB Output is correct
55 Correct 319 ms 22308 KB Output is correct
56 Correct 310 ms 22324 KB Output is correct
57 Correct 137 ms 12448 KB Output is correct
58 Correct 0 ms 332 KB Output is correct
59 Correct 0 ms 332 KB Output is correct
60 Correct 5 ms 844 KB Output is correct
61 Correct 109 ms 12220 KB Output is correct
62 Correct 0 ms 332 KB Output is correct
63 Correct 1 ms 332 KB Output is correct
64 Correct 1 ms 332 KB Output is correct
65 Correct 73 ms 6424 KB Output is correct
66 Correct 117 ms 14380 KB Output is correct
67 Correct 130 ms 14296 KB Output is correct
68 Correct 122 ms 14380 KB Output is correct
69 Correct 143 ms 14260 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 332 KB Output is correct
2 Correct 1 ms 332 KB Output is correct
3 Correct 0 ms 332 KB Output is correct
4 Correct 0 ms 332 KB Output is correct
5 Correct 1 ms 332 KB Output is correct
6 Correct 11 ms 1204 KB Output is correct
7 Correct 234 ms 22204 KB Output is correct
8 Correct 1 ms 332 KB Output is correct
9 Correct 1 ms 332 KB Output is correct
10 Correct 1 ms 332 KB Output is correct
11 Correct 1 ms 332 KB Output is correct
12 Correct 14 ms 1276 KB Output is correct
13 Correct 279 ms 22300 KB Output is correct
14 Correct 0 ms 332 KB Output is correct
15 Correct 0 ms 332 KB Output is correct
16 Correct 5 ms 844 KB Output is correct
17 Correct 118 ms 12212 KB Output is correct
18 Correct 1 ms 332 KB Output is correct
19 Correct 1 ms 332 KB Output is correct
20 Correct 73 ms 5812 KB Output is correct
21 Correct 237 ms 22068 KB Output is correct
22 Correct 251 ms 22180 KB Output is correct
23 Correct 259 ms 22112 KB Output is correct
24 Correct 294 ms 22212 KB Output is correct
25 Correct 108 ms 12208 KB Output is correct
26 Correct 123 ms 12276 KB Output is correct
27 Correct 251 ms 22100 KB Output is correct
28 Correct 313 ms 22220 KB Output is correct
29 Correct 1 ms 332 KB Output is correct
30 Correct 1 ms 332 KB Output is correct
31 Correct 1 ms 332 KB Output is correct
32 Correct 1 ms 332 KB Output is correct
33 Correct 1 ms 332 KB Output is correct
34 Correct 1 ms 332 KB Output is correct
35 Correct 1 ms 332 KB Output is correct
36 Correct 14 ms 1252 KB Output is correct
37 Correct 304 ms 22144 KB Output is correct
38 Correct 1 ms 332 KB Output is correct
39 Correct 1 ms 332 KB Output is correct
40 Correct 11 ms 1200 KB Output is correct
41 Correct 297 ms 22268 KB Output is correct
42 Correct 1 ms 332 KB Output is correct
43 Correct 1 ms 332 KB Output is correct
44 Correct 6 ms 844 KB Output is correct
45 Correct 147 ms 12468 KB Output is correct
46 Correct 1 ms 332 KB Output is correct
47 Correct 1 ms 332 KB Output is correct
48 Correct 1 ms 332 KB Output is correct
49 Correct 75 ms 5896 KB Output is correct
50 Correct 292 ms 22376 KB Output is correct
51 Correct 275 ms 22336 KB Output is correct
52 Correct 299 ms 22368 KB Output is correct
53 Correct 138 ms 12404 KB Output is correct
54 Correct 158 ms 12448 KB Output is correct
55 Correct 319 ms 22308 KB Output is correct
56 Correct 310 ms 22324 KB Output is correct
57 Correct 137 ms 12448 KB Output is correct
58 Correct 0 ms 332 KB Output is correct
59 Correct 0 ms 332 KB Output is correct
60 Correct 1 ms 332 KB Output is correct
61 Correct 67 ms 5864 KB Output is correct
62 Correct 254 ms 22184 KB Output is correct
63 Correct 307 ms 22176 KB Output is correct
64 Correct 256 ms 22196 KB Output is correct
65 Correct 1 ms 332 KB Output is correct
66 Correct 66 ms 5848 KB Output is correct
67 Correct 306 ms 22320 KB Output is correct
68 Correct 346 ms 22340 KB Output is correct
69 Correct 270 ms 22352 KB Output is correct
70 Correct 0 ms 332 KB Output is correct
71 Correct 0 ms 332 KB Output is correct
72 Correct 1 ms 332 KB Output is correct
73 Correct 63 ms 5884 KB Output is correct
74 Correct 279 ms 22380 KB Output is correct
75 Correct 271 ms 22332 KB Output is correct
76 Correct 295 ms 22348 KB Output is correct
77 Correct 288 ms 22320 KB Output is correct
78 Correct 0 ms 332 KB Output is correct
79 Correct 0 ms 332 KB Output is correct
80 Correct 5 ms 844 KB Output is correct
81 Correct 109 ms 12220 KB Output is correct
82 Correct 0 ms 332 KB Output is correct
83 Correct 1 ms 332 KB Output is correct
84 Correct 1 ms 332 KB Output is correct
85 Correct 73 ms 6424 KB Output is correct
86 Correct 117 ms 14380 KB Output is correct
87 Correct 130 ms 14296 KB Output is correct
88 Correct 122 ms 14380 KB Output is correct
89 Correct 143 ms 14260 KB Output is correct
90 Correct 1 ms 344 KB Output is correct
91 Correct 1 ms 332 KB Output is correct
92 Correct 5 ms 716 KB Output is correct
93 Correct 108 ms 10156 KB Output is correct
94 Correct 1 ms 332 KB Output is correct
95 Correct 1 ms 332 KB Output is correct
96 Correct 1 ms 332 KB Output is correct
97 Correct 25 ms 2756 KB Output is correct
98 Correct 129 ms 10184 KB Output is correct
99 Correct 104 ms 10148 KB Output is correct
100 Correct 92 ms 10156 KB Output is correct
101 Correct 103 ms 10164 KB Output is correct
102 Correct 132 ms 10160 KB Output is correct
103 Correct 97 ms 10156 KB Output is correct
104 Correct 95 ms 10160 KB Output is correct
105 Correct 109 ms 10152 KB Output is correct