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>
using namespace std;
int construct(vector<vector<int>> p) {
int n = p.size();
for (int i = 0; i < n; i++)
for (int j = 0; j < n; j++)
if (p[i][j] == 3)
return 0;
int C[n];
iota(C, C + n, 0);
for (int i = 0; i < n; i++)
for (int j = 0; j < n; j++)
{
if (p[i][j] == 1 && C[i] != C[j])
{
int x = C[i];
for (int a = 0; a < n; a++)
if (C[a] == x)
C[a] = C[j];
}
}
vector<vector<int>>ans(n, vector<int>(n, 0));
for (int i = 0; i < n; i++)
if (C[i] != i)
ans[i][C[i]] = ans[C[i]][i] = 1;
int X[n];
for (int i = 0; i < n; i++)
if (C[i] == i)
X[i] = i;
else
X[i] = -1;
for (int i = 0; i < n; i++)
for (int j = 0; j < n; j++)
{
if (p[i][j] == 2 && X[i] != X[j] && X[i] != -1 && X[j] != -1)
{
int x = X[i];
for (int a = 0; a < n; a++)
if (X[a] == x)
X[a] = X[j];
}
}
for (int i = 0; i < n; i++)
{
vector<int>x;
for (int j = 0; j < n; j++)
if (X[j] == i)
x.push_back(j);
if (x.size() > 1)
{
if (x.size() == 2)
return 0;
int a = x.back();
for (int b : x)
{
ans[a][b] = ans[b][a] = 1;
a = b;
}
}
}
for (int i = 0; i < n; i++)
{
for (int j = 0; j < n; j++)
{
if (p[i][j] == 0 && X[C[i]] == X[C[j]])
return 0;
if (p[i][j] == 1 && C[i] != C[j])
return 0;
if (p[i][j] == 2 && (X[C[i]] != X[C[j]] || C[i] == C[j]))
return 0;
}
}
build(ans);
return 1;
}
# | 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... |