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<iostream>
#include<vector>
#include<algorithm>
#include<iomanip>
using namespace std;
#define vi vector<int>
#define vvi vector<vi>
vvi L;
vi F;
int find(int a) {return (F[a] == -1 ? a : F[a] = find(F[a]));}
void uunion(int a, int b) {
a = find(a); b = find(b);
if (a == b) return;
F[a] = b;
}
int oink(vvi p) {
int n = p.size();
vvi Adj(n, vi(n, 0));
L.clear(); F.clear(); F.resize(n, -1);
for (int i = 0; i < n; i++) {
for (int j = 0; j < n; j++) {
if (p[i][j]) {
uunion(i, j);
continue;
}
//cerr << i << " " << j << " " << find(i) << " " << find(j) << endl;
if (find(i) == find(j)) return 0;
}
}
L.resize(n);
for (int i = 0; i < n; i++) {
L[find(i)].push_back(i);
}
for (auto i : L) {
if (i.size() < 2) continue;
if (i.size() == 2) return 0;
for (int j = 0; j < i.size(); j++) {
int a = i[(j+1)%i.size()];
int b = i[j];
Adj[b][a] = 1;
Adj[a][b] = 1;
}
}
build(Adj);
return 1;
}
int oinkoink(vvi p) {
int n = p.size();
vvi Adj(n, vi(n, 0));
F.clear(); F.resize(n, -1);
for (int i = 0; i < n; i++) {
for (int j = 0; j < n; j++) {
if (p[i][j]) {
if (find(i) == find(j)) continue;
Adj[i][j] = 1;
Adj[j][i] = 1;
uunion(i, j);
continue;
}
//cerr << i << " " << j << " " << find(i) << " " << find(j) << endl;
if (find(i) == find(j)) return 0;
}
}
build(Adj);
return 1;
}
int construct(std::vector<std::vector<int>> p) {
for (int i = 0; i < p.size(); i++) {
for (int j = i+1; j < p.size(); j++) {
if (p[i][j] == 1) return oinkoink(p);
if (p[i][j] == 2) return oink(p);
}
}
vvi Adj(p.size(), vi(p.size(), 0));
build(Adj);
return 1;
}
Compilation message (stderr)
supertrees.cpp: In function 'int oink(std::vector<std::vector<int> >)':
supertrees.cpp:45:27: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
45 | for (int j = 0; j < i.size(); j++) {
| ~~^~~~~~~~~~
supertrees.cpp: In function 'int construct(std::vector<std::vector<int> >)':
supertrees.cpp:78:23: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::vector<int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
78 | for (int i = 0; i < p.size(); i++) {
| ~~^~~~~~~~~~
supertrees.cpp:79:29: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::vector<int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
79 | for (int j = i+1; j < p.size(); j++) {
| ~~^~~~~~~~~~
# | 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... |