Submission #414550

# Submission time Handle Problem Language Result Execution time Memory
414550 2021-05-30T16:04:27 Z InternetPerson10 Connecting Supertrees (IOI20_supertrees) C++14
100 / 100
251 ms 24064 KB
#include "supertrees.h"
#include <bits/stdc++.h>

using namespace std;

bool taken[1001];
int nums[1001], cycs[1001];

vector<vector<int>> paths;
vector<vector<int>> cycles;
vector<vector<int>> ans;

int construct(std::vector<std::vector<int>> p) {
	vector<vector<int>>().swap(paths);
	vector<vector<int>>().swap(cycles);
	vector<vector<int>>().swap(ans);
	int n = p.size();
	ans.resize(n);
	for(int i = 0; i < n; i++) {
		ans[i].resize(n);
		if(!taken[i]) {
			taken[i] = true;
			nums[i] = paths.size();
			paths.push_back(vector<int>());
			for(int j = i; j < n; j++) {
				if(p[i][j] == 1) {
					paths[nums[i]].push_back(j);
					taken[j] = true;
					nums[j] = nums[i];
				}
			}
		}
	}
	// for(int i = 0; i < n; i++) cout << nums[i] << ' ';
	// cout << '\n';
	for(int i = 0; i < n; i++) taken[i] = false;
	for(int i = 0; i < (int)paths.size(); i++) {
		if(!taken[i]) {
			taken[i] = true;
			cycles.push_back(vector<int>());
			cycles[cycles.size() - 1].push_back(i);
			cycs[i] = cycles.size() - 1;
			for(int j = i+1; j < (int)paths.size(); j++) {
				if(p[paths[i][0]][paths[j][0]] == 2) {
					taken[j] = true;
					cycles[cycles.size() - 1].push_back(j);
					cycs[j] = cycles.size() - 1;
				}
			}
		}
	}
	// cout << "yehey\n";
	// for(int i = 0; i < n; i++) cout << cycs[i] << ' ';
	// cout << '\n';
	bool sad = false;
	for(int i = 0; i < n; i++) {
		for(int j = 0; j < n; j++) {
			int pi = nums[i], pj = nums[j];
			int ci = cycs[pi], cj = cycs[pj];
			if(p[i][j] == 0) {
				if(pi == pj || ci == cj) sad = true;
			}
			else if(p[i][j] == 1) {
				if(pi != pj) sad = true;
			}
			else if(p[i][j] == 2) {
				if(pi == pj || ci != cj) sad = true;
			}
			else {
				sad = true;
			}
		}
	}
	for(int i = 0; i < (int)cycles.size(); i++) {
		if(cycles[i].size() == 2) sad = true;
	}
	if(sad) {
		return 0;
	}
	// cout << "Yehey\n";
	for(int i = 0; i < (int)paths.size(); i++) {
		for(int j = 1; j < (int)paths[i].size(); j++) {
			ans[paths[i][j]][paths[i][j-1]] = 1;
			ans[paths[i][j-1]][paths[i][j]] = 1;
		}
	}
	for(int i = 0; i < (int)cycles.size(); i++) {
		if(cycles[i].size() == 1) continue;
		ans[paths[cycles[i][0]][0]][paths[cycles[i][cycles[i].size() - 1]][0]] = 1;
		ans[paths[cycles[i][cycles[i].size() - 1]][0]][paths[cycles[i][0]][0]] = 1;
		for(int j = 1; j < (int)cycles[i].size(); j++) {
			ans[paths[cycles[i][j-1]][0]][paths[cycles[i][j]][0]] = 1;
			ans[paths[cycles[i][j]][0]][paths[cycles[i][j-1]][0]] = 1;
		}
	}
	build(ans);
	return 1;
}
# Verdict Execution time Memory Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 1 ms 204 KB Output is correct
3 Correct 1 ms 296 KB Output is correct
4 Correct 1 ms 296 KB Output is correct
5 Correct 1 ms 204 KB Output is correct
6 Correct 11 ms 1172 KB Output is correct
7 Correct 232 ms 22768 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 1 ms 204 KB Output is correct
3 Correct 1 ms 296 KB Output is correct
4 Correct 1 ms 296 KB Output is correct
5 Correct 1 ms 204 KB Output is correct
6 Correct 11 ms 1172 KB Output is correct
7 Correct 232 ms 22768 KB Output is correct
8 Correct 1 ms 204 KB Output is correct
9 Correct 1 ms 204 KB Output is correct
10 Correct 1 ms 204 KB Output is correct
11 Correct 1 ms 204 KB Output is correct
12 Correct 11 ms 1228 KB Output is correct
13 Correct 228 ms 22860 KB Output is correct
14 Correct 1 ms 204 KB Output is correct
15 Correct 1 ms 204 KB Output is correct
16 Correct 5 ms 820 KB Output is correct
17 Correct 108 ms 12892 KB Output is correct
18 Correct 1 ms 204 KB Output is correct
19 Correct 1 ms 204 KB Output is correct
20 Correct 59 ms 6256 KB Output is correct
21 Correct 244 ms 22864 KB Output is correct
22 Correct 230 ms 22852 KB Output is correct
23 Correct 243 ms 22724 KB Output is correct
24 Correct 240 ms 22900 KB Output is correct
25 Correct 99 ms 12852 KB Output is correct
26 Correct 97 ms 12884 KB Output is correct
27 Correct 233 ms 22784 KB Output is correct
28 Correct 249 ms 22816 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 1 ms 204 KB Output is correct
3 Correct 1 ms 204 KB Output is correct
4 Correct 1 ms 204 KB Output is correct
5 Correct 1 ms 204 KB Output is correct
6 Correct 1 ms 204 KB Output is correct
7 Correct 1 ms 204 KB Output is correct
8 Correct 11 ms 1224 KB Output is correct
9 Correct 229 ms 24048 KB Output is correct
10 Correct 1 ms 204 KB Output is correct
11 Correct 1 ms 296 KB Output is correct
12 Correct 10 ms 1216 KB Output is correct
13 Correct 230 ms 24064 KB Output is correct
14 Correct 1 ms 204 KB Output is correct
15 Correct 1 ms 204 KB Output is correct
16 Correct 5 ms 844 KB Output is correct
17 Correct 110 ms 14072 KB Output is correct
18 Correct 1 ms 296 KB Output is correct
19 Correct 1 ms 204 KB Output is correct
20 Correct 1 ms 204 KB Output is correct
21 Correct 60 ms 6256 KB Output is correct
22 Correct 233 ms 24048 KB Output is correct
23 Correct 229 ms 24060 KB Output is correct
24 Correct 251 ms 24044 KB Output is correct
25 Correct 99 ms 14148 KB Output is correct
26 Correct 99 ms 14060 KB Output is correct
27 Correct 227 ms 24056 KB Output is correct
28 Correct 244 ms 23992 KB Output is correct
29 Correct 97 ms 14192 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 1 ms 204 KB Output is correct
3 Correct 1 ms 204 KB Output is correct
4 Correct 58 ms 6220 KB Output is correct
5 Correct 228 ms 22724 KB Output is correct
6 Correct 226 ms 22852 KB Output is correct
7 Correct 239 ms 22724 KB Output is correct
8 Correct 1 ms 204 KB Output is correct
9 Correct 63 ms 6212 KB Output is correct
10 Correct 230 ms 22828 KB Output is correct
11 Correct 227 ms 22872 KB Output is correct
12 Correct 236 ms 22800 KB Output is correct
13 Correct 1 ms 204 KB Output is correct
14 Correct 1 ms 204 KB Output is correct
15 Correct 1 ms 204 KB Output is correct
16 Correct 60 ms 6248 KB Output is correct
17 Correct 241 ms 22808 KB Output is correct
18 Correct 234 ms 22824 KB Output is correct
19 Correct 227 ms 22788 KB Output is correct
20 Correct 234 ms 23032 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 1 ms 204 KB Output is correct
3 Correct 1 ms 296 KB Output is correct
4 Correct 1 ms 296 KB Output is correct
5 Correct 1 ms 204 KB Output is correct
6 Correct 11 ms 1172 KB Output is correct
7 Correct 232 ms 22768 KB Output is correct
8 Correct 1 ms 204 KB Output is correct
9 Correct 1 ms 204 KB Output is correct
10 Correct 1 ms 204 KB Output is correct
11 Correct 1 ms 204 KB Output is correct
12 Correct 11 ms 1228 KB Output is correct
13 Correct 228 ms 22860 KB Output is correct
14 Correct 1 ms 204 KB Output is correct
15 Correct 1 ms 204 KB Output is correct
16 Correct 5 ms 820 KB Output is correct
17 Correct 108 ms 12892 KB Output is correct
18 Correct 1 ms 204 KB Output is correct
19 Correct 1 ms 204 KB Output is correct
20 Correct 59 ms 6256 KB Output is correct
21 Correct 244 ms 22864 KB Output is correct
22 Correct 230 ms 22852 KB Output is correct
23 Correct 243 ms 22724 KB Output is correct
24 Correct 240 ms 22900 KB Output is correct
25 Correct 99 ms 12852 KB Output is correct
26 Correct 97 ms 12884 KB Output is correct
27 Correct 233 ms 22784 KB Output is correct
28 Correct 249 ms 22816 KB Output is correct
29 Correct 1 ms 204 KB Output is correct
30 Correct 1 ms 204 KB Output is correct
31 Correct 1 ms 204 KB Output is correct
32 Correct 1 ms 204 KB Output is correct
33 Correct 1 ms 204 KB Output is correct
34 Correct 1 ms 204 KB Output is correct
35 Correct 1 ms 204 KB Output is correct
36 Correct 11 ms 1224 KB Output is correct
37 Correct 229 ms 24048 KB Output is correct
38 Correct 1 ms 204 KB Output is correct
39 Correct 1 ms 296 KB Output is correct
40 Correct 10 ms 1216 KB Output is correct
41 Correct 230 ms 24064 KB Output is correct
42 Correct 1 ms 204 KB Output is correct
43 Correct 1 ms 204 KB Output is correct
44 Correct 5 ms 844 KB Output is correct
45 Correct 110 ms 14072 KB Output is correct
46 Correct 1 ms 296 KB Output is correct
47 Correct 1 ms 204 KB Output is correct
48 Correct 1 ms 204 KB Output is correct
49 Correct 60 ms 6256 KB Output is correct
50 Correct 233 ms 24048 KB Output is correct
51 Correct 229 ms 24060 KB Output is correct
52 Correct 251 ms 24044 KB Output is correct
53 Correct 99 ms 14148 KB Output is correct
54 Correct 99 ms 14060 KB Output is correct
55 Correct 227 ms 24056 KB Output is correct
56 Correct 244 ms 23992 KB Output is correct
57 Correct 97 ms 14192 KB Output is correct
58 Correct 1 ms 204 KB Output is correct
59 Correct 1 ms 204 KB Output is correct
60 Correct 5 ms 820 KB Output is correct
61 Correct 109 ms 14016 KB Output is correct
62 Correct 1 ms 204 KB Output is correct
63 Correct 1 ms 204 KB Output is correct
64 Correct 1 ms 204 KB Output is correct
65 Correct 60 ms 6256 KB Output is correct
66 Correct 115 ms 14080 KB Output is correct
67 Correct 98 ms 14020 KB Output is correct
68 Correct 96 ms 14064 KB Output is correct
69 Correct 98 ms 14188 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 1 ms 204 KB Output is correct
3 Correct 1 ms 296 KB Output is correct
4 Correct 1 ms 296 KB Output is correct
5 Correct 1 ms 204 KB Output is correct
6 Correct 11 ms 1172 KB Output is correct
7 Correct 232 ms 22768 KB Output is correct
8 Correct 1 ms 204 KB Output is correct
9 Correct 1 ms 204 KB Output is correct
10 Correct 1 ms 204 KB Output is correct
11 Correct 1 ms 204 KB Output is correct
12 Correct 11 ms 1228 KB Output is correct
13 Correct 228 ms 22860 KB Output is correct
14 Correct 1 ms 204 KB Output is correct
15 Correct 1 ms 204 KB Output is correct
16 Correct 5 ms 820 KB Output is correct
17 Correct 108 ms 12892 KB Output is correct
18 Correct 1 ms 204 KB Output is correct
19 Correct 1 ms 204 KB Output is correct
20 Correct 59 ms 6256 KB Output is correct
21 Correct 244 ms 22864 KB Output is correct
22 Correct 230 ms 22852 KB Output is correct
23 Correct 243 ms 22724 KB Output is correct
24 Correct 240 ms 22900 KB Output is correct
25 Correct 99 ms 12852 KB Output is correct
26 Correct 97 ms 12884 KB Output is correct
27 Correct 233 ms 22784 KB Output is correct
28 Correct 249 ms 22816 KB Output is correct
29 Correct 1 ms 204 KB Output is correct
30 Correct 1 ms 204 KB Output is correct
31 Correct 1 ms 204 KB Output is correct
32 Correct 1 ms 204 KB Output is correct
33 Correct 1 ms 204 KB Output is correct
34 Correct 1 ms 204 KB Output is correct
35 Correct 1 ms 204 KB Output is correct
36 Correct 11 ms 1224 KB Output is correct
37 Correct 229 ms 24048 KB Output is correct
38 Correct 1 ms 204 KB Output is correct
39 Correct 1 ms 296 KB Output is correct
40 Correct 10 ms 1216 KB Output is correct
41 Correct 230 ms 24064 KB Output is correct
42 Correct 1 ms 204 KB Output is correct
43 Correct 1 ms 204 KB Output is correct
44 Correct 5 ms 844 KB Output is correct
45 Correct 110 ms 14072 KB Output is correct
46 Correct 1 ms 296 KB Output is correct
47 Correct 1 ms 204 KB Output is correct
48 Correct 1 ms 204 KB Output is correct
49 Correct 60 ms 6256 KB Output is correct
50 Correct 233 ms 24048 KB Output is correct
51 Correct 229 ms 24060 KB Output is correct
52 Correct 251 ms 24044 KB Output is correct
53 Correct 99 ms 14148 KB Output is correct
54 Correct 99 ms 14060 KB Output is correct
55 Correct 227 ms 24056 KB Output is correct
56 Correct 244 ms 23992 KB Output is correct
57 Correct 97 ms 14192 KB Output is correct
58 Correct 1 ms 204 KB Output is correct
59 Correct 1 ms 204 KB Output is correct
60 Correct 1 ms 204 KB Output is correct
61 Correct 58 ms 6220 KB Output is correct
62 Correct 228 ms 22724 KB Output is correct
63 Correct 226 ms 22852 KB Output is correct
64 Correct 239 ms 22724 KB Output is correct
65 Correct 1 ms 204 KB Output is correct
66 Correct 63 ms 6212 KB Output is correct
67 Correct 230 ms 22828 KB Output is correct
68 Correct 227 ms 22872 KB Output is correct
69 Correct 236 ms 22800 KB Output is correct
70 Correct 1 ms 204 KB Output is correct
71 Correct 1 ms 204 KB Output is correct
72 Correct 1 ms 204 KB Output is correct
73 Correct 60 ms 6248 KB Output is correct
74 Correct 241 ms 22808 KB Output is correct
75 Correct 234 ms 22824 KB Output is correct
76 Correct 227 ms 22788 KB Output is correct
77 Correct 234 ms 23032 KB Output is correct
78 Correct 1 ms 204 KB Output is correct
79 Correct 1 ms 204 KB Output is correct
80 Correct 5 ms 820 KB Output is correct
81 Correct 109 ms 14016 KB Output is correct
82 Correct 1 ms 204 KB Output is correct
83 Correct 1 ms 204 KB Output is correct
84 Correct 1 ms 204 KB Output is correct
85 Correct 60 ms 6256 KB Output is correct
86 Correct 115 ms 14080 KB Output is correct
87 Correct 98 ms 14020 KB Output is correct
88 Correct 96 ms 14064 KB Output is correct
89 Correct 98 ms 14188 KB Output is correct
90 Correct 1 ms 204 KB Output is correct
91 Correct 1 ms 204 KB Output is correct
92 Correct 5 ms 844 KB Output is correct
93 Correct 128 ms 14060 KB Output is correct
94 Correct 1 ms 204 KB Output is correct
95 Correct 1 ms 204 KB Output is correct
96 Correct 1 ms 204 KB Output is correct
97 Correct 25 ms 3696 KB Output is correct
98 Correct 107 ms 14072 KB Output is correct
99 Correct 98 ms 14068 KB Output is correct
100 Correct 96 ms 14020 KB Output is correct
101 Correct 98 ms 14204 KB Output is correct
102 Correct 119 ms 14196 KB Output is correct
103 Correct 102 ms 14060 KB Output is correct
104 Correct 100 ms 14072 KB Output is correct
105 Correct 120 ms 14072 KB Output is correct