#include "supertrees.h"
#include <vector>
#include <iostream>
#include <algorithm>
#include <map>
#include <numeric>
#include <cstring>
using namespace std;
#define ll long long
#define ln '\n'
const int N = 1000 + 5;
int par[N], rk[N];
map<int, vector<int>> mp;
bool ok = true;
int find(int u){return ((u == par[u])? u: par[u]=find(par[u]));}
void add(int u, int v, int c){
u = find(u);
v = find(v);
// if (rk[u] == -1 && rk[v] == -1){
// rk[u] = rk[v] = c;
// } else if (rk[u] == -1 && rk[v] == c) rk[u] = c;
// else if (rk[v] == -1 && rk[u] == c) rk[v] = c;
// else ok = false;
if (u != v) par[u] = v;
}
int construct(std::vector<std::vector<int>> p) {
int n = p.size();
std::vector<std::vector<int>> answer;
for (int i = 0; i < n; i++) {
std::vector<int> row;
row.resize(n);
answer.push_back(row);
}
iota(par, par+n, 0);
memset(rk, -1, sizeof(rk));
for (int i = 0; i < n; i++){
for (int j = i+1; j < n; j++){
if (p[i][j] == 0) continue;
add(i, j, p[i][j]);
}
}
if (!ok) return 0;
for (int i = 0; i < n; i++){
for (int j = i+1; j < n; j++){
if (!p[i][j] && find(i) == find(j)) return 0;
}
}
for (int i = 0; i < n; i++){
mp[find(i)].push_back(i);
}
for (auto& [p, v]: mp){
// if (rk[p] == 1){
// for (auto& u: v){
// if (u != p) answer[u][p] = answer[p][u] = 1;
// }
// } else {
// if (v.size() < 2) return 0;
// for (int i = 1; i < v.size(); i++){
// answer[v[i]][v[i-1]] = answer[v[i-1]][v[i]] = 1;
// }
// answer[v.back()][v.front()] = answer[v.front()][v.back()] = 1;
// }
if (v.size() < 2) return 0;
for (int i = 1; i < v.size(); i++){
answer[v[i]][v[i-1]] = answer[v[i-1]][v[i]] = 1;
}
answer[v.back()][v.front()] = answer[v.front()][v.back()] = 1;
}
build(answer);
return 1;
}
Compilation message
supertrees.cpp: In function 'int construct(std::vector<std::vector<int> >)':
supertrees.cpp:83:21: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
83 | for (int i = 1; i < v.size(); i++){
| ~~^~~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
0 ms |
212 KB |
Answer gives possible 0 while actual possible 1 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
0 ms |
212 KB |
Answer gives possible 0 while actual possible 1 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
0 ms |
212 KB |
Answer gives possible 0 while actual possible 1 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
1 ms |
212 KB |
Answer gives possible 0 while actual possible 1 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
0 ms |
212 KB |
Answer gives possible 0 while actual possible 1 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
0 ms |
212 KB |
Answer gives possible 0 while actual possible 1 |
2 |
Halted |
0 ms |
0 KB |
- |