Submission #431405

# Submission time Handle Problem Language Result Execution time Memory
431405 2021-06-17T11:42:31 Z Pbezz Connecting Supertrees (IOI20_supertrees) C++14
100 / 100
302 ms 22208 KB
#include "supertrees.h"
#include <vector>
#include <bits/stdc++.h>

using namespace std;

#define ll long long
#define pb push_back
typedef pair<ll,ll> pii;

const ll MAXN = 2e5+5;
int parent[MAXN],sizee[MAXN],contagem[MAXN];
int parent1[MAXN],sizee1[MAXN];

int find(ll x){
if(x==parent[x])return x;

return parent[x]=find(parent[x]);
}

void unite(ll a, ll b){
a = find(a);
b = find(b);
if(a==b)return;
if(sizee[a]<sizee[b])swap(a,b);

sizee[a]+=sizee[b];
parent[b]=a;
}

int find1(ll x){
if(x==parent1[x])return x;

return parent1[x]=find1(parent1[x]);
}

void unite1(ll a, ll b){
a = find1(a);
b = find1(b);
if(a==b)return;
if(sizee1[a]<sizee1[b])swap(a,b);

sizee1[a]+=sizee1[b];
parent1[b]=a;
}

int construct(std::vector<std::vector<int>> p) {
	int n = p.size(),i,j,k,a,b;
	std::vector<std::vector<int>> answer;
	for (i = 0; i < n; i++) {
		std::vector<int> row;
		row.resize(n);
		answer.push_back(row);
	}

	for(i=0;i<n;i++){
	parent[i]=i;
	sizee[i]=1;
	parent1[i]=i;
	sizee1[i]=1;
	}

	for(i=0;i<n;i++){
	for(j=i+1;j<n;j++){
	if(p[i][j]==0)continue;

	if(p[i][j]==1)contagem[i]++;

	if(p[i][j]==1)contagem[j]++;

	unite(i,j);
	}
}
vector<vector<int>>meh(n);
	for(i=0;i<n;i++){
	k=find(i);
	meh[k].pb(i);
	}//meh[i] e set da componente de i

	for(a=0;a<n;a++){
	if(a!=find(a))continue;//para cada componente
	k = meh[a].size();
	for(i=0;i<k;i++){
	for(j=i+1;j<k;j++){	if(p[ meh[a][i] ][ meh[a][j] ]==0)return 0;
	if(p[ meh[a][i] ][ meh[a][j] ]==2)continue;

	unite1(meh[a][i],meh[a][j]);
	}
}//componentes feitas

vector<vector<int>>meh1(n);
	for(i=0;i<k;i++){
	b=find1(meh[a][i]);//cout<<i<<" "<<meh[a][i]<<" "<<b<<endl;
	meh1[b].pb(meh[a][i]);
	}
	vector<int>fina;
	for(i=0;i<k;i++){
	if(find1(meh[a][i])!=meh[a][i])continue;
//meh[a][i] e representante de linha
	//cout<<meh[a][i]<<" "<<(int)meh1[ meh[a][i] ].size()<<"hicbnaui\n";
	for(j=1;j<(int)meh1[ meh[a][i] ].size();j++){//fazer linha
	answer[ meh1[ meh[a][i] ][j] ][ meh1[ meh[a][i] ][j-1] ]=1;
	answer[ meh1[ meh[a][i] ][j-1] ][ meh1[ meh[a][i] ][j] ]=1;

for(b=0;b<(int)meh1[ meh[a][i] ].size();b++){
if(p[ meh1[ meh[a][i] ][b] ][ meh1[ meh[a][i] ][j] ]==2)return 0;
}

	//ver se nao tem de ter 1 para algum de fora
	if(contagem[ meh1[ meh[a][i] ][j] ]!=(int)meh1[ meh[a][i] ].size()-1){
	//cout<<"hihihih "<<meh1[ meh[a][i] ][j]<<" "<<contagem[ meh1[ meh[a][i] ][j] ]<<endl;  ;
	return 0;
	}
	}

	fina.pb(meh[a][i]);
	}

	for(j=1;j<(int)fina.size();j++){
	answer[ fina[j] ][ fina[j-1] ]=1;
	answer[ fina[j-1] ][ fina[j] ]=1;
	}
	if(fina.size()>1){
	answer[ fina[(int)fina.size()-1] ][ fina[0] ]=1;
	answer[ fina[0] ][ fina[(int)fina.size()-1] ]=1;
	}
	if(fina.size()==2)return 0;
	}



	build(answer);
	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 0 ms 204 KB Output is correct
4 Correct 0 ms 204 KB Output is correct
5 Correct 0 ms 204 KB Output is correct
6 Correct 10 ms 1228 KB Output is correct
7 Correct 253 ms 22060 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 0 ms 204 KB Output is correct
4 Correct 0 ms 204 KB Output is correct
5 Correct 0 ms 204 KB Output is correct
6 Correct 10 ms 1228 KB Output is correct
7 Correct 253 ms 22060 KB Output is correct
8 Correct 1 ms 280 KB Output is correct
9 Correct 1 ms 204 KB Output is correct
10 Correct 0 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 273 ms 22024 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 716 KB Output is correct
17 Correct 110 ms 12176 KB Output is correct
18 Correct 1 ms 204 KB Output is correct
19 Correct 0 ms 204 KB Output is correct
20 Correct 72 ms 5764 KB Output is correct
21 Correct 246 ms 22008 KB Output is correct
22 Correct 230 ms 22084 KB Output is correct
23 Correct 244 ms 22036 KB Output is correct
24 Correct 256 ms 22032 KB Output is correct
25 Correct 109 ms 12164 KB Output is correct
26 Correct 101 ms 12180 KB Output is correct
27 Correct 263 ms 22032 KB Output is correct
28 Correct 263 ms 22140 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 204 KB Output is correct
2 Correct 0 ms 204 KB Output is correct
3 Correct 0 ms 204 KB Output is correct
4 Correct 0 ms 204 KB Output is correct
5 Correct 0 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 10 ms 1224 KB Output is correct
9 Correct 282 ms 22032 KB Output is correct
10 Correct 1 ms 204 KB Output is correct
11 Correct 1 ms 204 KB Output is correct
12 Correct 14 ms 1184 KB Output is correct
13 Correct 302 ms 22024 KB Output is correct
14 Correct 1 ms 204 KB Output is correct
15 Correct 1 ms 236 KB Output is correct
16 Correct 5 ms 716 KB Output is correct
17 Correct 109 ms 12180 KB Output is correct
18 Correct 1 ms 204 KB Output is correct
19 Correct 0 ms 204 KB Output is correct
20 Correct 1 ms 204 KB Output is correct
21 Correct 61 ms 5812 KB Output is correct
22 Correct 241 ms 22024 KB Output is correct
23 Correct 267 ms 22004 KB Output is correct
24 Correct 259 ms 22020 KB Output is correct
25 Correct 97 ms 12148 KB Output is correct
26 Correct 100 ms 12180 KB Output is correct
27 Correct 247 ms 22028 KB Output is correct
28 Correct 243 ms 22084 KB Output is correct
29 Correct 108 ms 12180 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 0 ms 204 KB Output is correct
4 Correct 70 ms 5700 KB Output is correct
5 Correct 264 ms 22116 KB Output is correct
6 Correct 234 ms 22024 KB Output is correct
7 Correct 260 ms 22016 KB Output is correct
8 Correct 1 ms 204 KB Output is correct
9 Correct 59 ms 5696 KB Output is correct
10 Correct 253 ms 22020 KB Output is correct
11 Correct 231 ms 22208 KB Output is correct
12 Correct 248 ms 22128 KB Output is correct
13 Correct 0 ms 204 KB Output is correct
14 Correct 1 ms 348 KB Output is correct
15 Correct 1 ms 204 KB Output is correct
16 Correct 59 ms 5724 KB Output is correct
17 Correct 238 ms 22120 KB Output is correct
18 Correct 235 ms 22068 KB Output is correct
19 Correct 256 ms 22124 KB Output is correct
20 Correct 248 ms 22024 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 0 ms 204 KB Output is correct
4 Correct 0 ms 204 KB Output is correct
5 Correct 0 ms 204 KB Output is correct
6 Correct 10 ms 1228 KB Output is correct
7 Correct 253 ms 22060 KB Output is correct
8 Correct 1 ms 280 KB Output is correct
9 Correct 1 ms 204 KB Output is correct
10 Correct 0 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 273 ms 22024 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 716 KB Output is correct
17 Correct 110 ms 12176 KB Output is correct
18 Correct 1 ms 204 KB Output is correct
19 Correct 0 ms 204 KB Output is correct
20 Correct 72 ms 5764 KB Output is correct
21 Correct 246 ms 22008 KB Output is correct
22 Correct 230 ms 22084 KB Output is correct
23 Correct 244 ms 22036 KB Output is correct
24 Correct 256 ms 22032 KB Output is correct
25 Correct 109 ms 12164 KB Output is correct
26 Correct 101 ms 12180 KB Output is correct
27 Correct 263 ms 22032 KB Output is correct
28 Correct 263 ms 22140 KB Output is correct
29 Correct 0 ms 204 KB Output is correct
30 Correct 0 ms 204 KB Output is correct
31 Correct 0 ms 204 KB Output is correct
32 Correct 0 ms 204 KB Output is correct
33 Correct 0 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 10 ms 1224 KB Output is correct
37 Correct 282 ms 22032 KB Output is correct
38 Correct 1 ms 204 KB Output is correct
39 Correct 1 ms 204 KB Output is correct
40 Correct 14 ms 1184 KB Output is correct
41 Correct 302 ms 22024 KB Output is correct
42 Correct 1 ms 204 KB Output is correct
43 Correct 1 ms 236 KB Output is correct
44 Correct 5 ms 716 KB Output is correct
45 Correct 109 ms 12180 KB Output is correct
46 Correct 1 ms 204 KB Output is correct
47 Correct 0 ms 204 KB Output is correct
48 Correct 1 ms 204 KB Output is correct
49 Correct 61 ms 5812 KB Output is correct
50 Correct 241 ms 22024 KB Output is correct
51 Correct 267 ms 22004 KB Output is correct
52 Correct 259 ms 22020 KB Output is correct
53 Correct 97 ms 12148 KB Output is correct
54 Correct 100 ms 12180 KB Output is correct
55 Correct 247 ms 22028 KB Output is correct
56 Correct 243 ms 22084 KB Output is correct
57 Correct 108 ms 12180 KB Output is correct
58 Correct 0 ms 204 KB Output is correct
59 Correct 1 ms 204 KB Output is correct
60 Correct 7 ms 716 KB Output is correct
61 Correct 116 ms 12168 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 75 ms 5768 KB Output is correct
66 Correct 100 ms 12164 KB Output is correct
67 Correct 106 ms 12228 KB Output is correct
68 Correct 124 ms 12168 KB Output is correct
69 Correct 97 ms 12168 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 0 ms 204 KB Output is correct
4 Correct 0 ms 204 KB Output is correct
5 Correct 0 ms 204 KB Output is correct
6 Correct 10 ms 1228 KB Output is correct
7 Correct 253 ms 22060 KB Output is correct
8 Correct 1 ms 280 KB Output is correct
9 Correct 1 ms 204 KB Output is correct
10 Correct 0 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 273 ms 22024 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 716 KB Output is correct
17 Correct 110 ms 12176 KB Output is correct
18 Correct 1 ms 204 KB Output is correct
19 Correct 0 ms 204 KB Output is correct
20 Correct 72 ms 5764 KB Output is correct
21 Correct 246 ms 22008 KB Output is correct
22 Correct 230 ms 22084 KB Output is correct
23 Correct 244 ms 22036 KB Output is correct
24 Correct 256 ms 22032 KB Output is correct
25 Correct 109 ms 12164 KB Output is correct
26 Correct 101 ms 12180 KB Output is correct
27 Correct 263 ms 22032 KB Output is correct
28 Correct 263 ms 22140 KB Output is correct
29 Correct 0 ms 204 KB Output is correct
30 Correct 0 ms 204 KB Output is correct
31 Correct 0 ms 204 KB Output is correct
32 Correct 0 ms 204 KB Output is correct
33 Correct 0 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 10 ms 1224 KB Output is correct
37 Correct 282 ms 22032 KB Output is correct
38 Correct 1 ms 204 KB Output is correct
39 Correct 1 ms 204 KB Output is correct
40 Correct 14 ms 1184 KB Output is correct
41 Correct 302 ms 22024 KB Output is correct
42 Correct 1 ms 204 KB Output is correct
43 Correct 1 ms 236 KB Output is correct
44 Correct 5 ms 716 KB Output is correct
45 Correct 109 ms 12180 KB Output is correct
46 Correct 1 ms 204 KB Output is correct
47 Correct 0 ms 204 KB Output is correct
48 Correct 1 ms 204 KB Output is correct
49 Correct 61 ms 5812 KB Output is correct
50 Correct 241 ms 22024 KB Output is correct
51 Correct 267 ms 22004 KB Output is correct
52 Correct 259 ms 22020 KB Output is correct
53 Correct 97 ms 12148 KB Output is correct
54 Correct 100 ms 12180 KB Output is correct
55 Correct 247 ms 22028 KB Output is correct
56 Correct 243 ms 22084 KB Output is correct
57 Correct 108 ms 12180 KB Output is correct
58 Correct 1 ms 204 KB Output is correct
59 Correct 1 ms 204 KB Output is correct
60 Correct 0 ms 204 KB Output is correct
61 Correct 70 ms 5700 KB Output is correct
62 Correct 264 ms 22116 KB Output is correct
63 Correct 234 ms 22024 KB Output is correct
64 Correct 260 ms 22016 KB Output is correct
65 Correct 1 ms 204 KB Output is correct
66 Correct 59 ms 5696 KB Output is correct
67 Correct 253 ms 22020 KB Output is correct
68 Correct 231 ms 22208 KB Output is correct
69 Correct 248 ms 22128 KB Output is correct
70 Correct 0 ms 204 KB Output is correct
71 Correct 1 ms 348 KB Output is correct
72 Correct 1 ms 204 KB Output is correct
73 Correct 59 ms 5724 KB Output is correct
74 Correct 238 ms 22120 KB Output is correct
75 Correct 235 ms 22068 KB Output is correct
76 Correct 256 ms 22124 KB Output is correct
77 Correct 248 ms 22024 KB Output is correct
78 Correct 0 ms 204 KB Output is correct
79 Correct 1 ms 204 KB Output is correct
80 Correct 7 ms 716 KB Output is correct
81 Correct 116 ms 12168 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 75 ms 5768 KB Output is correct
86 Correct 100 ms 12164 KB Output is correct
87 Correct 106 ms 12228 KB Output is correct
88 Correct 124 ms 12168 KB Output is correct
89 Correct 97 ms 12168 KB Output is correct
90 Correct 0 ms 204 KB Output is correct
91 Correct 1 ms 204 KB Output is correct
92 Correct 5 ms 716 KB Output is correct
93 Correct 112 ms 12168 KB Output is correct
94 Correct 1 ms 204 KB Output is correct
95 Correct 0 ms 204 KB Output is correct
96 Correct 0 ms 204 KB Output is correct
97 Correct 26 ms 3268 KB Output is correct
98 Correct 110 ms 12168 KB Output is correct
99 Correct 111 ms 12228 KB Output is correct
100 Correct 97 ms 12228 KB Output is correct
101 Correct 108 ms 12176 KB Output is correct
102 Correct 105 ms 12268 KB Output is correct
103 Correct 117 ms 12168 KB Output is correct
104 Correct 122 ms 12296 KB Output is correct
105 Correct 108 ms 12172 KB Output is correct