# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
928039 | EJIC_B_KEDAX | 슈퍼트리 잇기 (IOI20_supertrees) | C++17 | 163 ms | 22356 KiB |
이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
#include "supertrees.h"
using ll = long long;
using namespace std;
const int N = 1010;
int dsu[N];
int get(int x) {
return dsu[x] == x ? x : dsu[x] = get(dsu[x]);
}
void merge(int x, int y) {
dsu[get(x)] = get(y);
}
int construct(vector<vector<int>> p) {
int n = (int)p.size();
for (int i = 0; i < n; i++) {
dsu[i] = i;
}
for (int i = 0; i < n; i++) {
for (int j = i + 1; j < n; j++) {
if (p[i][j] == 1) {
merge(i, j);
}
}
}
vector<vector<int>> b(n, vector<int>(n, 0)), group(n), group2(n);
for (int i = 0; i < n; i++) {
for (int j = i + 1; j < n; j++) {
if (p[i][j] != 1 && get(i) == get(j)) {
return 0;
}
}
group[get(i)].push_back(i);
}
vector<int> g;
for (int i = 0; i < n; i++) {
for (int j = 1; j < group[i].size(); j++) {
b[group[i][j - 1]][group[i][j]] = 1;
b[group[i][j]][group[i][j - 1]] = 1;
}
if (!group[i].empty()) {
g.push_back(i);
}
}
for (int i : g) {
for (int j : g) {
if (p[i][j] == 2 && i < j) {
merge(i, j);
}
}
}
for (int i : g) {
for (int j : g) {
if (i != j && get(i) == get(j)) {
for (int ii : group[i]) {
if (p[ii][j] != 2) {
return 0;
}
}
}
}
group2[get(i)].push_back(i);
}
for (int i = 0; i < n; i++) {
for (int j = 0; j < group2[i].size() && group2[i].size() > 1; j++) {
b[group2[i][(j - 1 + group2[i].size()) % group2[i].size()]][group2[i][j]] = 1;
b[group2[i][j]][group2[i][(j - 1 + group2[i].size()) % group2[i].size()]] = 1;
}
}
for (int i = 0; i < n; i++) {
for (int j = i + 1; j < n; j++) {
if (p[i][j] == 3) {
return 0;
}
}
}
build(b);
return 1;
}
컴파일 시 표준 에러 (stderr) 메시지
# | 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... |