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>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> pll;
typedef pair<int, int> pii;
#include "supertrees.h"
#define con(a, b) answer[a][b] = 1;answer[b][a] = 1;
int construct(vector<vector<int>> p) {
int n = p.size();
vector<vector<int>> answer(n, vector<int>(n, 0));
vector<vector<int>> groups;
vector<bool> assigned(n, 0);
for (int i = 0; i < n; i++)
{
if (assigned[i]) continue;
vector<int> cgroup;
vector<bool> ingroup(n, 0);
for (int j = 0; j < n; j++)
{
if (p[i][j] == 0) continue;
if (assigned[j]) {
return 0;
}
ingroup[j] = 1;
cgroup.push_back(j);
assigned[j] = 1;
}
for (int j : cgroup) {
for (int k = 0; k < n; k++)
{
if (ingroup[k] != (bool)p[j][k]) {
return 0;
}
}
}
groups.push_back(cgroup);
}
for (auto &g : groups) {
vector<vector<int>> branches;
vector<bool> br(n, 0);
for (int i : g) {
if (br[i]) continue;
vector<int> branch;
for (int j : g) {
if (p[i][j] == 2) continue;
if (br[j]) return 0;
branch.push_back(j);
br[j] = 1;
}
branches.push_back(branch);
}
for (int i = 0; i < branches.size(); i++)
{
if (branches.size() != 1) {
con(branches[i][0], branches[(i+1)%branches.size()][0])
}
for (int j = 0; j < branches[i].size()-1; j++)
{
con(branches[i][j], branches[i][j+1])
}
}
}
build(answer);
return 1;
}
Compilation message (stderr)
supertrees.cpp: In function 'int construct(std::vector<std::vector<int> >)':
supertrees.cpp:57:27: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::vector<int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
57 | for (int i = 0; i < branches.size(); i++)
| ~~^~~~~~~~~~~~~~~~~
supertrees.cpp:62:31: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
62 | for (int j = 0; j < branches[i].size()-1; 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... |