Submission #314310

# Submission time Handle Problem Language Result Execution time Memory
314310 2020-10-19T16:10:16 Z wildturtle Connecting Supertrees (IOI20_supertrees) C++14
100 / 100
290 ms 45728 KB
#include "supertrees.h"
#include<bits/stdc++.h>
using namespace std;
int a,B[500005],B1[500005];
vector <int> v[500005],v1[500005],v2;
int get_col(int x) {
	if(B[x]==x) return x;
	B[x]=get_col(B[x]);
	return B[x];
}
void col(int x,int y) {
	B[get_col(x)]=get_col(y);
}
int get_col1(int x) {
	if(B1[x]==x) return x;
	B1[x]=get_col1(B1[x]);
	return B1[x];
}
void col1(int x,int y) {
	B1[get_col1(x)]=get_col1(y);
}
int construct(vector < vector < int > > p) {
	int n = p.size();
    vector < vector < int > > answer(n, vector < int >(n, 0));
	for (int i = 0; i < n; i++) {
		B[i]=i;
		B1[i]=i;
		for(int j=0;j<n;j++) {
			if(p[i][j]==3) return 0;
		}
	}

	for(int i=0;i<n;i++) {
		for(int j=0;j<n;j++) {
			if(p[i][j]!=0) col(i,j);
		}
	}
	for(int i=0;i<n;i++) {
		for(int j=0;j<n;j++) {
			if(get_col(i)==get_col(j) && p[i][j]==0) return 0;
		}
	}
	
	for(int i=0;i<n;i++) {
		v[get_col(i)].push_back(i);
	}
	
	for(int i=0;i<n;i++) {
		if(v[i].size()==0) continue;
		a=0;
		for(int j=0;j<v[i].size();j++) {
			for(int l=0;l<v[i].size();l++) {
				if(p[v[i][j]][v[i][l]]==2) a=1;
				else col1(v[i][j],v[i][l]);
			}
		}
		
		if(a==0) {
			for(int j=1;j<v[i].size();j++) {
				answer[v[i][j-1]][v[i][j]]=1;
				answer[v[i][j]][v[i][j-1]]=1;
			}
			
		}
		else {
			for(int i=0;i<v[i].size();i++) {
				for(int j=0;j<v[i].size();j++) {
					if(get_col1(i)==get_col1(j) && p[i][j]==2) return 0;
				}
			}
			for(int j=0;j<v[i].size();j++)
				v1[get_col1(v[i][j])].push_back(v[i][j]);
			v2.clear();
			for(int j=0;j<v[i].size();j++) {
				if(v1[v[i][j]].size()==0) continue;
				v2.push_back(v1[v[i][j]][0]);
				for(int l=1;l<v1[v[i][j]].size();l++) {
					answer[v1[v[i][j]][l-1]][v1[v[i][j]][l]]=1;
					answer[v1[v[i][j]][l]][v1[v[i][j]][l-1]]=1;
				}
			}
			if(v2.size()==2) return 0;
			for(int j=0;j<v2.size();j++) {
				if(j==v2.size()-1) {
					answer[v2[0]][v2[j]]=1;
					answer[v2[j]][v2[0]]=1;
				}
				else {
					answer[v2[j+1]][v2[j]]=1;
					answer[v2[j]][v2[j+1]]=1;
				}
			}
			for(int j=0;j<v[i].size();j++)
				v1[get_col1(v[i][j])].clear();
		}
	}
	build(answer);
	/*for(int i=0;i<n;i++) {
		for(int j=0;j<n;j++) {
			cout<<answer[i][j]<<" ";
		}
		cout<<endl;
	}*/
	return 1;
}/*
int main() {
	//cout<<construct({ {1,0} , {0,1} });
	cout<<construct({ {1,1,2,2} , {1,1,2,2} , {2,2,1,2} , {2,2,2,1} });
	//1,1,2,2
	//1,1,2,2
	//2,2,1,2
	//2,2,2,1
}*/

Compilation message

supertrees.cpp: In function 'int construct(std::vector<std::vector<int> >)':
supertrees.cpp:51:16: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   51 |   for(int j=0;j<v[i].size();j++) {
      |               ~^~~~~~~~~~~~
supertrees.cpp:52:17: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   52 |    for(int l=0;l<v[i].size();l++) {
      |                ~^~~~~~~~~~~~
supertrees.cpp:59:17: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   59 |    for(int j=1;j<v[i].size();j++) {
      |                ~^~~~~~~~~~~~
supertrees.cpp:66:17: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   66 |    for(int i=0;i<v[i].size();i++) {
      |                ~^~~~~~~~~~~~
supertrees.cpp:67:18: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   67 |     for(int j=0;j<v[i].size();j++) {
      |                 ~^~~~~~~~~~~~
supertrees.cpp:71:17: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   71 |    for(int j=0;j<v[i].size();j++)
      |                ~^~~~~~~~~~~~
supertrees.cpp:74:17: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   74 |    for(int j=0;j<v[i].size();j++) {
      |                ~^~~~~~~~~~~~
supertrees.cpp:77:18: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   77 |     for(int l=1;l<v1[v[i][j]].size();l++) {
      |                 ~^~~~~~~~~~~~~~~~~~~
supertrees.cpp:83:17: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   83 |    for(int j=0;j<v2.size();j++) {
      |                ~^~~~~~~~~~
supertrees.cpp:84:9: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   84 |     if(j==v2.size()-1) {
      |        ~^~~~~~~~~~~~~
supertrees.cpp:93:17: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   93 |    for(int j=0;j<v[i].size();j++)
      |                ~^~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 17 ms 23808 KB Output is correct
2 Correct 16 ms 23808 KB Output is correct
3 Correct 16 ms 23808 KB Output is correct
4 Correct 17 ms 23808 KB Output is correct
5 Correct 17 ms 23808 KB Output is correct
6 Correct 27 ms 24696 KB Output is correct
7 Correct 286 ms 45560 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 17 ms 23808 KB Output is correct
2 Correct 16 ms 23808 KB Output is correct
3 Correct 16 ms 23808 KB Output is correct
4 Correct 17 ms 23808 KB Output is correct
5 Correct 17 ms 23808 KB Output is correct
6 Correct 27 ms 24696 KB Output is correct
7 Correct 286 ms 45560 KB Output is correct
8 Correct 16 ms 23936 KB Output is correct
9 Correct 18 ms 23808 KB Output is correct
10 Correct 17 ms 23808 KB Output is correct
11 Correct 17 ms 23808 KB Output is correct
12 Correct 26 ms 24704 KB Output is correct
13 Correct 253 ms 45688 KB Output is correct
14 Correct 16 ms 23808 KB Output is correct
15 Correct 16 ms 23808 KB Output is correct
16 Correct 22 ms 24320 KB Output is correct
17 Correct 136 ms 35704 KB Output is correct
18 Correct 16 ms 23808 KB Output is correct
19 Correct 16 ms 23808 KB Output is correct
20 Correct 79 ms 29288 KB Output is correct
21 Correct 265 ms 45688 KB Output is correct
22 Correct 259 ms 45560 KB Output is correct
23 Correct 290 ms 45688 KB Output is correct
24 Correct 264 ms 45728 KB Output is correct
25 Correct 120 ms 35704 KB Output is correct
26 Correct 116 ms 35708 KB Output is correct
27 Correct 288 ms 45688 KB Output is correct
28 Correct 259 ms 45560 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 17 ms 23808 KB Output is correct
2 Correct 16 ms 23808 KB Output is correct
3 Correct 17 ms 23808 KB Output is correct
4 Correct 17 ms 23808 KB Output is correct
5 Correct 16 ms 23808 KB Output is correct
6 Correct 16 ms 23808 KB Output is correct
7 Correct 18 ms 23808 KB Output is correct
8 Correct 27 ms 24704 KB Output is correct
9 Correct 255 ms 45688 KB Output is correct
10 Correct 17 ms 23936 KB Output is correct
11 Correct 17 ms 23808 KB Output is correct
12 Correct 27 ms 24700 KB Output is correct
13 Correct 278 ms 45688 KB Output is correct
14 Correct 16 ms 23808 KB Output is correct
15 Correct 19 ms 23808 KB Output is correct
16 Correct 22 ms 24320 KB Output is correct
17 Correct 135 ms 35704 KB Output is correct
18 Correct 17 ms 23808 KB Output is correct
19 Correct 16 ms 23808 KB Output is correct
20 Correct 16 ms 23808 KB Output is correct
21 Correct 77 ms 29304 KB Output is correct
22 Correct 260 ms 45688 KB Output is correct
23 Correct 258 ms 45688 KB Output is correct
24 Correct 285 ms 45688 KB Output is correct
25 Correct 127 ms 35832 KB Output is correct
26 Correct 120 ms 35704 KB Output is correct
27 Correct 257 ms 45688 KB Output is correct
28 Correct 283 ms 45688 KB Output is correct
29 Correct 120 ms 35704 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 18 ms 23808 KB Output is correct
2 Correct 17 ms 23808 KB Output is correct
3 Correct 16 ms 23808 KB Output is correct
4 Correct 78 ms 29304 KB Output is correct
5 Correct 269 ms 45688 KB Output is correct
6 Correct 259 ms 45604 KB Output is correct
7 Correct 287 ms 45560 KB Output is correct
8 Correct 18 ms 23808 KB Output is correct
9 Correct 78 ms 29332 KB Output is correct
10 Correct 260 ms 45688 KB Output is correct
11 Correct 265 ms 45596 KB Output is correct
12 Correct 282 ms 45688 KB Output is correct
13 Correct 17 ms 23808 KB Output is correct
14 Correct 17 ms 23808 KB Output is correct
15 Correct 17 ms 23808 KB Output is correct
16 Correct 77 ms 29304 KB Output is correct
17 Correct 260 ms 45688 KB Output is correct
18 Correct 264 ms 45688 KB Output is correct
19 Correct 263 ms 45560 KB Output is correct
20 Correct 253 ms 45688 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 17 ms 23808 KB Output is correct
2 Correct 16 ms 23808 KB Output is correct
3 Correct 16 ms 23808 KB Output is correct
4 Correct 17 ms 23808 KB Output is correct
5 Correct 17 ms 23808 KB Output is correct
6 Correct 27 ms 24696 KB Output is correct
7 Correct 286 ms 45560 KB Output is correct
8 Correct 16 ms 23936 KB Output is correct
9 Correct 18 ms 23808 KB Output is correct
10 Correct 17 ms 23808 KB Output is correct
11 Correct 17 ms 23808 KB Output is correct
12 Correct 26 ms 24704 KB Output is correct
13 Correct 253 ms 45688 KB Output is correct
14 Correct 16 ms 23808 KB Output is correct
15 Correct 16 ms 23808 KB Output is correct
16 Correct 22 ms 24320 KB Output is correct
17 Correct 136 ms 35704 KB Output is correct
18 Correct 16 ms 23808 KB Output is correct
19 Correct 16 ms 23808 KB Output is correct
20 Correct 79 ms 29288 KB Output is correct
21 Correct 265 ms 45688 KB Output is correct
22 Correct 259 ms 45560 KB Output is correct
23 Correct 290 ms 45688 KB Output is correct
24 Correct 264 ms 45728 KB Output is correct
25 Correct 120 ms 35704 KB Output is correct
26 Correct 116 ms 35708 KB Output is correct
27 Correct 288 ms 45688 KB Output is correct
28 Correct 259 ms 45560 KB Output is correct
29 Correct 17 ms 23808 KB Output is correct
30 Correct 16 ms 23808 KB Output is correct
31 Correct 17 ms 23808 KB Output is correct
32 Correct 17 ms 23808 KB Output is correct
33 Correct 16 ms 23808 KB Output is correct
34 Correct 16 ms 23808 KB Output is correct
35 Correct 18 ms 23808 KB Output is correct
36 Correct 27 ms 24704 KB Output is correct
37 Correct 255 ms 45688 KB Output is correct
38 Correct 17 ms 23936 KB Output is correct
39 Correct 17 ms 23808 KB Output is correct
40 Correct 27 ms 24700 KB Output is correct
41 Correct 278 ms 45688 KB Output is correct
42 Correct 16 ms 23808 KB Output is correct
43 Correct 19 ms 23808 KB Output is correct
44 Correct 22 ms 24320 KB Output is correct
45 Correct 135 ms 35704 KB Output is correct
46 Correct 17 ms 23808 KB Output is correct
47 Correct 16 ms 23808 KB Output is correct
48 Correct 16 ms 23808 KB Output is correct
49 Correct 77 ms 29304 KB Output is correct
50 Correct 260 ms 45688 KB Output is correct
51 Correct 258 ms 45688 KB Output is correct
52 Correct 285 ms 45688 KB Output is correct
53 Correct 127 ms 35832 KB Output is correct
54 Correct 120 ms 35704 KB Output is correct
55 Correct 257 ms 45688 KB Output is correct
56 Correct 283 ms 45688 KB Output is correct
57 Correct 120 ms 35704 KB Output is correct
58 Correct 17 ms 23808 KB Output is correct
59 Correct 17 ms 23808 KB Output is correct
60 Correct 23 ms 24320 KB Output is correct
61 Correct 135 ms 35704 KB Output is correct
62 Correct 16 ms 23808 KB Output is correct
63 Correct 16 ms 23808 KB Output is correct
64 Correct 16 ms 23808 KB Output is correct
65 Correct 78 ms 29304 KB Output is correct
66 Correct 124 ms 35704 KB Output is correct
67 Correct 125 ms 35704 KB Output is correct
68 Correct 118 ms 35708 KB Output is correct
69 Correct 120 ms 35704 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 17 ms 23808 KB Output is correct
2 Correct 16 ms 23808 KB Output is correct
3 Correct 16 ms 23808 KB Output is correct
4 Correct 17 ms 23808 KB Output is correct
5 Correct 17 ms 23808 KB Output is correct
6 Correct 27 ms 24696 KB Output is correct
7 Correct 286 ms 45560 KB Output is correct
8 Correct 16 ms 23936 KB Output is correct
9 Correct 18 ms 23808 KB Output is correct
10 Correct 17 ms 23808 KB Output is correct
11 Correct 17 ms 23808 KB Output is correct
12 Correct 26 ms 24704 KB Output is correct
13 Correct 253 ms 45688 KB Output is correct
14 Correct 16 ms 23808 KB Output is correct
15 Correct 16 ms 23808 KB Output is correct
16 Correct 22 ms 24320 KB Output is correct
17 Correct 136 ms 35704 KB Output is correct
18 Correct 16 ms 23808 KB Output is correct
19 Correct 16 ms 23808 KB Output is correct
20 Correct 79 ms 29288 KB Output is correct
21 Correct 265 ms 45688 KB Output is correct
22 Correct 259 ms 45560 KB Output is correct
23 Correct 290 ms 45688 KB Output is correct
24 Correct 264 ms 45728 KB Output is correct
25 Correct 120 ms 35704 KB Output is correct
26 Correct 116 ms 35708 KB Output is correct
27 Correct 288 ms 45688 KB Output is correct
28 Correct 259 ms 45560 KB Output is correct
29 Correct 17 ms 23808 KB Output is correct
30 Correct 16 ms 23808 KB Output is correct
31 Correct 17 ms 23808 KB Output is correct
32 Correct 17 ms 23808 KB Output is correct
33 Correct 16 ms 23808 KB Output is correct
34 Correct 16 ms 23808 KB Output is correct
35 Correct 18 ms 23808 KB Output is correct
36 Correct 27 ms 24704 KB Output is correct
37 Correct 255 ms 45688 KB Output is correct
38 Correct 17 ms 23936 KB Output is correct
39 Correct 17 ms 23808 KB Output is correct
40 Correct 27 ms 24700 KB Output is correct
41 Correct 278 ms 45688 KB Output is correct
42 Correct 16 ms 23808 KB Output is correct
43 Correct 19 ms 23808 KB Output is correct
44 Correct 22 ms 24320 KB Output is correct
45 Correct 135 ms 35704 KB Output is correct
46 Correct 17 ms 23808 KB Output is correct
47 Correct 16 ms 23808 KB Output is correct
48 Correct 16 ms 23808 KB Output is correct
49 Correct 77 ms 29304 KB Output is correct
50 Correct 260 ms 45688 KB Output is correct
51 Correct 258 ms 45688 KB Output is correct
52 Correct 285 ms 45688 KB Output is correct
53 Correct 127 ms 35832 KB Output is correct
54 Correct 120 ms 35704 KB Output is correct
55 Correct 257 ms 45688 KB Output is correct
56 Correct 283 ms 45688 KB Output is correct
57 Correct 120 ms 35704 KB Output is correct
58 Correct 18 ms 23808 KB Output is correct
59 Correct 17 ms 23808 KB Output is correct
60 Correct 16 ms 23808 KB Output is correct
61 Correct 78 ms 29304 KB Output is correct
62 Correct 269 ms 45688 KB Output is correct
63 Correct 259 ms 45604 KB Output is correct
64 Correct 287 ms 45560 KB Output is correct
65 Correct 18 ms 23808 KB Output is correct
66 Correct 78 ms 29332 KB Output is correct
67 Correct 260 ms 45688 KB Output is correct
68 Correct 265 ms 45596 KB Output is correct
69 Correct 282 ms 45688 KB Output is correct
70 Correct 17 ms 23808 KB Output is correct
71 Correct 17 ms 23808 KB Output is correct
72 Correct 17 ms 23808 KB Output is correct
73 Correct 77 ms 29304 KB Output is correct
74 Correct 260 ms 45688 KB Output is correct
75 Correct 264 ms 45688 KB Output is correct
76 Correct 263 ms 45560 KB Output is correct
77 Correct 253 ms 45688 KB Output is correct
78 Correct 17 ms 23808 KB Output is correct
79 Correct 17 ms 23808 KB Output is correct
80 Correct 23 ms 24320 KB Output is correct
81 Correct 135 ms 35704 KB Output is correct
82 Correct 16 ms 23808 KB Output is correct
83 Correct 16 ms 23808 KB Output is correct
84 Correct 16 ms 23808 KB Output is correct
85 Correct 78 ms 29304 KB Output is correct
86 Correct 124 ms 35704 KB Output is correct
87 Correct 125 ms 35704 KB Output is correct
88 Correct 118 ms 35708 KB Output is correct
89 Correct 120 ms 35704 KB Output is correct
90 Correct 16 ms 23808 KB Output is correct
91 Correct 17 ms 23808 KB Output is correct
92 Correct 21 ms 24320 KB Output is correct
93 Correct 126 ms 35704 KB Output is correct
94 Correct 17 ms 23808 KB Output is correct
95 Correct 17 ms 23808 KB Output is correct
96 Correct 18 ms 23808 KB Output is correct
97 Correct 41 ms 26744 KB Output is correct
98 Correct 119 ms 35704 KB Output is correct
99 Correct 118 ms 35704 KB Output is correct
100 Correct 121 ms 35704 KB Output is correct
101 Correct 116 ms 35704 KB Output is correct
102 Correct 127 ms 35616 KB Output is correct
103 Correct 127 ms 35704 KB Output is correct
104 Correct 125 ms 35704 KB Output is correct
105 Correct 126 ms 35612 KB Output is correct