이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
#include "supertrees.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;
vector<vector<int>> answer(N, vector<int>(N, 0));
vector<int> line(N, 0), compo(N, 0);
for (int i=0;i<N;i++) line[i] = compo[i] = i;
function<int(int, vector<int>&)> get; get = [&](int n, vector<int> &par){ return par[n] == n ? n : par[n] = get(par[n], par); };
for (int i=0;i<N;i++) for (int j=i+1;j<N;j++){
if (p[i][j]) compo[get(j, compo)] = get(i, compo);
if (p[i][j] == 1) line[get(j, line)] = get(i, line);
}
for (int i=0;i<N;i++) if (get(i, compo) == i){
vector <int> cycle;
for (int j=0;j<N;j++) if (get(j, compo) == i && get(j, line) == j) cycle.push_back(j);
int n = cycle.size();
if (n == 1) continue;
if (n == 2) return 0;
for (int j=0;j<n;j++) answer[cycle[j]][cycle[(j+1)%n]] = answer[cycle[(j+1)%n]][cycle[j]] = 1;
}
for (int i=0;i<N;i++) if (get(i, line) != i) answer[get(i, line)][i] = answer[i][get(i, line)] = 1;
for (int i=0;i<N;i++) for (int j=i+1;j<N;j++){
if (get(i, line) == get(j, line)){
if (p[i][j] != 1) return 0;
}
else if (get(i, compo) == get(j, compo)){
if (p[i][j] != 2) return 0;
}else{
if (p[i][j] != 0) return 0;
}
}
build(answer);
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... |