This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include "supertrees.h"
#include <bits/stdc++.h>
#define pb push_back
#define f first
#define sc second
using namespace std;
typedef long long int ll;
typedef string str;
vector<vector<int>> v;
vector <vector<int>> dsu1;
vector <int> dsu2;
void unite(int a, int b){
if(dsu2[a] == dsu2[b]) return;
int x = dsu2[a], y = dsu2[b];
if(dsu1[x].size() < dsu1.size()){
while(!dsu1[x].empty()){
int ss = dsu1[x].back();
dsu1[x].pop_back();
dsu2[ss] = y;
dsu1[y].pb(ss);
}
}
else{
while(!dsu1[y].empty()){
int ss = dsu1[y].back();
dsu1[y].pop_back();
dsu2[ss] = x;
dsu1[x].pb(ss);
}
}
}
int construct(vector<vector<int>> p){
v.clear();
dsu1.clear();
dsu2.clear();
int n = p.size();
v = vector<vector<int>>(n, vector<int>(n, 0));
dsu1 = vector<vector<int>>(n);
dsu2 = vector<int>(n);
for(int i = 0; i < n ; i++) dsu1[i].pb(i);
for(int i = 0; i < n; i++) dsu2[i] = i;
vector <int> zot(3, 0);
for(int i = 0; i < n; i++) for(int j = 0; j < n; j++) if(i != j) zot[p[i][j]]++;
for(int i = 0; i < n; i++) for(int j = 0; j < n; j++) if(p[i][j] != 0) unite(i, j);
bool bl = 1;
for(auto sth: dsu1){
if(sth.size() < 2) continue;
for(int i = 0; i < sth.size(); i++) for(int j = 0; j < sth.size(); j++){
if(i == j) continue;
if(p[sth[i]][sth[j]] == 0){
bl = 0;
break;
}
}
}
if(!bl) return 0;
for(auto sth: dsu1){
if(sth.size() <= 2) continue;
vector <int> two, one;
for(int x: sth){
int o = 0,tw = 0;
for(int y: p[x]){
if(y == 1) o++;
else tw++;
}
if(o == 1) two.pb(x);
else one.pb(x);
}
for(int i = 0; i < one.size() - 1; i++){
int x = one[i], y = one[i+1];
v[x][y] = 1;
v[y][x] = 1;
}
if(two.size() == 0) continue;
if(two.size() == 1){
bl = 0;
break;
}
for(int i = 0; i < two.size() - 1; i++){
int x = two[i], y = two[i+1];
v[x][y] = 1;
v[y][x] = 1;
}
if(one.size() == 0){
int x = two[0], y = two.back();
v[x][y] = 1;
v[y][x] = 1;
}
else{
int x = two[0], y = two.back(), z = one[0];
v[x][z] = 1;
v[z][x] = 1;
v[y][z] = 1;
v[z][y] = 1;
}
}
if(!bl) return 0;
build(v);
return 1;
}
Compilation message (stderr)
supertrees.cpp: In function 'int construct(std::vector<std::vector<int> >)':
supertrees.cpp:48:26: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
48 | for(int i = 0; i < sth.size(); i++) for(int j = 0; j < sth.size(); j++){
| ~~^~~~~~~~~~~~
supertrees.cpp:48:62: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
48 | for(int i = 0; i < sth.size(); i++) for(int j = 0; j < sth.size(); j++){
| ~~^~~~~~~~~~~~
supertrees.cpp:69:26: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
69 | for(int i = 0; i < one.size() - 1; i++){
| ~~^~~~~~~~~~~~~~~~
supertrees.cpp:79:26: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
79 | for(int i = 0; i < two.size() - 1; i++){
| ~~^~~~~~~~~~~~~~~~
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |