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 <bits/stdc++.h>
#include "supertrees.h"
#define ll long long
using namespace std;
const int INF = 1e9;
const int MOD = 1e9 + 7;
vector<vector<int>> p, ans;
vector<int>idk, comp;
int n, rep[1002], selected, viz[1002];
void dfs1 (int nod) {
rep[nod] = selected;
viz[nod] = 1;
for (int i = 0; i < n; i++)
if (p[nod][i] == 1 && !viz[i])
dfs1(i);
}
void dfs2 (int nod) {
comp.push_back(nod);
viz[nod] = 1;
for (auto it : idk)
if (!viz[it] && p[nod][it] == 2)
dfs2(it);
}
int construct (vector<vector<int>>aux) {
p = aux;
n = p.size();
ans.resize(n);
for (int i = 0; i < n; i++)
for (int j = 0; j < n; j++)
if (p[i][j] == 3)
return 0;
for (int i = 0; i < n; i++)
ans[i].resize(n);
for (int i = 0; i < n; i++)
if (!viz[i]) {
selected = i;
idk.push_back(selected);
dfs1(i);
}
for (int i = 0; i < n; i++)
for (int j = 0; j < n; j++)
if (rep[i] == rep[j] && p[i][j] != 1)
return 0;
for (int i = 0; i < n; i++)
for (int j = 0; j < n; j++)
if (rep[i] != rep[j] && p[i][j] != p[rep[i]][rep[j]])
return 0;
for (auto it : idk) {
int aux = -1;
for (int j = 0; j < n; j++)
if (rep[j] == it) {
if (aux != -1)
ans[aux][j] = ans[j][aux] = 1;
aux = j;
}
}
memset(viz, 0, sizeof(viz));
for (auto it : idk) {
if (!viz[it]) {
comp.clear();
dfs2(it);
if (comp.size() == 1)
continue;
if (comp.size() == 2)
return 0;
for (int i = 0; i < comp.size(); i++)
for (int j = i + 1; j < comp.size(); j++)
if (p[comp[i]][comp[j]] != 2)
return 0;
for (int i = 0; i < comp.size(); i++)
ans[comp[i]][comp[(i + 1) % comp.size()]] = ans[comp[(i + 1) % comp.size()]][comp[i]] = 1;
}
}
build(ans);
return 1;
}
// int main ()
// {
// cout << construct({{1, 2, 0, 2}, {2, 1, 2, 2}, {2, 2, 1, 2}, {2, 2, 2, 1}});
// return 0;
// }
Compilation message (stderr)
supertrees.cpp: In function 'int construct(std::vector<std::vector<int> >)':
supertrees.cpp:75:25: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
75 | for (int i = 0; i < comp.size(); i++)
| ~~^~~~~~~~~~~~~
supertrees.cpp:76:31: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
76 | for (int j = i + 1; j < comp.size(); j++)
| ~~^~~~~~~~~~~~~
supertrees.cpp:79:25: 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 < comp.size(); 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... |