#include "supertrees.h"
#include<bits/stdc++.h>
#define lcm(a,b) (a/__gcd(a,b))*b
#define fast ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define ll long long int
#define vi vector<int>
#define vll vector<ll>
#define pb push_back
#define F first
#define S second
//"\n"
using namespace std;
const int tam=1001;
int P0[tam];
int P1[tam];
int P2[tam];
void init(){
for(int i=0;i<tam;i++){
P0[i]=P1[i]=P2[i]=i;
}
}
int find0(int a){
if(a==P0[a])return a;
return P0[a]=find0(P0[a]);
}
int find1(int a){
if(a==P1[a])return a;
return P1[a]=find1(P1[a]);
}
int find2(int a){
if(a==P2[a])return a;
return P2[a]=find2(P2[a]);
}
void union0(int a,int b){
a=find0(a);b=find0(b);
P0[a]=b;
}
void union1(int a,int b){
a=find1(a);b=find1(b);
P1[a]=b;
}
void union2(int a,int b){
a=find2(a);b=find2(b);
P2[a]=b;
}
int construct(vector<vi> p){
init();
int n = p.size();
vector<vector<int> > res(n,vector<int>(n,0));
for(int i=0;i<n;i++){
for(int l=0;l<n;l++){
if(p[i][l]==3)return 0;
if(p[i][l]!=0){
union0(i,l);
}
}
}
for(int i=0;i<n;i++){
for(int l=i+1;l<n;l++){
if(p[i][l]==0 && find0(i)==find0(l)){
return 0;
}
}
}
for(int i=0;i<n;i++){
for(int l=i+1;l<n;l++){
if(p[i][l]==1){
union1(i,l);
}
}
}
for(int i=0;i<n;i++){
int v=find1(i);
if(i!=v)res[i][v]=res[v][i]=1;
for(int l=i+1;l<n;l++){
if(p[i][l]==2 && find1(i)==find1(l)){
return 0;
}
if(p[i][l]==2){
union2(find1(i),find1(l));
}
}
}
vector<vi>G(n+1);
for(int i=0;i<n;i++){
int e=find2(i);
G[e].pb(i);
}
for(int i=0;i<n;i++){
if(G[i].size()<=1)continue;
if(G[i].size()==2)return 0;
int u,v;
for(int l=0;l<G[i].size()-1;l++){
u=G[i][l],v=G[i][l+1];
res[u][v]=res[v][u]=1;
}
u=G[i][0],v=G[i][G[i].size()-1];
res[u][v]=res[v][u]=1;
}
build(res);
return 1;
}
/*
4
0 1 1 1
1 0 1 1
1 1 0 1
1 1 1 0
4
0 2 2 2
2 0 2 2
2 2 0 2
2 2 2 0
*/
//que no haya p[i][j]=3
//1° que no haya un p[i][j] en los mega conjuntos
//2° saco los conjuntos p[i][j]=1
//3° que no haya p[i][j]=2 en los conjuntos de 1
//ahora ya puedo tomar los arboles como un solo nodo
//pq tengo asegurado que si es que lo quiero conectar con otro arbol
//todos los nodos de mi arbol con los del otro igual a 2 por punto 3°
//4° intento hacer ciclos con en subtask 2/3
//terminado 100 pts izi
//IMPORTANTE
//puedo hacer el punto cuatro porque tengo garantizado que si un nod quiere ciclo con otro
//todos los nodos del arbol igual quieren pq si no pertenecerian al mismo arbol o ya hubiese retornado 0 en el punto 1
Compilation message
supertrees.cpp: In function 'int construct(std::vector<std::vector<int> >)':
supertrees.cpp:94:22: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
94 | for(int l=0;l<G[i].size()-1;l++){
| ~^~~~~~~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
364 KB |
Output is correct |
2 |
Correct |
1 ms |
364 KB |
Output is correct |
3 |
Correct |
1 ms |
364 KB |
Output is correct |
4 |
Correct |
1 ms |
364 KB |
Output is correct |
5 |
Correct |
1 ms |
364 KB |
Output is correct |
6 |
Correct |
15 ms |
1260 KB |
Output is correct |
7 |
Correct |
259 ms |
23016 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
364 KB |
Output is correct |
2 |
Correct |
1 ms |
364 KB |
Output is correct |
3 |
Correct |
1 ms |
364 KB |
Output is correct |
4 |
Correct |
1 ms |
364 KB |
Output is correct |
5 |
Correct |
1 ms |
364 KB |
Output is correct |
6 |
Correct |
15 ms |
1260 KB |
Output is correct |
7 |
Correct |
259 ms |
23016 KB |
Output is correct |
8 |
Correct |
1 ms |
364 KB |
Output is correct |
9 |
Correct |
1 ms |
364 KB |
Output is correct |
10 |
Correct |
1 ms |
364 KB |
Output is correct |
11 |
Correct |
1 ms |
364 KB |
Output is correct |
12 |
Correct |
11 ms |
1260 KB |
Output is correct |
13 |
Correct |
247 ms |
23252 KB |
Output is correct |
14 |
Correct |
1 ms |
364 KB |
Output is correct |
15 |
Correct |
1 ms |
364 KB |
Output is correct |
16 |
Correct |
6 ms |
876 KB |
Output is correct |
17 |
Correct |
111 ms |
13036 KB |
Output is correct |
18 |
Correct |
1 ms |
364 KB |
Output is correct |
19 |
Correct |
1 ms |
364 KB |
Output is correct |
20 |
Correct |
64 ms |
6380 KB |
Output is correct |
21 |
Correct |
275 ms |
23020 KB |
Output is correct |
22 |
Correct |
264 ms |
23148 KB |
Output is correct |
23 |
Correct |
277 ms |
23020 KB |
Output is correct |
24 |
Correct |
262 ms |
23012 KB |
Output is correct |
25 |
Correct |
102 ms |
13036 KB |
Output is correct |
26 |
Correct |
103 ms |
13036 KB |
Output is correct |
27 |
Correct |
266 ms |
23148 KB |
Output is correct |
28 |
Correct |
252 ms |
22740 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
364 KB |
Output is correct |
2 |
Correct |
1 ms |
364 KB |
Output is correct |
3 |
Correct |
1 ms |
364 KB |
Output is correct |
4 |
Correct |
2 ms |
364 KB |
Output is correct |
5 |
Correct |
1 ms |
364 KB |
Output is correct |
6 |
Correct |
1 ms |
364 KB |
Output is correct |
7 |
Correct |
1 ms |
364 KB |
Output is correct |
8 |
Correct |
11 ms |
1260 KB |
Output is correct |
9 |
Correct |
250 ms |
23148 KB |
Output is correct |
10 |
Correct |
1 ms |
364 KB |
Output is correct |
11 |
Correct |
1 ms |
384 KB |
Output is correct |
12 |
Correct |
11 ms |
1260 KB |
Output is correct |
13 |
Correct |
247 ms |
23148 KB |
Output is correct |
14 |
Correct |
1 ms |
364 KB |
Output is correct |
15 |
Correct |
1 ms |
364 KB |
Output is correct |
16 |
Correct |
6 ms |
876 KB |
Output is correct |
17 |
Correct |
138 ms |
13164 KB |
Output is correct |
18 |
Correct |
1 ms |
364 KB |
Output is correct |
19 |
Correct |
1 ms |
364 KB |
Output is correct |
20 |
Correct |
1 ms |
364 KB |
Output is correct |
21 |
Correct |
64 ms |
6528 KB |
Output is correct |
22 |
Correct |
259 ms |
23268 KB |
Output is correct |
23 |
Correct |
254 ms |
23148 KB |
Output is correct |
24 |
Correct |
286 ms |
23148 KB |
Output is correct |
25 |
Correct |
104 ms |
13292 KB |
Output is correct |
26 |
Correct |
104 ms |
13164 KB |
Output is correct |
27 |
Correct |
253 ms |
23148 KB |
Output is correct |
28 |
Correct |
267 ms |
23420 KB |
Output is correct |
29 |
Correct |
106 ms |
13292 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
364 KB |
Output is correct |
2 |
Correct |
1 ms |
364 KB |
Output is correct |
3 |
Correct |
2 ms |
500 KB |
Output is correct |
4 |
Correct |
64 ms |
6380 KB |
Output is correct |
5 |
Correct |
253 ms |
22892 KB |
Output is correct |
6 |
Correct |
271 ms |
22892 KB |
Output is correct |
7 |
Correct |
264 ms |
22892 KB |
Output is correct |
8 |
Correct |
1 ms |
364 KB |
Output is correct |
9 |
Correct |
64 ms |
6380 KB |
Output is correct |
10 |
Correct |
257 ms |
23020 KB |
Output is correct |
11 |
Correct |
254 ms |
22764 KB |
Output is correct |
12 |
Correct |
272 ms |
22764 KB |
Output is correct |
13 |
Correct |
1 ms |
364 KB |
Output is correct |
14 |
Correct |
1 ms |
364 KB |
Output is correct |
15 |
Correct |
1 ms |
364 KB |
Output is correct |
16 |
Correct |
64 ms |
6380 KB |
Output is correct |
17 |
Correct |
251 ms |
22892 KB |
Output is correct |
18 |
Correct |
260 ms |
22892 KB |
Output is correct |
19 |
Correct |
250 ms |
22756 KB |
Output is correct |
20 |
Correct |
251 ms |
22636 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
364 KB |
Output is correct |
2 |
Correct |
1 ms |
364 KB |
Output is correct |
3 |
Correct |
1 ms |
364 KB |
Output is correct |
4 |
Correct |
1 ms |
364 KB |
Output is correct |
5 |
Correct |
1 ms |
364 KB |
Output is correct |
6 |
Correct |
15 ms |
1260 KB |
Output is correct |
7 |
Correct |
259 ms |
23016 KB |
Output is correct |
8 |
Correct |
1 ms |
364 KB |
Output is correct |
9 |
Correct |
1 ms |
364 KB |
Output is correct |
10 |
Correct |
1 ms |
364 KB |
Output is correct |
11 |
Correct |
1 ms |
364 KB |
Output is correct |
12 |
Correct |
11 ms |
1260 KB |
Output is correct |
13 |
Correct |
247 ms |
23252 KB |
Output is correct |
14 |
Correct |
1 ms |
364 KB |
Output is correct |
15 |
Correct |
1 ms |
364 KB |
Output is correct |
16 |
Correct |
6 ms |
876 KB |
Output is correct |
17 |
Correct |
111 ms |
13036 KB |
Output is correct |
18 |
Correct |
1 ms |
364 KB |
Output is correct |
19 |
Correct |
1 ms |
364 KB |
Output is correct |
20 |
Correct |
64 ms |
6380 KB |
Output is correct |
21 |
Correct |
275 ms |
23020 KB |
Output is correct |
22 |
Correct |
264 ms |
23148 KB |
Output is correct |
23 |
Correct |
277 ms |
23020 KB |
Output is correct |
24 |
Correct |
262 ms |
23012 KB |
Output is correct |
25 |
Correct |
102 ms |
13036 KB |
Output is correct |
26 |
Correct |
103 ms |
13036 KB |
Output is correct |
27 |
Correct |
266 ms |
23148 KB |
Output is correct |
28 |
Correct |
252 ms |
22740 KB |
Output is correct |
29 |
Correct |
1 ms |
364 KB |
Output is correct |
30 |
Correct |
1 ms |
364 KB |
Output is correct |
31 |
Correct |
1 ms |
364 KB |
Output is correct |
32 |
Correct |
2 ms |
364 KB |
Output is correct |
33 |
Correct |
1 ms |
364 KB |
Output is correct |
34 |
Correct |
1 ms |
364 KB |
Output is correct |
35 |
Correct |
1 ms |
364 KB |
Output is correct |
36 |
Correct |
11 ms |
1260 KB |
Output is correct |
37 |
Correct |
250 ms |
23148 KB |
Output is correct |
38 |
Correct |
1 ms |
364 KB |
Output is correct |
39 |
Correct |
1 ms |
384 KB |
Output is correct |
40 |
Correct |
11 ms |
1260 KB |
Output is correct |
41 |
Correct |
247 ms |
23148 KB |
Output is correct |
42 |
Correct |
1 ms |
364 KB |
Output is correct |
43 |
Correct |
1 ms |
364 KB |
Output is correct |
44 |
Correct |
6 ms |
876 KB |
Output is correct |
45 |
Correct |
138 ms |
13164 KB |
Output is correct |
46 |
Correct |
1 ms |
364 KB |
Output is correct |
47 |
Correct |
1 ms |
364 KB |
Output is correct |
48 |
Correct |
1 ms |
364 KB |
Output is correct |
49 |
Correct |
64 ms |
6528 KB |
Output is correct |
50 |
Correct |
259 ms |
23268 KB |
Output is correct |
51 |
Correct |
254 ms |
23148 KB |
Output is correct |
52 |
Correct |
286 ms |
23148 KB |
Output is correct |
53 |
Correct |
104 ms |
13292 KB |
Output is correct |
54 |
Correct |
104 ms |
13164 KB |
Output is correct |
55 |
Correct |
253 ms |
23148 KB |
Output is correct |
56 |
Correct |
267 ms |
23420 KB |
Output is correct |
57 |
Correct |
106 ms |
13292 KB |
Output is correct |
58 |
Correct |
1 ms |
364 KB |
Output is correct |
59 |
Correct |
1 ms |
364 KB |
Output is correct |
60 |
Correct |
6 ms |
876 KB |
Output is correct |
61 |
Correct |
113 ms |
12780 KB |
Output is correct |
62 |
Correct |
1 ms |
364 KB |
Output is correct |
63 |
Correct |
2 ms |
364 KB |
Output is correct |
64 |
Correct |
1 ms |
364 KB |
Output is correct |
65 |
Correct |
65 ms |
6380 KB |
Output is correct |
66 |
Correct |
105 ms |
12756 KB |
Output is correct |
67 |
Correct |
114 ms |
12652 KB |
Output is correct |
68 |
Correct |
101 ms |
12652 KB |
Output is correct |
69 |
Correct |
122 ms |
12772 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
364 KB |
Output is correct |
2 |
Correct |
1 ms |
364 KB |
Output is correct |
3 |
Correct |
1 ms |
364 KB |
Output is correct |
4 |
Correct |
1 ms |
364 KB |
Output is correct |
5 |
Correct |
1 ms |
364 KB |
Output is correct |
6 |
Correct |
15 ms |
1260 KB |
Output is correct |
7 |
Correct |
259 ms |
23016 KB |
Output is correct |
8 |
Correct |
1 ms |
364 KB |
Output is correct |
9 |
Correct |
1 ms |
364 KB |
Output is correct |
10 |
Correct |
1 ms |
364 KB |
Output is correct |
11 |
Correct |
1 ms |
364 KB |
Output is correct |
12 |
Correct |
11 ms |
1260 KB |
Output is correct |
13 |
Correct |
247 ms |
23252 KB |
Output is correct |
14 |
Correct |
1 ms |
364 KB |
Output is correct |
15 |
Correct |
1 ms |
364 KB |
Output is correct |
16 |
Correct |
6 ms |
876 KB |
Output is correct |
17 |
Correct |
111 ms |
13036 KB |
Output is correct |
18 |
Correct |
1 ms |
364 KB |
Output is correct |
19 |
Correct |
1 ms |
364 KB |
Output is correct |
20 |
Correct |
64 ms |
6380 KB |
Output is correct |
21 |
Correct |
275 ms |
23020 KB |
Output is correct |
22 |
Correct |
264 ms |
23148 KB |
Output is correct |
23 |
Correct |
277 ms |
23020 KB |
Output is correct |
24 |
Correct |
262 ms |
23012 KB |
Output is correct |
25 |
Correct |
102 ms |
13036 KB |
Output is correct |
26 |
Correct |
103 ms |
13036 KB |
Output is correct |
27 |
Correct |
266 ms |
23148 KB |
Output is correct |
28 |
Correct |
252 ms |
22740 KB |
Output is correct |
29 |
Correct |
1 ms |
364 KB |
Output is correct |
30 |
Correct |
1 ms |
364 KB |
Output is correct |
31 |
Correct |
1 ms |
364 KB |
Output is correct |
32 |
Correct |
2 ms |
364 KB |
Output is correct |
33 |
Correct |
1 ms |
364 KB |
Output is correct |
34 |
Correct |
1 ms |
364 KB |
Output is correct |
35 |
Correct |
1 ms |
364 KB |
Output is correct |
36 |
Correct |
11 ms |
1260 KB |
Output is correct |
37 |
Correct |
250 ms |
23148 KB |
Output is correct |
38 |
Correct |
1 ms |
364 KB |
Output is correct |
39 |
Correct |
1 ms |
384 KB |
Output is correct |
40 |
Correct |
11 ms |
1260 KB |
Output is correct |
41 |
Correct |
247 ms |
23148 KB |
Output is correct |
42 |
Correct |
1 ms |
364 KB |
Output is correct |
43 |
Correct |
1 ms |
364 KB |
Output is correct |
44 |
Correct |
6 ms |
876 KB |
Output is correct |
45 |
Correct |
138 ms |
13164 KB |
Output is correct |
46 |
Correct |
1 ms |
364 KB |
Output is correct |
47 |
Correct |
1 ms |
364 KB |
Output is correct |
48 |
Correct |
1 ms |
364 KB |
Output is correct |
49 |
Correct |
64 ms |
6528 KB |
Output is correct |
50 |
Correct |
259 ms |
23268 KB |
Output is correct |
51 |
Correct |
254 ms |
23148 KB |
Output is correct |
52 |
Correct |
286 ms |
23148 KB |
Output is correct |
53 |
Correct |
104 ms |
13292 KB |
Output is correct |
54 |
Correct |
104 ms |
13164 KB |
Output is correct |
55 |
Correct |
253 ms |
23148 KB |
Output is correct |
56 |
Correct |
267 ms |
23420 KB |
Output is correct |
57 |
Correct |
106 ms |
13292 KB |
Output is correct |
58 |
Correct |
1 ms |
364 KB |
Output is correct |
59 |
Correct |
1 ms |
364 KB |
Output is correct |
60 |
Correct |
2 ms |
500 KB |
Output is correct |
61 |
Correct |
64 ms |
6380 KB |
Output is correct |
62 |
Correct |
253 ms |
22892 KB |
Output is correct |
63 |
Correct |
271 ms |
22892 KB |
Output is correct |
64 |
Correct |
264 ms |
22892 KB |
Output is correct |
65 |
Correct |
1 ms |
364 KB |
Output is correct |
66 |
Correct |
64 ms |
6380 KB |
Output is correct |
67 |
Correct |
257 ms |
23020 KB |
Output is correct |
68 |
Correct |
254 ms |
22764 KB |
Output is correct |
69 |
Correct |
272 ms |
22764 KB |
Output is correct |
70 |
Correct |
1 ms |
364 KB |
Output is correct |
71 |
Correct |
1 ms |
364 KB |
Output is correct |
72 |
Correct |
1 ms |
364 KB |
Output is correct |
73 |
Correct |
64 ms |
6380 KB |
Output is correct |
74 |
Correct |
251 ms |
22892 KB |
Output is correct |
75 |
Correct |
260 ms |
22892 KB |
Output is correct |
76 |
Correct |
250 ms |
22756 KB |
Output is correct |
77 |
Correct |
251 ms |
22636 KB |
Output is correct |
78 |
Correct |
1 ms |
364 KB |
Output is correct |
79 |
Correct |
1 ms |
364 KB |
Output is correct |
80 |
Correct |
6 ms |
876 KB |
Output is correct |
81 |
Correct |
113 ms |
12780 KB |
Output is correct |
82 |
Correct |
1 ms |
364 KB |
Output is correct |
83 |
Correct |
2 ms |
364 KB |
Output is correct |
84 |
Correct |
1 ms |
364 KB |
Output is correct |
85 |
Correct |
65 ms |
6380 KB |
Output is correct |
86 |
Correct |
105 ms |
12756 KB |
Output is correct |
87 |
Correct |
114 ms |
12652 KB |
Output is correct |
88 |
Correct |
101 ms |
12652 KB |
Output is correct |
89 |
Correct |
122 ms |
12772 KB |
Output is correct |
90 |
Correct |
1 ms |
364 KB |
Output is correct |
91 |
Correct |
1 ms |
364 KB |
Output is correct |
92 |
Correct |
5 ms |
876 KB |
Output is correct |
93 |
Correct |
96 ms |
12652 KB |
Output is correct |
94 |
Correct |
1 ms |
236 KB |
Output is correct |
95 |
Correct |
1 ms |
364 KB |
Output is correct |
96 |
Correct |
2 ms |
364 KB |
Output is correct |
97 |
Correct |
26 ms |
3820 KB |
Output is correct |
98 |
Correct |
102 ms |
12652 KB |
Output is correct |
99 |
Correct |
100 ms |
12652 KB |
Output is correct |
100 |
Correct |
117 ms |
12912 KB |
Output is correct |
101 |
Correct |
102 ms |
12652 KB |
Output is correct |
102 |
Correct |
89 ms |
12652 KB |
Output is correct |
103 |
Correct |
88 ms |
12652 KB |
Output is correct |
104 |
Correct |
115 ms |
12652 KB |
Output is correct |
105 |
Correct |
111 ms |
12652 KB |
Output is correct |