#include "supertrees.h"
#include <bits/stdc++.h>
#define ll long long
#define ff first
#define ss second
#define pb push_back
using namespace std;
vector<vector<int>>P;
vector<std::vector<int>> answer;
bool vis[1003];
int dsu1[1003];
int n;
const bool debug = false;
void ponerPuente(int a, int b){
answer[a][b] = 1;
answer[b][a] = 1;
if(debug)cout << "puente puesto " << a << " - " << b << endl;
}
int findd(int k){
if(dsu1[k] == k )return k;
return dsu1[k] = findd(dsu1[k]);
}
void join1(int a, int b){
a = findd(a);
b = findd(b);
if(a == b)return ;
dsu1[a] = b;
}
int construct(std::vector<std::vector<int>> p) {
n = p.size();
P = p;
memset(vis, false, sizeof vis);
for(int i = 0 ; i < n ; i ++)dsu1[i] = i;
vector<int> row;
for(int j = 0 ; j < n ; j ++)row.pb(0);
for (int i = 0; i < n; i++) {
answer.push_back(row);
}
bool isInG[n+1];
memset(isInG, false, sizeof isInG);
for(int i = 0 ; i < n ; i ++){
if(vis[i])continue;
set<int>grupo1;
for(int j = 0 ; j < n ; j ++){
if(p[i][j] == 1){
grupo1.insert(j);
isInG[j] = true;
}
}
vector<int>g;
for(auto j :grupo1){
g.pb(j);
}
for(auto j : g){
for(int x = 0 ; x < n ; x ++){
if(p[j][x] == 1 and !isInG[x])return 0;
if(p[j][x] == 0 and isInG[x])return 0;
if(p[j][x] == 2 and isInG[x])return 0; // !!
}
}
for(auto j : g){
isInG[j] = false;
vis[j] = true;
}
for(int j = 1 ; j < g.size() ; j ++){
ponerPuente(g[j-1], g[j]);
join1(g[j-1], g[j]);
}
}
//cout << " uniones con 1 hechas " << endl;
memset(vis, false, sizeof vis);
for(int i = 0 ; i < n ; i++){
if(vis[i])continue;
vis[i] = true;
set<int>grupo2;
for(int j = 0 ; j < n ; j ++){
if(p[i][j] == 2){
if(vis[j])return 0;
grupo2.insert(j);
isInG[j] = true;
}
}
if(grupo2.size() == 0)continue;
grupo2.insert(i);
isInG[i] = true;
if(grupo2.size() <= 2)return 0;
vector<int>g;
if(debug)cout << "Nuevo grupo de 2 desde " << i << endl;
for(auto j :grupo2){
g.pb(j);
if(debug)cout << j << " " ;
}
if(debug)cout << endl;
for(auto j : g){
if(!isInG[j])continue;
//cout << "revisando en " << j << endl;
for(int x = 0 ; x < n ; x ++){
if(p[j][x] == 1 and isInG[x] and x != j){
isInG[x] = false;
grupo2.erase(x);
if(debug)cout << x << " eliminado " << endl;
}
if(p[j][x] == 0 and isInG[x])return 0;
}
}
for(auto j : g)isInG[j] = false;
g.clear();
for(auto j :grupo2)g.pb(j);
if(g.size() <= 2)return 0;
for(int j = 1 ; j < g.size() ; j ++){
ponerPuente(g[j-1], g[j]);
}
ponerPuente(g[0], g.back());
vector<int>allNodes;
for(int i = 0 ; i < n ; i ++){
if(p[g[0]][i] > 0)allNodes.pb(i);
}
for(auto j : allNodes)isInG[j] = true;
for(int j = 0 ; j < allNodes.size() ; j ++){
//cout << "checking " << i << endl;
for(int x = 0 ; x < n ; x ++){
//cout << "with " << x << endl;
//cout << isInG[x] << " " << p[allNodes[j]][x] << endl;
if(findd(allNodes[j]) == findd(x) and isInG[x])continue;
if(findd(allNodes[j]) == findd(x))return 0;
if(isInG[x] and p[allNodes[j]][x] != 2) return 0;
if(!isInG[x] and p[allNodes[j]][x] != 0)return 0;
}
}
for(auto j : allNodes){
vis[j] = true;
isInG[j] = false;
}
}
build(answer);
return 1;
}
Compilation message
supertrees.cpp: In function 'int construct(std::vector<std::vector<int> >)':
supertrees.cpp:70:21: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
70 | for(int j = 1 ; j < g.size() ; j ++){
| ~~^~~~~~~~~~
supertrees.cpp:115:21: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
115 | for(int j = 1 ; j < g.size() ; j ++){
| ~~^~~~~~~~~~
supertrees.cpp:126:21: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
126 | for(int j = 0 ; j < allNodes.size() ; j ++){
| ~~^~~~~~~~~~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
0 ms |
212 KB |
Output is correct |
3 |
Correct |
0 ms |
212 KB |
Output is correct |
4 |
Correct |
0 ms |
212 KB |
Output is correct |
5 |
Correct |
0 ms |
212 KB |
Output is correct |
6 |
Correct |
7 ms |
1364 KB |
Output is correct |
7 |
Correct |
156 ms |
25992 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
0 ms |
212 KB |
Output is correct |
3 |
Correct |
0 ms |
212 KB |
Output is correct |
4 |
Correct |
0 ms |
212 KB |
Output is correct |
5 |
Correct |
0 ms |
212 KB |
Output is correct |
6 |
Correct |
7 ms |
1364 KB |
Output is correct |
7 |
Correct |
156 ms |
25992 KB |
Output is correct |
8 |
Correct |
0 ms |
212 KB |
Output is correct |
9 |
Correct |
0 ms |
212 KB |
Output is correct |
10 |
Correct |
0 ms |
212 KB |
Output is correct |
11 |
Correct |
0 ms |
212 KB |
Output is correct |
12 |
Correct |
7 ms |
1364 KB |
Output is correct |
13 |
Correct |
156 ms |
26000 KB |
Output is correct |
14 |
Correct |
1 ms |
212 KB |
Output is correct |
15 |
Correct |
0 ms |
212 KB |
Output is correct |
16 |
Correct |
3 ms |
852 KB |
Output is correct |
17 |
Correct |
72 ms |
16020 KB |
Output is correct |
18 |
Correct |
0 ms |
212 KB |
Output is correct |
19 |
Correct |
0 ms |
212 KB |
Output is correct |
20 |
Correct |
39 ms |
6676 KB |
Output is correct |
21 |
Correct |
156 ms |
26000 KB |
Output is correct |
22 |
Correct |
155 ms |
25988 KB |
Output is correct |
23 |
Correct |
159 ms |
25932 KB |
Output is correct |
24 |
Correct |
156 ms |
25932 KB |
Output is correct |
25 |
Correct |
70 ms |
16204 KB |
Output is correct |
26 |
Correct |
65 ms |
16008 KB |
Output is correct |
27 |
Correct |
171 ms |
26004 KB |
Output is correct |
28 |
Correct |
156 ms |
26000 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
0 ms |
212 KB |
Output is correct |
3 |
Correct |
0 ms |
212 KB |
Output is correct |
4 |
Correct |
0 ms |
212 KB |
Output is correct |
5 |
Correct |
0 ms |
212 KB |
Output is correct |
6 |
Correct |
0 ms |
212 KB |
Output is correct |
7 |
Correct |
0 ms |
212 KB |
Output is correct |
8 |
Correct |
7 ms |
1364 KB |
Output is correct |
9 |
Correct |
156 ms |
26012 KB |
Output is correct |
10 |
Correct |
0 ms |
212 KB |
Output is correct |
11 |
Correct |
0 ms |
212 KB |
Output is correct |
12 |
Correct |
7 ms |
1324 KB |
Output is correct |
13 |
Correct |
170 ms |
25896 KB |
Output is correct |
14 |
Correct |
0 ms |
212 KB |
Output is correct |
15 |
Correct |
0 ms |
212 KB |
Output is correct |
16 |
Correct |
3 ms |
852 KB |
Output is correct |
17 |
Correct |
75 ms |
16004 KB |
Output is correct |
18 |
Correct |
0 ms |
212 KB |
Output is correct |
19 |
Correct |
0 ms |
212 KB |
Output is correct |
20 |
Correct |
0 ms |
212 KB |
Output is correct |
21 |
Correct |
42 ms |
6668 KB |
Output is correct |
22 |
Correct |
168 ms |
26008 KB |
Output is correct |
23 |
Correct |
167 ms |
25952 KB |
Output is correct |
24 |
Correct |
178 ms |
26108 KB |
Output is correct |
25 |
Correct |
67 ms |
16008 KB |
Output is correct |
26 |
Correct |
80 ms |
16076 KB |
Output is correct |
27 |
Correct |
168 ms |
25996 KB |
Output is correct |
28 |
Correct |
174 ms |
26004 KB |
Output is correct |
29 |
Correct |
73 ms |
16012 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
0 ms |
212 KB |
Output is correct |
3 |
Correct |
0 ms |
212 KB |
Output is correct |
4 |
Correct |
39 ms |
6744 KB |
Output is correct |
5 |
Correct |
156 ms |
25992 KB |
Output is correct |
6 |
Correct |
161 ms |
26020 KB |
Output is correct |
7 |
Correct |
160 ms |
25996 KB |
Output is correct |
8 |
Correct |
0 ms |
212 KB |
Output is correct |
9 |
Correct |
42 ms |
6668 KB |
Output is correct |
10 |
Correct |
169 ms |
25988 KB |
Output is correct |
11 |
Correct |
170 ms |
26060 KB |
Output is correct |
12 |
Correct |
178 ms |
25972 KB |
Output is correct |
13 |
Correct |
0 ms |
212 KB |
Output is correct |
14 |
Correct |
0 ms |
212 KB |
Output is correct |
15 |
Correct |
1 ms |
212 KB |
Output is correct |
16 |
Correct |
44 ms |
6740 KB |
Output is correct |
17 |
Correct |
169 ms |
25932 KB |
Output is correct |
18 |
Correct |
169 ms |
25904 KB |
Output is correct |
19 |
Correct |
168 ms |
25988 KB |
Output is correct |
20 |
Correct |
155 ms |
26008 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
0 ms |
212 KB |
Output is correct |
3 |
Correct |
0 ms |
212 KB |
Output is correct |
4 |
Correct |
0 ms |
212 KB |
Output is correct |
5 |
Correct |
0 ms |
212 KB |
Output is correct |
6 |
Correct |
7 ms |
1364 KB |
Output is correct |
7 |
Correct |
156 ms |
25992 KB |
Output is correct |
8 |
Correct |
0 ms |
212 KB |
Output is correct |
9 |
Correct |
0 ms |
212 KB |
Output is correct |
10 |
Correct |
0 ms |
212 KB |
Output is correct |
11 |
Correct |
0 ms |
212 KB |
Output is correct |
12 |
Correct |
7 ms |
1364 KB |
Output is correct |
13 |
Correct |
156 ms |
26000 KB |
Output is correct |
14 |
Correct |
1 ms |
212 KB |
Output is correct |
15 |
Correct |
0 ms |
212 KB |
Output is correct |
16 |
Correct |
3 ms |
852 KB |
Output is correct |
17 |
Correct |
72 ms |
16020 KB |
Output is correct |
18 |
Correct |
0 ms |
212 KB |
Output is correct |
19 |
Correct |
0 ms |
212 KB |
Output is correct |
20 |
Correct |
39 ms |
6676 KB |
Output is correct |
21 |
Correct |
156 ms |
26000 KB |
Output is correct |
22 |
Correct |
155 ms |
25988 KB |
Output is correct |
23 |
Correct |
159 ms |
25932 KB |
Output is correct |
24 |
Correct |
156 ms |
25932 KB |
Output is correct |
25 |
Correct |
70 ms |
16204 KB |
Output is correct |
26 |
Correct |
65 ms |
16008 KB |
Output is correct |
27 |
Correct |
171 ms |
26004 KB |
Output is correct |
28 |
Correct |
156 ms |
26000 KB |
Output is correct |
29 |
Correct |
0 ms |
212 KB |
Output is correct |
30 |
Correct |
0 ms |
212 KB |
Output is correct |
31 |
Correct |
0 ms |
212 KB |
Output is correct |
32 |
Correct |
0 ms |
212 KB |
Output is correct |
33 |
Correct |
0 ms |
212 KB |
Output is correct |
34 |
Correct |
0 ms |
212 KB |
Output is correct |
35 |
Correct |
0 ms |
212 KB |
Output is correct |
36 |
Correct |
7 ms |
1364 KB |
Output is correct |
37 |
Correct |
156 ms |
26012 KB |
Output is correct |
38 |
Correct |
0 ms |
212 KB |
Output is correct |
39 |
Correct |
0 ms |
212 KB |
Output is correct |
40 |
Correct |
7 ms |
1324 KB |
Output is correct |
41 |
Correct |
170 ms |
25896 KB |
Output is correct |
42 |
Correct |
0 ms |
212 KB |
Output is correct |
43 |
Correct |
0 ms |
212 KB |
Output is correct |
44 |
Correct |
3 ms |
852 KB |
Output is correct |
45 |
Correct |
75 ms |
16004 KB |
Output is correct |
46 |
Correct |
0 ms |
212 KB |
Output is correct |
47 |
Correct |
0 ms |
212 KB |
Output is correct |
48 |
Correct |
0 ms |
212 KB |
Output is correct |
49 |
Correct |
42 ms |
6668 KB |
Output is correct |
50 |
Correct |
168 ms |
26008 KB |
Output is correct |
51 |
Correct |
167 ms |
25952 KB |
Output is correct |
52 |
Correct |
178 ms |
26108 KB |
Output is correct |
53 |
Correct |
67 ms |
16008 KB |
Output is correct |
54 |
Correct |
80 ms |
16076 KB |
Output is correct |
55 |
Correct |
168 ms |
25996 KB |
Output is correct |
56 |
Correct |
174 ms |
26004 KB |
Output is correct |
57 |
Correct |
73 ms |
16012 KB |
Output is correct |
58 |
Correct |
0 ms |
212 KB |
Output is correct |
59 |
Correct |
0 ms |
212 KB |
Output is correct |
60 |
Correct |
3 ms |
852 KB |
Output is correct |
61 |
Correct |
68 ms |
16016 KB |
Output is correct |
62 |
Correct |
0 ms |
212 KB |
Output is correct |
63 |
Correct |
0 ms |
212 KB |
Output is correct |
64 |
Correct |
1 ms |
212 KB |
Output is correct |
65 |
Correct |
42 ms |
6672 KB |
Output is correct |
66 |
Correct |
69 ms |
16016 KB |
Output is correct |
67 |
Correct |
65 ms |
16020 KB |
Output is correct |
68 |
Correct |
67 ms |
16008 KB |
Output is correct |
69 |
Correct |
65 ms |
16008 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
0 ms |
212 KB |
Output is correct |
3 |
Correct |
0 ms |
212 KB |
Output is correct |
4 |
Correct |
0 ms |
212 KB |
Output is correct |
5 |
Correct |
0 ms |
212 KB |
Output is correct |
6 |
Correct |
7 ms |
1364 KB |
Output is correct |
7 |
Correct |
156 ms |
25992 KB |
Output is correct |
8 |
Correct |
0 ms |
212 KB |
Output is correct |
9 |
Correct |
0 ms |
212 KB |
Output is correct |
10 |
Correct |
0 ms |
212 KB |
Output is correct |
11 |
Correct |
0 ms |
212 KB |
Output is correct |
12 |
Correct |
7 ms |
1364 KB |
Output is correct |
13 |
Correct |
156 ms |
26000 KB |
Output is correct |
14 |
Correct |
1 ms |
212 KB |
Output is correct |
15 |
Correct |
0 ms |
212 KB |
Output is correct |
16 |
Correct |
3 ms |
852 KB |
Output is correct |
17 |
Correct |
72 ms |
16020 KB |
Output is correct |
18 |
Correct |
0 ms |
212 KB |
Output is correct |
19 |
Correct |
0 ms |
212 KB |
Output is correct |
20 |
Correct |
39 ms |
6676 KB |
Output is correct |
21 |
Correct |
156 ms |
26000 KB |
Output is correct |
22 |
Correct |
155 ms |
25988 KB |
Output is correct |
23 |
Correct |
159 ms |
25932 KB |
Output is correct |
24 |
Correct |
156 ms |
25932 KB |
Output is correct |
25 |
Correct |
70 ms |
16204 KB |
Output is correct |
26 |
Correct |
65 ms |
16008 KB |
Output is correct |
27 |
Correct |
171 ms |
26004 KB |
Output is correct |
28 |
Correct |
156 ms |
26000 KB |
Output is correct |
29 |
Correct |
0 ms |
212 KB |
Output is correct |
30 |
Correct |
0 ms |
212 KB |
Output is correct |
31 |
Correct |
0 ms |
212 KB |
Output is correct |
32 |
Correct |
0 ms |
212 KB |
Output is correct |
33 |
Correct |
0 ms |
212 KB |
Output is correct |
34 |
Correct |
0 ms |
212 KB |
Output is correct |
35 |
Correct |
0 ms |
212 KB |
Output is correct |
36 |
Correct |
7 ms |
1364 KB |
Output is correct |
37 |
Correct |
156 ms |
26012 KB |
Output is correct |
38 |
Correct |
0 ms |
212 KB |
Output is correct |
39 |
Correct |
0 ms |
212 KB |
Output is correct |
40 |
Correct |
7 ms |
1324 KB |
Output is correct |
41 |
Correct |
170 ms |
25896 KB |
Output is correct |
42 |
Correct |
0 ms |
212 KB |
Output is correct |
43 |
Correct |
0 ms |
212 KB |
Output is correct |
44 |
Correct |
3 ms |
852 KB |
Output is correct |
45 |
Correct |
75 ms |
16004 KB |
Output is correct |
46 |
Correct |
0 ms |
212 KB |
Output is correct |
47 |
Correct |
0 ms |
212 KB |
Output is correct |
48 |
Correct |
0 ms |
212 KB |
Output is correct |
49 |
Correct |
42 ms |
6668 KB |
Output is correct |
50 |
Correct |
168 ms |
26008 KB |
Output is correct |
51 |
Correct |
167 ms |
25952 KB |
Output is correct |
52 |
Correct |
178 ms |
26108 KB |
Output is correct |
53 |
Correct |
67 ms |
16008 KB |
Output is correct |
54 |
Correct |
80 ms |
16076 KB |
Output is correct |
55 |
Correct |
168 ms |
25996 KB |
Output is correct |
56 |
Correct |
174 ms |
26004 KB |
Output is correct |
57 |
Correct |
73 ms |
16012 KB |
Output is correct |
58 |
Correct |
0 ms |
212 KB |
Output is correct |
59 |
Correct |
0 ms |
212 KB |
Output is correct |
60 |
Correct |
0 ms |
212 KB |
Output is correct |
61 |
Correct |
39 ms |
6744 KB |
Output is correct |
62 |
Correct |
156 ms |
25992 KB |
Output is correct |
63 |
Correct |
161 ms |
26020 KB |
Output is correct |
64 |
Correct |
160 ms |
25996 KB |
Output is correct |
65 |
Correct |
0 ms |
212 KB |
Output is correct |
66 |
Correct |
42 ms |
6668 KB |
Output is correct |
67 |
Correct |
169 ms |
25988 KB |
Output is correct |
68 |
Correct |
170 ms |
26060 KB |
Output is correct |
69 |
Correct |
178 ms |
25972 KB |
Output is correct |
70 |
Correct |
0 ms |
212 KB |
Output is correct |
71 |
Correct |
0 ms |
212 KB |
Output is correct |
72 |
Correct |
1 ms |
212 KB |
Output is correct |
73 |
Correct |
44 ms |
6740 KB |
Output is correct |
74 |
Correct |
169 ms |
25932 KB |
Output is correct |
75 |
Correct |
169 ms |
25904 KB |
Output is correct |
76 |
Correct |
168 ms |
25988 KB |
Output is correct |
77 |
Correct |
155 ms |
26008 KB |
Output is correct |
78 |
Correct |
0 ms |
212 KB |
Output is correct |
79 |
Correct |
0 ms |
212 KB |
Output is correct |
80 |
Correct |
3 ms |
852 KB |
Output is correct |
81 |
Correct |
68 ms |
16016 KB |
Output is correct |
82 |
Correct |
0 ms |
212 KB |
Output is correct |
83 |
Correct |
0 ms |
212 KB |
Output is correct |
84 |
Correct |
1 ms |
212 KB |
Output is correct |
85 |
Correct |
42 ms |
6672 KB |
Output is correct |
86 |
Correct |
69 ms |
16016 KB |
Output is correct |
87 |
Correct |
65 ms |
16020 KB |
Output is correct |
88 |
Correct |
67 ms |
16008 KB |
Output is correct |
89 |
Correct |
65 ms |
16008 KB |
Output is correct |
90 |
Correct |
0 ms |
212 KB |
Output is correct |
91 |
Correct |
0 ms |
212 KB |
Output is correct |
92 |
Correct |
3 ms |
852 KB |
Output is correct |
93 |
Correct |
67 ms |
16012 KB |
Output is correct |
94 |
Correct |
0 ms |
212 KB |
Output is correct |
95 |
Correct |
0 ms |
212 KB |
Output is correct |
96 |
Correct |
0 ms |
212 KB |
Output is correct |
97 |
Correct |
19 ms |
4668 KB |
Output is correct |
98 |
Correct |
70 ms |
18048 KB |
Output is correct |
99 |
Correct |
79 ms |
18040 KB |
Output is correct |
100 |
Correct |
79 ms |
18056 KB |
Output is correct |
101 |
Incorrect |
157 ms |
27852 KB |
Answer gives possible 1 while actual possible 0 |
102 |
Halted |
0 ms |
0 KB |
- |