#include "supertrees.h"
#include <vector>
#include<bits/stdc++.h>
using namespace std;
const int N = 1e3+7;
int p[N];
int sz[N];
int pa(int u){
p[u]=(p[u] == u ? u : pa(p[u]));
return p[u];
}
bool sm(int u, int v){
return pa(u) == pa(v);
}
void un(int u, int v){
if(sm(u, v)) return;
u = pa(u);
v = pa(v);
if(sz[v] > sz[u]) swap(u, v);
sz[u]+=sz[v];
p[v]=u;
}
int construct(vector<vector<int>> v) {
int n = v.size();
for(int i = 0; i <= n; i++){
p[i]=i;
sz[i]=1;
}
for(int i = 0; i < n; i++){
bool ch = 0;
if(pa(i)==i) ch = 1;
for(int j = i+1; j < n; j++){
if(ch){
if(v[i][j] == 0) continue;
if(pa(j) == j){
un(i, j);
}
else return 0;
}
else{
if(pa(j) != pa(i)) return 0;
}
}
}
map<int, int> m;
for(int i = 0; i < n; i++){
vector<int> a(4, 0);
for(int j = 0; j < n; j++){
if(i == j) continue;
a[v[i][j]]++;
}
if(a[1] > 0) m[i]=1;
else if(a[2] > 0) m[i]=2;
else if(a[3] > 0) m[i]=3;
else m[i]=0;
}
vector<vector<int>> ans(n, vector<int> (n, 0));
for(int i = 0; i < n; i++){
if(pa(i) != i) continue;
vector<vector<int>> a(4);
vector<int> w;
for(int j = 0; j < n; j++){
if(pa(j) == i){
w.push_back(j);
a[m[j]].push_back(j);
}
}
//aquí ya lo tengo que cambiar si quiero hacer para 3
for(int j = 0; j < w.size(); j++){
for(int k = j+1; k < w.size(); k++){
int r = m[w[j]], s = m[w[k]];
// if(max(r, s) == 2){
// if(v[j][k] != 2) return 0;
// }
// else{
if(max(r, s) == 1) if(v[w[j]][w[k]] != 1) return 0;
// }
}
}
for(int j = 1; j < (int) a[1].size(); j++){
ans[a[1][j]][a[1][j-1]] = 1;
ans[a[1][j-1]][a[1][j]] = 1;
}
if(a[2].size() == 0) continue;
for(int j = 1; j < (int) a[2].size(); j++){
ans[a[2][j]][a[2][j-1]] = 1;
ans[a[2][j-1]][a[2][j]] = 1;
}
if(a[1].size() == 1){
ans[a[2][0]][a[2].back()] = 1;
ans[a[2].back()][a[2][0]] = 1;
continue;
}
ans[a[2][0]][a[1].back()] = 1;
ans[a[1].back()][a[2][0]] = 1;
ans[a[2].back()][a[1].back()] = 1;
ans[a[1].back()][a[2].back()] = 1;
}
build(ans);
return 1;
}
Compilation message
supertrees.cpp: In function 'int construct(std::vector<std::vector<int> >)':
supertrees.cpp:80:26: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
80 | for(int j = 0; j < w.size(); j++){
| ~~^~~~~~~~~~
supertrees.cpp:81:32: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
81 | for(int k = j+1; k < w.size(); k++){
| ~~^~~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
348 KB |
Output is correct |
2 |
Correct |
1 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
0 ms |
348 KB |
Output is correct |
6 |
Correct |
10 ms |
1284 KB |
Output is correct |
7 |
Correct |
137 ms |
22100 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
348 KB |
Output is correct |
2 |
Correct |
1 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
0 ms |
348 KB |
Output is correct |
6 |
Correct |
10 ms |
1284 KB |
Output is correct |
7 |
Correct |
137 ms |
22100 KB |
Output is correct |
8 |
Correct |
1 ms |
344 KB |
Output is correct |
9 |
Correct |
1 ms |
348 KB |
Output is correct |
10 |
Correct |
0 ms |
348 KB |
Output is correct |
11 |
Correct |
1 ms |
348 KB |
Output is correct |
12 |
Correct |
6 ms |
1116 KB |
Output is correct |
13 |
Correct |
129 ms |
22040 KB |
Output is correct |
14 |
Correct |
0 ms |
344 KB |
Output is correct |
15 |
Correct |
0 ms |
348 KB |
Output is correct |
16 |
Correct |
3 ms |
604 KB |
Output is correct |
17 |
Correct |
53 ms |
8220 KB |
Output is correct |
18 |
Correct |
0 ms |
348 KB |
Output is correct |
19 |
Correct |
0 ms |
348 KB |
Output is correct |
20 |
Incorrect |
24 ms |
2396 KB |
Answer gives possible 0 while actual possible 1 |
21 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
1 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Runtime error |
1 ms |
348 KB |
Execution killed with signal 11 |
5 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Runtime error |
1 ms |
348 KB |
Execution killed with signal 11 |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
348 KB |
Output is correct |
2 |
Correct |
1 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
0 ms |
348 KB |
Output is correct |
6 |
Correct |
10 ms |
1284 KB |
Output is correct |
7 |
Correct |
137 ms |
22100 KB |
Output is correct |
8 |
Correct |
1 ms |
344 KB |
Output is correct |
9 |
Correct |
1 ms |
348 KB |
Output is correct |
10 |
Correct |
0 ms |
348 KB |
Output is correct |
11 |
Correct |
1 ms |
348 KB |
Output is correct |
12 |
Correct |
6 ms |
1116 KB |
Output is correct |
13 |
Correct |
129 ms |
22040 KB |
Output is correct |
14 |
Correct |
0 ms |
344 KB |
Output is correct |
15 |
Correct |
0 ms |
348 KB |
Output is correct |
16 |
Correct |
3 ms |
604 KB |
Output is correct |
17 |
Correct |
53 ms |
8220 KB |
Output is correct |
18 |
Correct |
0 ms |
348 KB |
Output is correct |
19 |
Correct |
0 ms |
348 KB |
Output is correct |
20 |
Incorrect |
24 ms |
2396 KB |
Answer gives possible 0 while actual possible 1 |
21 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
348 KB |
Output is correct |
2 |
Correct |
1 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
0 ms |
348 KB |
Output is correct |
6 |
Correct |
10 ms |
1284 KB |
Output is correct |
7 |
Correct |
137 ms |
22100 KB |
Output is correct |
8 |
Correct |
1 ms |
344 KB |
Output is correct |
9 |
Correct |
1 ms |
348 KB |
Output is correct |
10 |
Correct |
0 ms |
348 KB |
Output is correct |
11 |
Correct |
1 ms |
348 KB |
Output is correct |
12 |
Correct |
6 ms |
1116 KB |
Output is correct |
13 |
Correct |
129 ms |
22040 KB |
Output is correct |
14 |
Correct |
0 ms |
344 KB |
Output is correct |
15 |
Correct |
0 ms |
348 KB |
Output is correct |
16 |
Correct |
3 ms |
604 KB |
Output is correct |
17 |
Correct |
53 ms |
8220 KB |
Output is correct |
18 |
Correct |
0 ms |
348 KB |
Output is correct |
19 |
Correct |
0 ms |
348 KB |
Output is correct |
20 |
Incorrect |
24 ms |
2396 KB |
Answer gives possible 0 while actual possible 1 |
21 |
Halted |
0 ms |
0 KB |
- |