이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include "supertrees.h"
#include <bits/stdc++.h>
using namespace std;
int n, flag[1008], f[1008];
bool kt[1008];
vector<int>ds, cir, tour, vt[1008];
vector<vector<int> >a;
int construct(std::vector<std::vector<int>> p) {
n = p.size();
a.resize(n);
for (int i = 0; i < n; i++){
for (int j = i + 1; j < n; j++)
assert(p[i][j] < 3);
a[i].resize(n, 0);
}
fill(kt, kt + n, false);
for (int i = 0; i < n; i++)
if (!kt[i]){
ds.push_back(i);
vt[i].push_back(i);
kt[i] = true;
flag[i] = i;
for (int j = i + 1; j < n; j++)
if (!kt[j] && p[i][j] == 1){
vt[i].push_back(j);
kt[j] = true;
flag[j] = i;
}
for (int u : vt[i])
for (int v : vt[i])
if (p[u][v] != 1)
return 0;
for (int pos = 1; pos < (int)vt[i].size(); pos++)
a[vt[i][pos]][vt[i][pos - 1]] = a[vt[i][pos - 1]][vt[i][pos]] = 1;
}
for (int i = 0; i < n; i++)
for (int j = i + 1; j < n; j++)
if (p[i][j] == 1 && flag[i] != flag[j])
return 0;
fill(kt, kt + n, false);
for (int i : ds)
if (!kt[i]){
cir.clear();
tour.clear();
kt[i] = true;
f[i] = i;
tour.push_back(i);
for (int tmp : vt[i])
cir.push_back(tmp);
for (int j : ds)
if (p[i][j] == 2){
if (kt[j])
return 0;
tour.push_back(j);
kt[j] = true;
f[j] = i;
for (int u : vt[j])
for (int v : cir)
if (p[u][v] != 2)
return 0;
for (int u : vt[j])
cir.push_back(u);
}
if (tour.size() <= 2){
if (tour.size() == 2)
return 0;
else
continue;
}
tour.push_back(tour[0]);
for (int pos = 1; pos < (int)tour.size(); pos++)
a[tour[pos]][tour[pos - 1]] = a[tour[pos - 1]][tour[pos]] = 1;
}
for (int i = 0; i < n; i++)
for (int j = 0; j < n; j++)
if (p[i][j] == 2 && f[flag[i]] != f[flag[j]])
return 0;
build(a);
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... |