Submission #788291

# Submission time Handle Problem Language Result Execution time Memory
788291 2023-07-20T04:52:30 Z mindiyak Connecting Supertrees (IOI20_supertrees) C++14
100 / 100
186 ms 24080 KB
//In heads make different sets of heads



#include "supertrees.h"
#include <vector>
#include <set>
#include <iostream>

using namespace std;

vector<int> parent(1003);
vector<int> header_parent(1003);
vector<int> header_parent_current(1003);
vector<set<int>> header_counter;

int find_head(int n){
	if(parent[n] == n){
		return n;
	}return find_head(parent[n]);
}

int find_head_parent(int n){
	if(header_parent[n] == n){
		return n;
	}return find_head_parent(header_parent[n]);
}

int construct(std::vector<std::vector<int>> p) {
	int n = p.size();
	vector<vector<int>>ans(n,vector<int>(n,0));
	set<int> a;

	for (int i = 0; i < n; i++) {
		parent[i] = i;
		header_parent[i] = i;
		header_parent_current[i] = i;
		header_counter.push_back(a);
	}

	for(int i=0;i<n;i++){
		for(int j=0;j<n;j++){
			if(i==j)
				continue;
			if(p[i][j] == 3){
				return 0;
			}else if(p[i][j] == 1){
				int lower = min(i,j);
				int higher = max(i,j);
				if(find_head(lower) != find_head(higher)){
					ans[i][j] = 1;
					ans[j][i] = 1;
					parent[higher] = find_head(lower);
					header_parent[higher] = parent[higher];
				}
			}
		}
	}

	// cout <<"process 2" << endl;

	for(int i=0;i<n;i++){
		for(int j=0;j<n;j++){
			if(i==j)
				continue;
			if(p[i][j] == 2){
				int q = find_head(i);
				int m = find_head(j);
				if(q==m)
					return 0;
				if(header_parent[q] == header_parent[m])
					continue;
				int lower = min(q,m);
				int higher = max(q,m);
				ans[header_parent_current[q]][header_parent_current[m]] = 1;
				ans[header_parent_current[m]][header_parent_current[q]] = 1;
				header_parent[higher] = find_head_parent(lower);
				header_counter[header_parent[higher]].insert(higher);
				header_parent_current[header_parent[higher]] = higher;
				// cout << i << " " << j << " " << header_parent[higher] << " " << header_counter[header_parent[higher]].size() << endl;
			}
		}
	}

	for(int i=0;i<n;i++){
		if(i != header_parent_current[i]){
			ans[header_parent_current[i]][i] = 1;
			ans[i][header_parent_current[i]] = 1;
		}
	}

	// cout << "headers connected" << endl;

	// cout << endl;
	// for (int i = 0; i < n; i++) {
	// 	cout << i << " " << parent[i] << " " << header_parent[i] << " " << header_counter[i].size() << endl;
	// }
	// cout << endl;

	for(int i=0;i<n;i++){
		for(int j=0;j<n;j++){
			int i_head = find_head(i);
			int j_head = find_head(j);
			int i_head_header = find_head_parent(i_head);
			int j_head_header = find_head_parent(j_head);
			if(i==j)
				continue;
			if(p[i][j] == 0){
				if(i_head == j_head){
					return 0;
				}
				if(i_head_header == j_head_header){
					return 0;
				}
			}else if(p[i][j] == 1){
				if(i_head != j_head){
					return 0;
				}
			}else if(p[i][j] == 2){
				// cout << i << " " << j << " " << i_head_header << " " << j_head_header << endl;
				if((header_counter[i_head_header].size() < 2)){
					return 0;
				}
				if(i_head == j_head){
					return 0;
				}
				if(i_head_header != j_head_header){
					return 0;
				}
			}
		}
	}


	build(ans);
	return 1;
}
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 0 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 0 ms 212 KB Output is correct
6 Correct 7 ms 1108 KB Output is correct
7 Correct 164 ms 22016 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 0 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 0 ms 212 KB Output is correct
6 Correct 7 ms 1108 KB Output is correct
7 Correct 164 ms 22016 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 212 KB Output is correct
11 Correct 0 ms 212 KB Output is correct
12 Correct 7 ms 1108 KB Output is correct
13 Correct 159 ms 22032 KB Output is correct
14 Correct 1 ms 212 KB Output is correct
15 Correct 0 ms 212 KB Output is correct
16 Correct 4 ms 728 KB Output is correct
17 Correct 76 ms 12188 KB Output is correct
18 Correct 0 ms 212 KB Output is correct
19 Correct 0 ms 212 KB Output is correct
20 Correct 40 ms 5708 KB Output is correct
21 Correct 166 ms 22044 KB Output is correct
22 Correct 163 ms 21996 KB Output is correct
23 Correct 175 ms 22056 KB Output is correct
24 Correct 162 ms 22004 KB Output is correct
25 Correct 74 ms 12236 KB Output is correct
26 Correct 66 ms 12248 KB Output is correct
27 Correct 185 ms 22040 KB Output is correct
28 Correct 158 ms 22060 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 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 0 ms 212 KB Output is correct
6 Correct 0 ms 212 KB Output is correct
7 Correct 0 ms 212 KB Output is correct
8 Correct 8 ms 1108 KB Output is correct
9 Correct 162 ms 22040 KB Output is correct
10 Correct 0 ms 212 KB Output is correct
11 Correct 0 ms 212 KB Output is correct
12 Correct 7 ms 1108 KB Output is correct
13 Correct 159 ms 22092 KB Output is correct
14 Correct 1 ms 212 KB Output is correct
15 Correct 1 ms 212 KB Output is correct
16 Correct 3 ms 728 KB Output is correct
17 Correct 77 ms 12176 KB Output is correct
18 Correct 0 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 40 ms 5740 KB Output is correct
22 Correct 186 ms 22048 KB Output is correct
23 Correct 162 ms 22036 KB Output is correct
24 Correct 165 ms 22032 KB Output is correct
25 Correct 75 ms 12188 KB Output is correct
26 Correct 70 ms 12192 KB Output is correct
27 Correct 157 ms 22092 KB Output is correct
28 Correct 165 ms 22240 KB Output is correct
29 Correct 71 ms 12188 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 41 ms 5752 KB Output is correct
5 Correct 167 ms 22092 KB Output is correct
6 Correct 167 ms 22072 KB Output is correct
7 Correct 166 ms 22092 KB Output is correct
8 Correct 0 ms 212 KB Output is correct
9 Correct 40 ms 5772 KB Output is correct
10 Correct 169 ms 22040 KB Output is correct
11 Correct 161 ms 22048 KB Output is correct
12 Correct 166 ms 22036 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 316 KB Output is correct
16 Correct 41 ms 6284 KB Output is correct
17 Correct 162 ms 24068 KB Output is correct
18 Correct 167 ms 24080 KB Output is correct
19 Correct 162 ms 24032 KB Output is correct
20 Correct 160 ms 23992 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 0 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 0 ms 212 KB Output is correct
6 Correct 7 ms 1108 KB Output is correct
7 Correct 164 ms 22016 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 212 KB Output is correct
11 Correct 0 ms 212 KB Output is correct
12 Correct 7 ms 1108 KB Output is correct
13 Correct 159 ms 22032 KB Output is correct
14 Correct 1 ms 212 KB Output is correct
15 Correct 0 ms 212 KB Output is correct
16 Correct 4 ms 728 KB Output is correct
17 Correct 76 ms 12188 KB Output is correct
18 Correct 0 ms 212 KB Output is correct
19 Correct 0 ms 212 KB Output is correct
20 Correct 40 ms 5708 KB Output is correct
21 Correct 166 ms 22044 KB Output is correct
22 Correct 163 ms 21996 KB Output is correct
23 Correct 175 ms 22056 KB Output is correct
24 Correct 162 ms 22004 KB Output is correct
25 Correct 74 ms 12236 KB Output is correct
26 Correct 66 ms 12248 KB Output is correct
27 Correct 185 ms 22040 KB Output is correct
28 Correct 158 ms 22060 KB Output is correct
29 Correct 0 ms 212 KB Output is correct
30 Correct 0 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 0 ms 212 KB Output is correct
34 Correct 0 ms 212 KB Output is correct
35 Correct 0 ms 212 KB Output is correct
36 Correct 8 ms 1108 KB Output is correct
37 Correct 162 ms 22040 KB Output is correct
38 Correct 0 ms 212 KB Output is correct
39 Correct 0 ms 212 KB Output is correct
40 Correct 7 ms 1108 KB Output is correct
41 Correct 159 ms 22092 KB Output is correct
42 Correct 1 ms 212 KB Output is correct
43 Correct 1 ms 212 KB Output is correct
44 Correct 3 ms 728 KB Output is correct
45 Correct 77 ms 12176 KB Output is correct
46 Correct 0 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 40 ms 5740 KB Output is correct
50 Correct 186 ms 22048 KB Output is correct
51 Correct 162 ms 22036 KB Output is correct
52 Correct 165 ms 22032 KB Output is correct
53 Correct 75 ms 12188 KB Output is correct
54 Correct 70 ms 12192 KB Output is correct
55 Correct 157 ms 22092 KB Output is correct
56 Correct 165 ms 22240 KB Output is correct
57 Correct 71 ms 12188 KB Output is correct
58 Correct 0 ms 212 KB Output is correct
59 Correct 0 ms 212 KB Output is correct
60 Correct 3 ms 724 KB Output is correct
61 Correct 73 ms 12188 KB Output is correct
62 Correct 0 ms 212 KB Output is correct
63 Correct 1 ms 212 KB Output is correct
64 Correct 1 ms 212 KB Output is correct
65 Correct 41 ms 6312 KB Output is correct
66 Correct 67 ms 14084 KB Output is correct
67 Correct 69 ms 14080 KB Output is correct
68 Correct 67 ms 14076 KB Output is correct
69 Correct 67 ms 14136 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 0 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 0 ms 212 KB Output is correct
6 Correct 7 ms 1108 KB Output is correct
7 Correct 164 ms 22016 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 212 KB Output is correct
11 Correct 0 ms 212 KB Output is correct
12 Correct 7 ms 1108 KB Output is correct
13 Correct 159 ms 22032 KB Output is correct
14 Correct 1 ms 212 KB Output is correct
15 Correct 0 ms 212 KB Output is correct
16 Correct 4 ms 728 KB Output is correct
17 Correct 76 ms 12188 KB Output is correct
18 Correct 0 ms 212 KB Output is correct
19 Correct 0 ms 212 KB Output is correct
20 Correct 40 ms 5708 KB Output is correct
21 Correct 166 ms 22044 KB Output is correct
22 Correct 163 ms 21996 KB Output is correct
23 Correct 175 ms 22056 KB Output is correct
24 Correct 162 ms 22004 KB Output is correct
25 Correct 74 ms 12236 KB Output is correct
26 Correct 66 ms 12248 KB Output is correct
27 Correct 185 ms 22040 KB Output is correct
28 Correct 158 ms 22060 KB Output is correct
29 Correct 0 ms 212 KB Output is correct
30 Correct 0 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 0 ms 212 KB Output is correct
34 Correct 0 ms 212 KB Output is correct
35 Correct 0 ms 212 KB Output is correct
36 Correct 8 ms 1108 KB Output is correct
37 Correct 162 ms 22040 KB Output is correct
38 Correct 0 ms 212 KB Output is correct
39 Correct 0 ms 212 KB Output is correct
40 Correct 7 ms 1108 KB Output is correct
41 Correct 159 ms 22092 KB Output is correct
42 Correct 1 ms 212 KB Output is correct
43 Correct 1 ms 212 KB Output is correct
44 Correct 3 ms 728 KB Output is correct
45 Correct 77 ms 12176 KB Output is correct
46 Correct 0 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 40 ms 5740 KB Output is correct
50 Correct 186 ms 22048 KB Output is correct
51 Correct 162 ms 22036 KB Output is correct
52 Correct 165 ms 22032 KB Output is correct
53 Correct 75 ms 12188 KB Output is correct
54 Correct 70 ms 12192 KB Output is correct
55 Correct 157 ms 22092 KB Output is correct
56 Correct 165 ms 22240 KB Output is correct
57 Correct 71 ms 12188 KB Output is correct
58 Correct 0 ms 212 KB Output is correct
59 Correct 0 ms 212 KB Output is correct
60 Correct 0 ms 212 KB Output is correct
61 Correct 41 ms 5752 KB Output is correct
62 Correct 167 ms 22092 KB Output is correct
63 Correct 167 ms 22072 KB Output is correct
64 Correct 166 ms 22092 KB Output is correct
65 Correct 0 ms 212 KB Output is correct
66 Correct 40 ms 5772 KB Output is correct
67 Correct 169 ms 22040 KB Output is correct
68 Correct 161 ms 22048 KB Output is correct
69 Correct 166 ms 22036 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 316 KB Output is correct
73 Correct 41 ms 6284 KB Output is correct
74 Correct 162 ms 24068 KB Output is correct
75 Correct 167 ms 24080 KB Output is correct
76 Correct 162 ms 24032 KB Output is correct
77 Correct 160 ms 23992 KB Output is correct
78 Correct 0 ms 212 KB Output is correct
79 Correct 0 ms 212 KB Output is correct
80 Correct 3 ms 724 KB Output is correct
81 Correct 73 ms 12188 KB Output is correct
82 Correct 0 ms 212 KB Output is correct
83 Correct 1 ms 212 KB Output is correct
84 Correct 1 ms 212 KB Output is correct
85 Correct 41 ms 6312 KB Output is correct
86 Correct 67 ms 14084 KB Output is correct
87 Correct 69 ms 14080 KB Output is correct
88 Correct 67 ms 14076 KB Output is correct
89 Correct 67 ms 14136 KB Output is correct
90 Correct 1 ms 212 KB Output is correct
91 Correct 1 ms 212 KB Output is correct
92 Correct 3 ms 836 KB Output is correct
93 Correct 67 ms 14076 KB Output is correct
94 Correct 1 ms 212 KB Output is correct
95 Correct 1 ms 212 KB Output is correct
96 Correct 1 ms 212 KB Output is correct
97 Correct 16 ms 3712 KB Output is correct
98 Correct 65 ms 14092 KB Output is correct
99 Correct 65 ms 14156 KB Output is correct
100 Correct 65 ms 14088 KB Output is correct
101 Correct 65 ms 14080 KB Output is correct
102 Correct 65 ms 14136 KB Output is correct
103 Correct 68 ms 14080 KB Output is correct
104 Correct 68 ms 14080 KB Output is correct
105 Correct 67 ms 14076 KB Output is correct