Submission #414114

# Submission time Handle Problem Language Result Execution time Memory
414114 2021-05-30T04:41:50 Z Bill_00 Connecting Supertrees (IOI20_supertrees) C++14
100 / 100
253 ms 24180 KB
#include "supertrees.h"
#include <bits/stdc++.h>
using namespace std;
int head[1005],sz[1005];
vector<int>groups[1005],lines[1005];

int find(int node){
	return head[node]=(node==head[node]?node:find(head[node]));
}

void combine(int i,int j){
	int a=find(i);
	int b=find(j);
	if(a==b) return;
	if(sz[a]>sz[b]){
		head[b]=a;
		sz[a]+=sz[b];
	}
	else{
		head[a]=b;
		sz[b]+=sz[a];
	}
} 

int construct(vector<vector<int> >p) {
	// cout << "LOL" << '\n';
	int n = p.size();
	vector<vector<int> > ans;
	for (int i = 0; i < n; i++) {
		vector<int> row;
		row.resize(n);
		ans.push_back(row);
	}
	for(int i=0;i<n;i++){
		head[i]=i;
		sz[i]=1;
	}
	for(int i=0;i<n;i++){
		for(int j=0;j<n;j++){
			if(p[i][j]==3) return 0;
			if(p[i][j]>0){
				combine(i,j);
			}
		}
	}
	for(int i=0;i<n;i++){
		groups[find(i)].push_back(i);
	}
	for(int i=0;i<n;i++){
		head[i]=i;
		sz[i]=1;
	}
	for(int i=0;i<n;i++){
		int szz=groups[i].size();
		// cout << szz << '\n';
		for(int j=0;j<szz;j++){
			for(int k=0;k<szz;k++){
				int a=groups[i][j];
				int b=groups[i][k];
				if(p[a][b]==0) return 0;
				if(p[a][b]==1) combine(a,b);
			}
		}
		for(int j=0;j<szz;j++){
			int node=groups[i][j];
			lines[find(node)].push_back(node);
			// cout << node << ' ' << find(node) << '\n';
		}
		vector<int>cycle;
		for(int j=0;j<szz;j++){
			int node=groups[i][j];
			int szzz=lines[node].size();
			if(szzz) cycle.push_back(lines[node][0]);
			for(int k=0;k<szzz;k++){
				for(int g=0;g<szzz;g++){
					int a=lines[node][k];
					int b=lines[node][g];
					if(p[a][b]==2) return 0;
				}
			}
			for(int k=1;k<szzz;k++){
				int a=lines[node][k];
				int b=lines[node][k-1];
				ans[a][b]=1;
				ans[b][a]=1;
			}
		}
		int szzzz=cycle.size();
		if(szzzz==2) return 0;
		if(szzzz==1) continue;
		for(int j=0;j<szzzz;j++){
			int a=cycle[j];
			int b=cycle[(j-1+szzzz)%szzzz];
			ans[a][b]=1;
			ans[b][a]=1;
		}
	}
	build(ans);
	return 1;
}
# 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 348 KB Output is correct
4 Correct 1 ms 332 KB Output is correct
5 Correct 1 ms 332 KB Output is correct
6 Correct 11 ms 1300 KB Output is correct
7 Correct 245 ms 23980 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 348 KB Output is correct
4 Correct 1 ms 332 KB Output is correct
5 Correct 1 ms 332 KB Output is correct
6 Correct 11 ms 1300 KB Output is correct
7 Correct 245 ms 23980 KB Output is correct
8 Correct 1 ms 332 KB Output is correct
9 Correct 1 ms 348 KB Output is correct
10 Correct 1 ms 332 KB Output is correct
11 Correct 1 ms 332 KB Output is correct
12 Correct 10 ms 1288 KB Output is correct
13 Correct 228 ms 24112 KB Output is correct
14 Correct 1 ms 332 KB Output is correct
15 Correct 1 ms 332 KB Output is correct
16 Correct 7 ms 844 KB Output is correct
17 Correct 113 ms 14148 KB Output is correct
18 Correct 1 ms 332 KB Output is correct
19 Correct 1 ms 332 KB Output is correct
20 Correct 58 ms 6200 KB Output is correct
21 Correct 232 ms 24060 KB Output is correct
22 Correct 241 ms 23992 KB Output is correct
23 Correct 253 ms 23988 KB Output is correct
24 Correct 226 ms 24024 KB Output is correct
25 Correct 101 ms 14120 KB Output is correct
26 Correct 98 ms 14120 KB Output is correct
27 Correct 247 ms 24016 KB Output is correct
28 Correct 228 ms 24108 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 348 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 340 KB Output is correct
8 Correct 11 ms 1224 KB Output is correct
9 Correct 225 ms 24180 KB Output is correct
10 Correct 1 ms 332 KB Output is correct
11 Correct 1 ms 332 KB Output is correct
12 Correct 10 ms 1280 KB Output is correct
13 Correct 238 ms 24020 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 116 ms 14120 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 58 ms 6296 KB Output is correct
22 Correct 233 ms 24096 KB Output is correct
23 Correct 228 ms 24004 KB Output is correct
24 Correct 243 ms 24004 KB Output is correct
25 Correct 98 ms 14120 KB Output is correct
26 Correct 102 ms 14112 KB Output is correct
27 Correct 225 ms 24096 KB Output is correct
28 Correct 245 ms 24104 KB Output is correct
29 Correct 95 ms 14124 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 57 ms 6308 KB Output is correct
5 Correct 231 ms 23968 KB Output is correct
6 Correct 223 ms 24004 KB Output is correct
7 Correct 249 ms 23968 KB Output is correct
8 Correct 1 ms 332 KB Output is correct
9 Correct 61 ms 6292 KB Output is correct
10 Correct 240 ms 23980 KB Output is correct
11 Correct 232 ms 24132 KB Output is correct
12 Correct 245 ms 24132 KB Output is correct
13 Correct 1 ms 332 KB Output is correct
14 Correct 1 ms 332 KB Output is correct
15 Correct 1 ms 460 KB Output is correct
16 Correct 57 ms 6220 KB Output is correct
17 Correct 238 ms 24004 KB Output is correct
18 Correct 229 ms 23976 KB Output is correct
19 Correct 224 ms 23980 KB Output is correct
20 Correct 233 ms 24024 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 348 KB Output is correct
4 Correct 1 ms 332 KB Output is correct
5 Correct 1 ms 332 KB Output is correct
6 Correct 11 ms 1300 KB Output is correct
7 Correct 245 ms 23980 KB Output is correct
8 Correct 1 ms 332 KB Output is correct
9 Correct 1 ms 348 KB Output is correct
10 Correct 1 ms 332 KB Output is correct
11 Correct 1 ms 332 KB Output is correct
12 Correct 10 ms 1288 KB Output is correct
13 Correct 228 ms 24112 KB Output is correct
14 Correct 1 ms 332 KB Output is correct
15 Correct 1 ms 332 KB Output is correct
16 Correct 7 ms 844 KB Output is correct
17 Correct 113 ms 14148 KB Output is correct
18 Correct 1 ms 332 KB Output is correct
19 Correct 1 ms 332 KB Output is correct
20 Correct 58 ms 6200 KB Output is correct
21 Correct 232 ms 24060 KB Output is correct
22 Correct 241 ms 23992 KB Output is correct
23 Correct 253 ms 23988 KB Output is correct
24 Correct 226 ms 24024 KB Output is correct
25 Correct 101 ms 14120 KB Output is correct
26 Correct 98 ms 14120 KB Output is correct
27 Correct 247 ms 24016 KB Output is correct
28 Correct 228 ms 24108 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 348 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 340 KB Output is correct
36 Correct 11 ms 1224 KB Output is correct
37 Correct 225 ms 24180 KB Output is correct
38 Correct 1 ms 332 KB Output is correct
39 Correct 1 ms 332 KB Output is correct
40 Correct 10 ms 1280 KB Output is correct
41 Correct 238 ms 24020 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 116 ms 14120 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 58 ms 6296 KB Output is correct
50 Correct 233 ms 24096 KB Output is correct
51 Correct 228 ms 24004 KB Output is correct
52 Correct 243 ms 24004 KB Output is correct
53 Correct 98 ms 14120 KB Output is correct
54 Correct 102 ms 14112 KB Output is correct
55 Correct 225 ms 24096 KB Output is correct
56 Correct 245 ms 24104 KB Output is correct
57 Correct 95 ms 14124 KB Output is correct
58 Correct 1 ms 344 KB Output is correct
59 Correct 1 ms 332 KB Output is correct
60 Correct 6 ms 844 KB Output is correct
61 Correct 117 ms 14144 KB Output is correct
62 Correct 1 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 58 ms 6304 KB Output is correct
66 Correct 101 ms 14148 KB Output is correct
67 Correct 99 ms 14108 KB Output is correct
68 Correct 98 ms 14124 KB Output is correct
69 Correct 95 ms 14148 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 348 KB Output is correct
4 Correct 1 ms 332 KB Output is correct
5 Correct 1 ms 332 KB Output is correct
6 Correct 11 ms 1300 KB Output is correct
7 Correct 245 ms 23980 KB Output is correct
8 Correct 1 ms 332 KB Output is correct
9 Correct 1 ms 348 KB Output is correct
10 Correct 1 ms 332 KB Output is correct
11 Correct 1 ms 332 KB Output is correct
12 Correct 10 ms 1288 KB Output is correct
13 Correct 228 ms 24112 KB Output is correct
14 Correct 1 ms 332 KB Output is correct
15 Correct 1 ms 332 KB Output is correct
16 Correct 7 ms 844 KB Output is correct
17 Correct 113 ms 14148 KB Output is correct
18 Correct 1 ms 332 KB Output is correct
19 Correct 1 ms 332 KB Output is correct
20 Correct 58 ms 6200 KB Output is correct
21 Correct 232 ms 24060 KB Output is correct
22 Correct 241 ms 23992 KB Output is correct
23 Correct 253 ms 23988 KB Output is correct
24 Correct 226 ms 24024 KB Output is correct
25 Correct 101 ms 14120 KB Output is correct
26 Correct 98 ms 14120 KB Output is correct
27 Correct 247 ms 24016 KB Output is correct
28 Correct 228 ms 24108 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 348 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 340 KB Output is correct
36 Correct 11 ms 1224 KB Output is correct
37 Correct 225 ms 24180 KB Output is correct
38 Correct 1 ms 332 KB Output is correct
39 Correct 1 ms 332 KB Output is correct
40 Correct 10 ms 1280 KB Output is correct
41 Correct 238 ms 24020 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 116 ms 14120 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 58 ms 6296 KB Output is correct
50 Correct 233 ms 24096 KB Output is correct
51 Correct 228 ms 24004 KB Output is correct
52 Correct 243 ms 24004 KB Output is correct
53 Correct 98 ms 14120 KB Output is correct
54 Correct 102 ms 14112 KB Output is correct
55 Correct 225 ms 24096 KB Output is correct
56 Correct 245 ms 24104 KB Output is correct
57 Correct 95 ms 14124 KB Output is correct
58 Correct 1 ms 332 KB Output is correct
59 Correct 1 ms 332 KB Output is correct
60 Correct 1 ms 332 KB Output is correct
61 Correct 57 ms 6308 KB Output is correct
62 Correct 231 ms 23968 KB Output is correct
63 Correct 223 ms 24004 KB Output is correct
64 Correct 249 ms 23968 KB Output is correct
65 Correct 1 ms 332 KB Output is correct
66 Correct 61 ms 6292 KB Output is correct
67 Correct 240 ms 23980 KB Output is correct
68 Correct 232 ms 24132 KB Output is correct
69 Correct 245 ms 24132 KB Output is correct
70 Correct 1 ms 332 KB Output is correct
71 Correct 1 ms 332 KB Output is correct
72 Correct 1 ms 460 KB Output is correct
73 Correct 57 ms 6220 KB Output is correct
74 Correct 238 ms 24004 KB Output is correct
75 Correct 229 ms 23976 KB Output is correct
76 Correct 224 ms 23980 KB Output is correct
77 Correct 233 ms 24024 KB Output is correct
78 Correct 1 ms 344 KB Output is correct
79 Correct 1 ms 332 KB Output is correct
80 Correct 6 ms 844 KB Output is correct
81 Correct 117 ms 14144 KB Output is correct
82 Correct 1 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 58 ms 6304 KB Output is correct
86 Correct 101 ms 14148 KB Output is correct
87 Correct 99 ms 14108 KB Output is correct
88 Correct 98 ms 14124 KB Output is correct
89 Correct 95 ms 14148 KB Output is correct
90 Correct 1 ms 332 KB Output is correct
91 Correct 1 ms 332 KB Output is correct
92 Correct 5 ms 844 KB Output is correct
93 Correct 103 ms 14128 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 26 ms 3744 KB Output is correct
98 Correct 97 ms 14112 KB Output is correct
99 Correct 96 ms 14108 KB Output is correct
100 Correct 98 ms 14148 KB Output is correct
101 Correct 96 ms 14124 KB Output is correct
102 Correct 97 ms 14136 KB Output is correct
103 Correct 102 ms 14128 KB Output is correct
104 Correct 96 ms 14048 KB Output is correct
105 Correct 104 ms 14112 KB Output is correct