이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include "supertrees.h"
#include<bits/stdc++.h>
using namespace std;
#define vec vector
int construct(vec<vec<int>> p) {
int n = p.size();
vec<vec<int>> edges(n, vec<int>(n, 0));
vec<int> comp(n, -1);
for(int i = 0; i<n; i++) {
if(comp[i] != -1) continue;
for(int j = i; j<n; j++) {
if(p[i][j] > 0) comp[j] = i;
}
}
for(int i = 0; i<n; i++) {
for(int j = 0; j<n; j++) {
if(((p[i][j] > 0) != (comp[i] == comp[j])) || p[i][j] == 3) {
return 0;
}
}
}
vec<set<int>> comp_cycle(n);
vec<int> cycle_chains(n, -1);
for(int i = 0; i<n; i++) {
for(int j = 0; j<n; j++) {
if(p[i][j] == 1) {
cycle_chains[i] = j;
comp_cycle[comp[i]].insert(j);
break;
}
}
}
for(int i = 0; i<n; i++) {
for(int j = 0; j<n; j++) {
if(comp[i] != comp[j]) continue;
if((cycle_chains[i] == cycle_chains[j]) != (p[i][j] == 1)) {
return 0;
}
}
}
for(int i = 0; i<n; i++) {
if(comp[i] != i) continue;
// assert(comp_cycle[i].size() > 0);
if(comp_cycle[i].size() == 0) return 0;
if(comp_cycle[i].size() == 2) return 0;
if(comp_cycle[i].size() == 1) continue;
int prev = *comp_cycle[i].end();
for(int u : comp_cycle[i]) {
edges[prev][u] = 1;
edges[u][prev] = 1;
prev = u;
}
}
for(int i = 0; i<n; i++) {
for(int j = i-1; j>=0; j--) {
if(cycle_chains[i] != -1 && cycle_chains[i] == cycle_chains[j]) {
edges[i][j] = 1;
edges[j][i] = 1;
break;
}
}
}
build(edges);
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... |