# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
771883 | Alty | 슈퍼트리 잇기 (IOI20_supertrees) | C++17 | 1163 ms | 2097152 KiB |
이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
#include "supertrees.h"
using namespace std;
int leader[1005], ranking[1005];
int Find(int n) {
if (leader[n] != n) leader[n] = Find(leader[n]);
return leader[n];
}
void Union(int x, int y) {
x = Find(x), y = Find(y);
if (ranking[x] > ranking[y]) swap(x, y);
ranking[y] += ranking[x];
leader[x] = y;
}
vector<int> g[1005];
bool visited[1005];
vector<int> components;
void dfs(int n) {
visited[n] = 1;
components.push_back(n);
for (auto x : g[n]) {
if (visited[x]) continue;
dfs(n);
}
}
int construct(vector<vector<int>> p) {
int n = p.size();
for (int i = 0; i <= n; i++) {
leader[i] = i;
ranking[i] = 1;
}
vector<vector<int>> answer(n, vector<int>(n));
for (int i = 0; i < n; i++) {
for (int j = i + 1; j < n; j++) {
if (p[i][j] == 3) return 0;
if (p[i][j] == 1) Union(i, j);
}
}
for (int i = 0; i < n; i++) if (Find(i) != i) answer[Find(i)][i] = answer[i][Find(i)] = 1;
for (int i = 0; i < n; i++) {
for (int j = i + 1; j < n; j++) {
if (p[i][j] == 0 && Find(i) == Find(j)) return 0;
if (p[i][j] == 2 && Find(i) == i && Find(j) == j) {
g[i].push_back(j);
g[j].push_back(i);
}
}
}
for (int i = 0; i < n; i++) {
if (Find(i) != i || visited[i]) continue;
dfs(i);
if (components.size() == 2) return 0;
for (auto x : components) {
for (auto y : components) if (x != y && p[x][y] != 2) return 0;
}
for (int j = 0; j < components.size() - 1; j++) {
answer[components[j]][components[j + 1]] = answer[components[j + 1]][components[j]] = 1;
}
if (components.size() != 1) answer[components[0]][components[components.size() - 1]] = answer[components.size() - 1][components[0]] = 1;
components.clear();
}
build(answer);
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... |