Submission #301612

# Submission time Handle Problem Language Result Execution time Memory
301612 2020-09-18T05:20:38 Z nandonathaniel Connecting Supertrees (IOI20_supertrees) C++14
100 / 100
278 ms 24164 KB
#include "supertrees.h"
#include "bits/stdc++.h"
using namespace std;
typedef pair<int,int> pii;
const int MAXN=1005;

int par[MAXN];
bool idx[MAXN];
vector<int> kel[MAXN],kelkecil[MAXN];

int find(int x){
	if(par[x]==x)return par[x];
	return par[x]=find(par[x]);
}

void join(int a,int b){
	int ortua=find(a),ortub=find(b);
	par[ortua]=ortub;
}

int construct(vector<vector<int>> p){
	vector<pii> nol;
	vector<vector<int>> ans;
	int n = p.size();
	for(int i=0;i<n;i++)par[i]=i;
	ans.resize(n);
	for(int i=0;i<n;i++){
		ans[i].resize(n);
		for(int j=0;j<n;j++){
			ans[i][j]=0;
			if(i==j)continue;
			if(p[i][j])join(i,j);
			else if(i<j)nol.push_back({i,j});
		}
	}
	for(auto isi : nol){
		if(find(isi.first)==find(isi.second))return 0;
	}
	for(int i=0;i<n;i++)kel[find(i)].push_back(i);
	for(int i=0;i<n;i++){
		if(kel[i].size()<=1)continue;
		for(int j=0;j<n;j++){
			kelkecil[j].clear();
			par[j]=j;
			idx[j]=false;
		}
		bool dua=false,tiga=false;
		for(auto isi : kel[i]){
			for(auto isi2 : kel[i]){
				if(p[isi][isi2]==1)join(isi,isi2);
				else if(p[isi][isi2]==3)tiga=true;
				else dua=true;
			}
		}
		if(tiga)return 0;
		for(auto isi : kel[i])kelkecil[find(isi)].push_back(isi);
		vector<vector<int>> satu;
		vector<int> rest;
		for(int j=0;j<n;j++){
			if(kelkecil[j].size()<=1)continue;
			for(auto isi : kelkecil[j]){
				for(auto isi2 : kelkecil[j]){
					if(p[isi][isi2]!=1)return 0;
				}
			}
			satu.push_back(kelkecil[j]);
		}
		for(auto isi : satu){
			for(auto isi2 : isi)idx[isi2]=true;
		}
		for(auto isi : kel[i]){
			if(!idx[isi])rest.push_back(isi);
		}
		vector<int> cycle;
		for(auto isi : rest)cycle.push_back(isi);
		for(auto isi : satu)cycle.push_back(isi.back());
		if(cycle.size()==2)return 0;
		for(auto isi : satu){
			for(int j=0;j<isi.size()-1;j++){
				ans[isi[j]][isi[j+1]]=1;
				ans[isi[j+1]][isi[j]]=1;
			}
		}
		if(cycle.size()>1){
			for(int j=0;j<cycle.size();j++){
				ans[cycle[j]][cycle[(j+1)%cycle.size()]]=1;
				ans[cycle[(j+1)%cycle.size()]][cycle[j]]=1;
			}
		}
	}
	build(ans);
	return 1;
}

Compilation message

supertrees.cpp: In function 'int construct(std::vector<std::vector<int> >)':
supertrees.cpp:79:17: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   79 |    for(int j=0;j<isi.size()-1;j++){
      |                ~^~~~~~~~~~~~~
supertrees.cpp:85:17: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   85 |    for(int j=0;j<cycle.size();j++){
      |                ~^~~~~~~~~~~~~
supertrees.cpp:47:8: warning: variable 'dua' set but not used [-Wunused-but-set-variable]
   47 |   bool dua=false,tiga=false;
      |        ^~~
# Verdict Execution time Memory Grader output
1 Correct 1 ms 384 KB Output is correct
2 Correct 1 ms 384 KB Output is correct
3 Correct 1 ms 384 KB Output is correct
4 Correct 1 ms 384 KB Output is correct
5 Correct 1 ms 384 KB Output is correct
6 Correct 11 ms 1280 KB Output is correct
7 Correct 274 ms 22136 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 384 KB Output is correct
2 Correct 1 ms 384 KB Output is correct
3 Correct 1 ms 384 KB Output is correct
4 Correct 1 ms 384 KB Output is correct
5 Correct 1 ms 384 KB Output is correct
6 Correct 11 ms 1280 KB Output is correct
7 Correct 274 ms 22136 KB Output is correct
8 Correct 1 ms 384 KB Output is correct
9 Correct 1 ms 384 KB Output is correct
10 Correct 1 ms 384 KB Output is correct
11 Correct 1 ms 384 KB Output is correct
12 Correct 10 ms 1368 KB Output is correct
13 Correct 241 ms 24036 KB Output is correct
14 Correct 1 ms 384 KB Output is correct
15 Correct 1 ms 384 KB Output is correct
16 Correct 6 ms 896 KB Output is correct
17 Correct 129 ms 14312 KB Output is correct
18 Correct 1 ms 384 KB Output is correct
19 Correct 1 ms 384 KB Output is correct
20 Correct 62 ms 6380 KB Output is correct
21 Correct 252 ms 23652 KB Output is correct
22 Correct 245 ms 24036 KB Output is correct
23 Correct 275 ms 22208 KB Output is correct
24 Correct 250 ms 24056 KB Output is correct
25 Correct 114 ms 15720 KB Output is correct
26 Correct 112 ms 16244 KB Output is correct
27 Correct 270 ms 22212 KB Output is correct
28 Correct 251 ms 24032 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 384 KB Output is correct
2 Correct 1 ms 384 KB Output is correct
3 Correct 1 ms 384 KB Output is correct
4 Correct 1 ms 384 KB Output is correct
5 Correct 1 ms 384 KB Output is correct
6 Correct 1 ms 384 KB Output is correct
7 Correct 1 ms 384 KB Output is correct
8 Correct 10 ms 1368 KB Output is correct
9 Correct 242 ms 24164 KB Output is correct
10 Correct 1 ms 384 KB Output is correct
11 Correct 1 ms 384 KB Output is correct
12 Correct 11 ms 1280 KB Output is correct
13 Correct 278 ms 22264 KB Output is correct
14 Correct 1 ms 384 KB Output is correct
15 Correct 1 ms 384 KB Output is correct
16 Correct 6 ms 896 KB Output is correct
17 Correct 131 ms 14200 KB Output is correct
18 Correct 1 ms 384 KB Output is correct
19 Correct 1 ms 384 KB Output is correct
20 Correct 1 ms 384 KB Output is correct
21 Correct 62 ms 6356 KB Output is correct
22 Correct 265 ms 23652 KB Output is correct
23 Correct 248 ms 24036 KB Output is correct
24 Correct 262 ms 22320 KB Output is correct
25 Correct 112 ms 16104 KB Output is correct
26 Correct 112 ms 15844 KB Output is correct
27 Correct 248 ms 24040 KB Output is correct
28 Correct 269 ms 22188 KB Output is correct
29 Correct 112 ms 16228 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 384 KB Output is correct
2 Correct 1 ms 384 KB Output is correct
3 Correct 1 ms 384 KB Output is correct
4 Correct 63 ms 6252 KB Output is correct
5 Correct 249 ms 23780 KB Output is correct
6 Correct 246 ms 24036 KB Output is correct
7 Correct 273 ms 22188 KB Output is correct
8 Correct 1 ms 384 KB Output is correct
9 Correct 66 ms 6252 KB Output is correct
10 Correct 249 ms 23652 KB Output is correct
11 Correct 248 ms 24032 KB Output is correct
12 Correct 265 ms 22372 KB Output is correct
13 Correct 1 ms 384 KB Output is correct
14 Correct 1 ms 512 KB Output is correct
15 Correct 1 ms 384 KB Output is correct
16 Correct 62 ms 6388 KB Output is correct
17 Correct 248 ms 23648 KB Output is correct
18 Correct 249 ms 23652 KB Output is correct
19 Correct 246 ms 23908 KB Output is correct
20 Correct 245 ms 24164 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 384 KB Output is correct
2 Correct 1 ms 384 KB Output is correct
3 Correct 1 ms 384 KB Output is correct
4 Correct 1 ms 384 KB Output is correct
5 Correct 1 ms 384 KB Output is correct
6 Correct 11 ms 1280 KB Output is correct
7 Correct 274 ms 22136 KB Output is correct
8 Correct 1 ms 384 KB Output is correct
9 Correct 1 ms 384 KB Output is correct
10 Correct 1 ms 384 KB Output is correct
11 Correct 1 ms 384 KB Output is correct
12 Correct 10 ms 1368 KB Output is correct
13 Correct 241 ms 24036 KB Output is correct
14 Correct 1 ms 384 KB Output is correct
15 Correct 1 ms 384 KB Output is correct
16 Correct 6 ms 896 KB Output is correct
17 Correct 129 ms 14312 KB Output is correct
18 Correct 1 ms 384 KB Output is correct
19 Correct 1 ms 384 KB Output is correct
20 Correct 62 ms 6380 KB Output is correct
21 Correct 252 ms 23652 KB Output is correct
22 Correct 245 ms 24036 KB Output is correct
23 Correct 275 ms 22208 KB Output is correct
24 Correct 250 ms 24056 KB Output is correct
25 Correct 114 ms 15720 KB Output is correct
26 Correct 112 ms 16244 KB Output is correct
27 Correct 270 ms 22212 KB Output is correct
28 Correct 251 ms 24032 KB Output is correct
29 Correct 1 ms 384 KB Output is correct
30 Correct 1 ms 384 KB Output is correct
31 Correct 1 ms 384 KB Output is correct
32 Correct 1 ms 384 KB Output is correct
33 Correct 1 ms 384 KB Output is correct
34 Correct 1 ms 384 KB Output is correct
35 Correct 1 ms 384 KB Output is correct
36 Correct 10 ms 1368 KB Output is correct
37 Correct 242 ms 24164 KB Output is correct
38 Correct 1 ms 384 KB Output is correct
39 Correct 1 ms 384 KB Output is correct
40 Correct 11 ms 1280 KB Output is correct
41 Correct 278 ms 22264 KB Output is correct
42 Correct 1 ms 384 KB Output is correct
43 Correct 1 ms 384 KB Output is correct
44 Correct 6 ms 896 KB Output is correct
45 Correct 131 ms 14200 KB Output is correct
46 Correct 1 ms 384 KB Output is correct
47 Correct 1 ms 384 KB Output is correct
48 Correct 1 ms 384 KB Output is correct
49 Correct 62 ms 6356 KB Output is correct
50 Correct 265 ms 23652 KB Output is correct
51 Correct 248 ms 24036 KB Output is correct
52 Correct 262 ms 22320 KB Output is correct
53 Correct 112 ms 16104 KB Output is correct
54 Correct 112 ms 15844 KB Output is correct
55 Correct 248 ms 24040 KB Output is correct
56 Correct 269 ms 22188 KB Output is correct
57 Correct 112 ms 16228 KB Output is correct
58 Correct 1 ms 384 KB Output is correct
59 Correct 1 ms 384 KB Output is correct
60 Correct 6 ms 896 KB Output is correct
61 Correct 135 ms 13544 KB Output is correct
62 Correct 1 ms 384 KB Output is correct
63 Correct 1 ms 384 KB Output is correct
64 Correct 1 ms 384 KB Output is correct
65 Correct 62 ms 6380 KB Output is correct
66 Correct 117 ms 15844 KB Output is correct
67 Correct 111 ms 15716 KB Output is correct
68 Correct 114 ms 15996 KB Output is correct
69 Correct 109 ms 16100 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 384 KB Output is correct
2 Correct 1 ms 384 KB Output is correct
3 Correct 1 ms 384 KB Output is correct
4 Correct 1 ms 384 KB Output is correct
5 Correct 1 ms 384 KB Output is correct
6 Correct 11 ms 1280 KB Output is correct
7 Correct 274 ms 22136 KB Output is correct
8 Correct 1 ms 384 KB Output is correct
9 Correct 1 ms 384 KB Output is correct
10 Correct 1 ms 384 KB Output is correct
11 Correct 1 ms 384 KB Output is correct
12 Correct 10 ms 1368 KB Output is correct
13 Correct 241 ms 24036 KB Output is correct
14 Correct 1 ms 384 KB Output is correct
15 Correct 1 ms 384 KB Output is correct
16 Correct 6 ms 896 KB Output is correct
17 Correct 129 ms 14312 KB Output is correct
18 Correct 1 ms 384 KB Output is correct
19 Correct 1 ms 384 KB Output is correct
20 Correct 62 ms 6380 KB Output is correct
21 Correct 252 ms 23652 KB Output is correct
22 Correct 245 ms 24036 KB Output is correct
23 Correct 275 ms 22208 KB Output is correct
24 Correct 250 ms 24056 KB Output is correct
25 Correct 114 ms 15720 KB Output is correct
26 Correct 112 ms 16244 KB Output is correct
27 Correct 270 ms 22212 KB Output is correct
28 Correct 251 ms 24032 KB Output is correct
29 Correct 1 ms 384 KB Output is correct
30 Correct 1 ms 384 KB Output is correct
31 Correct 1 ms 384 KB Output is correct
32 Correct 1 ms 384 KB Output is correct
33 Correct 1 ms 384 KB Output is correct
34 Correct 1 ms 384 KB Output is correct
35 Correct 1 ms 384 KB Output is correct
36 Correct 10 ms 1368 KB Output is correct
37 Correct 242 ms 24164 KB Output is correct
38 Correct 1 ms 384 KB Output is correct
39 Correct 1 ms 384 KB Output is correct
40 Correct 11 ms 1280 KB Output is correct
41 Correct 278 ms 22264 KB Output is correct
42 Correct 1 ms 384 KB Output is correct
43 Correct 1 ms 384 KB Output is correct
44 Correct 6 ms 896 KB Output is correct
45 Correct 131 ms 14200 KB Output is correct
46 Correct 1 ms 384 KB Output is correct
47 Correct 1 ms 384 KB Output is correct
48 Correct 1 ms 384 KB Output is correct
49 Correct 62 ms 6356 KB Output is correct
50 Correct 265 ms 23652 KB Output is correct
51 Correct 248 ms 24036 KB Output is correct
52 Correct 262 ms 22320 KB Output is correct
53 Correct 112 ms 16104 KB Output is correct
54 Correct 112 ms 15844 KB Output is correct
55 Correct 248 ms 24040 KB Output is correct
56 Correct 269 ms 22188 KB Output is correct
57 Correct 112 ms 16228 KB Output is correct
58 Correct 1 ms 384 KB Output is correct
59 Correct 1 ms 384 KB Output is correct
60 Correct 1 ms 384 KB Output is correct
61 Correct 63 ms 6252 KB Output is correct
62 Correct 249 ms 23780 KB Output is correct
63 Correct 246 ms 24036 KB Output is correct
64 Correct 273 ms 22188 KB Output is correct
65 Correct 1 ms 384 KB Output is correct
66 Correct 66 ms 6252 KB Output is correct
67 Correct 249 ms 23652 KB Output is correct
68 Correct 248 ms 24032 KB Output is correct
69 Correct 265 ms 22372 KB Output is correct
70 Correct 1 ms 384 KB Output is correct
71 Correct 1 ms 512 KB Output is correct
72 Correct 1 ms 384 KB Output is correct
73 Correct 62 ms 6388 KB Output is correct
74 Correct 248 ms 23648 KB Output is correct
75 Correct 249 ms 23652 KB Output is correct
76 Correct 246 ms 23908 KB Output is correct
77 Correct 245 ms 24164 KB Output is correct
78 Correct 1 ms 384 KB Output is correct
79 Correct 1 ms 384 KB Output is correct
80 Correct 6 ms 896 KB Output is correct
81 Correct 135 ms 13544 KB Output is correct
82 Correct 1 ms 384 KB Output is correct
83 Correct 1 ms 384 KB Output is correct
84 Correct 1 ms 384 KB Output is correct
85 Correct 62 ms 6380 KB Output is correct
86 Correct 117 ms 15844 KB Output is correct
87 Correct 111 ms 15716 KB Output is correct
88 Correct 114 ms 15996 KB Output is correct
89 Correct 109 ms 16100 KB Output is correct
90 Correct 0 ms 384 KB Output is correct
91 Correct 1 ms 384 KB Output is correct
92 Correct 6 ms 896 KB Output is correct
93 Correct 130 ms 13164 KB Output is correct
94 Correct 1 ms 384 KB Output is correct
95 Correct 1 ms 384 KB Output is correct
96 Correct 1 ms 384 KB Output is correct
97 Correct 32 ms 4332 KB Output is correct
98 Correct 127 ms 15820 KB Output is correct
99 Correct 111 ms 15844 KB Output is correct
100 Correct 111 ms 15972 KB Output is correct
101 Correct 113 ms 16100 KB Output is correct
102 Correct 132 ms 12280 KB Output is correct
103 Correct 128 ms 12280 KB Output is correct
104 Correct 134 ms 12280 KB Output is correct
105 Correct 132 ms 14312 KB Output is correct