#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){
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 : ";
for(auto j :grupo2){
g.pb(j);
if(debug)cout << j << " " ;
}
if(debug)cout << endl;
for(auto j : g){
//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 ; i < allNodes.size() ; i ++){
for(int x = 0 ; x < n ; x ++){
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:113:21: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
113 | for(int j = 1 ; j < g.size() ; j ++){
| ~~^~~~~~~~~~
supertrees.cpp:124:21: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
124 | for(int j = 0 ; i < allNodes.size() ; i ++){
| ~~^~~~~~~~~~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
1 ms |
212 KB |
Output is correct |
3 |
Correct |
1 ms |
212 KB |
Output is correct |
4 |
Correct |
0 ms |
212 KB |
Output is correct |
5 |
Correct |
1 ms |
212 KB |
Output is correct |
6 |
Correct |
7 ms |
1436 KB |
Output is correct |
7 |
Correct |
156 ms |
27924 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
1 ms |
212 KB |
Output is correct |
3 |
Correct |
1 ms |
212 KB |
Output is correct |
4 |
Correct |
0 ms |
212 KB |
Output is correct |
5 |
Correct |
1 ms |
212 KB |
Output is correct |
6 |
Correct |
7 ms |
1436 KB |
Output is correct |
7 |
Correct |
156 ms |
27924 KB |
Output is correct |
8 |
Correct |
1 ms |
212 KB |
Output is correct |
9 |
Correct |
1 ms |
304 KB |
Output is correct |
10 |
Correct |
0 ms |
212 KB |
Output is correct |
11 |
Correct |
1 ms |
308 KB |
Output is correct |
12 |
Correct |
7 ms |
1364 KB |
Output is correct |
13 |
Correct |
157 ms |
27880 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 |
980 KB |
Output is correct |
17 |
Correct |
72 ms |
18044 KB |
Output is correct |
18 |
Correct |
1 ms |
212 KB |
Output is correct |
19 |
Correct |
1 ms |
260 KB |
Output is correct |
20 |
Correct |
38 ms |
7244 KB |
Output is correct |
21 |
Correct |
154 ms |
27892 KB |
Output is correct |
22 |
Correct |
161 ms |
27908 KB |
Output is correct |
23 |
Correct |
161 ms |
27896 KB |
Output is correct |
24 |
Correct |
155 ms |
27852 KB |
Output is correct |
25 |
Correct |
70 ms |
18040 KB |
Output is correct |
26 |
Correct |
80 ms |
18052 KB |
Output is correct |
27 |
Correct |
162 ms |
27884 KB |
Output is correct |
28 |
Correct |
186 ms |
27852 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
1 ms |
212 KB |
Output is correct |
3 |
Correct |
1 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 |
1 ms |
212 KB |
Output is correct |
8 |
Correct |
8 ms |
1336 KB |
Output is correct |
9 |
Correct |
183 ms |
28000 KB |
Output is correct |
10 |
Correct |
1 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 |
170 ms |
27880 KB |
Output is correct |
14 |
Incorrect |
0 ms |
212 KB |
Answer gives possible 1 while actual possible 0 |
15 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
1 ms |
304 KB |
Output is correct |
3 |
Correct |
0 ms |
300 KB |
Output is correct |
4 |
Correct |
39 ms |
7172 KB |
Output is correct |
5 |
Correct |
154 ms |
27912 KB |
Output is correct |
6 |
Correct |
167 ms |
27860 KB |
Output is correct |
7 |
Correct |
196 ms |
27924 KB |
Output is correct |
8 |
Correct |
1 ms |
304 KB |
Output is correct |
9 |
Correct |
52 ms |
7160 KB |
Output is correct |
10 |
Correct |
165 ms |
27944 KB |
Output is correct |
11 |
Correct |
175 ms |
27900 KB |
Output is correct |
12 |
Correct |
166 ms |
27908 KB |
Output is correct |
13 |
Correct |
1 ms |
212 KB |
Output is correct |
14 |
Correct |
1 ms |
300 KB |
Output is correct |
15 |
Correct |
1 ms |
212 KB |
Output is correct |
16 |
Incorrect |
18 ms |
4728 KB |
Answer gives possible 0 while actual possible 1 |
17 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
1 ms |
212 KB |
Output is correct |
3 |
Correct |
1 ms |
212 KB |
Output is correct |
4 |
Correct |
0 ms |
212 KB |
Output is correct |
5 |
Correct |
1 ms |
212 KB |
Output is correct |
6 |
Correct |
7 ms |
1436 KB |
Output is correct |
7 |
Correct |
156 ms |
27924 KB |
Output is correct |
8 |
Correct |
1 ms |
212 KB |
Output is correct |
9 |
Correct |
1 ms |
304 KB |
Output is correct |
10 |
Correct |
0 ms |
212 KB |
Output is correct |
11 |
Correct |
1 ms |
308 KB |
Output is correct |
12 |
Correct |
7 ms |
1364 KB |
Output is correct |
13 |
Correct |
157 ms |
27880 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 |
980 KB |
Output is correct |
17 |
Correct |
72 ms |
18044 KB |
Output is correct |
18 |
Correct |
1 ms |
212 KB |
Output is correct |
19 |
Correct |
1 ms |
260 KB |
Output is correct |
20 |
Correct |
38 ms |
7244 KB |
Output is correct |
21 |
Correct |
154 ms |
27892 KB |
Output is correct |
22 |
Correct |
161 ms |
27908 KB |
Output is correct |
23 |
Correct |
161 ms |
27896 KB |
Output is correct |
24 |
Correct |
155 ms |
27852 KB |
Output is correct |
25 |
Correct |
70 ms |
18040 KB |
Output is correct |
26 |
Correct |
80 ms |
18052 KB |
Output is correct |
27 |
Correct |
162 ms |
27884 KB |
Output is correct |
28 |
Correct |
186 ms |
27852 KB |
Output is correct |
29 |
Correct |
1 ms |
212 KB |
Output is correct |
30 |
Correct |
1 ms |
212 KB |
Output is correct |
31 |
Correct |
1 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 |
1 ms |
212 KB |
Output is correct |
36 |
Correct |
8 ms |
1336 KB |
Output is correct |
37 |
Correct |
183 ms |
28000 KB |
Output is correct |
38 |
Correct |
1 ms |
212 KB |
Output is correct |
39 |
Correct |
0 ms |
212 KB |
Output is correct |
40 |
Correct |
7 ms |
1364 KB |
Output is correct |
41 |
Correct |
170 ms |
27880 KB |
Output is correct |
42 |
Incorrect |
0 ms |
212 KB |
Answer gives possible 1 while actual possible 0 |
43 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
1 ms |
212 KB |
Output is correct |
3 |
Correct |
1 ms |
212 KB |
Output is correct |
4 |
Correct |
0 ms |
212 KB |
Output is correct |
5 |
Correct |
1 ms |
212 KB |
Output is correct |
6 |
Correct |
7 ms |
1436 KB |
Output is correct |
7 |
Correct |
156 ms |
27924 KB |
Output is correct |
8 |
Correct |
1 ms |
212 KB |
Output is correct |
9 |
Correct |
1 ms |
304 KB |
Output is correct |
10 |
Correct |
0 ms |
212 KB |
Output is correct |
11 |
Correct |
1 ms |
308 KB |
Output is correct |
12 |
Correct |
7 ms |
1364 KB |
Output is correct |
13 |
Correct |
157 ms |
27880 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 |
980 KB |
Output is correct |
17 |
Correct |
72 ms |
18044 KB |
Output is correct |
18 |
Correct |
1 ms |
212 KB |
Output is correct |
19 |
Correct |
1 ms |
260 KB |
Output is correct |
20 |
Correct |
38 ms |
7244 KB |
Output is correct |
21 |
Correct |
154 ms |
27892 KB |
Output is correct |
22 |
Correct |
161 ms |
27908 KB |
Output is correct |
23 |
Correct |
161 ms |
27896 KB |
Output is correct |
24 |
Correct |
155 ms |
27852 KB |
Output is correct |
25 |
Correct |
70 ms |
18040 KB |
Output is correct |
26 |
Correct |
80 ms |
18052 KB |
Output is correct |
27 |
Correct |
162 ms |
27884 KB |
Output is correct |
28 |
Correct |
186 ms |
27852 KB |
Output is correct |
29 |
Correct |
1 ms |
212 KB |
Output is correct |
30 |
Correct |
1 ms |
212 KB |
Output is correct |
31 |
Correct |
1 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 |
1 ms |
212 KB |
Output is correct |
36 |
Correct |
8 ms |
1336 KB |
Output is correct |
37 |
Correct |
183 ms |
28000 KB |
Output is correct |
38 |
Correct |
1 ms |
212 KB |
Output is correct |
39 |
Correct |
0 ms |
212 KB |
Output is correct |
40 |
Correct |
7 ms |
1364 KB |
Output is correct |
41 |
Correct |
170 ms |
27880 KB |
Output is correct |
42 |
Incorrect |
0 ms |
212 KB |
Answer gives possible 1 while actual possible 0 |
43 |
Halted |
0 ms |
0 KB |
- |