# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
760586 | raysh07 | 슈퍼트리 잇기 (IOI20_supertrees) | C++17 | 159 ms | 27164 KiB |
이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include "supertrees.h"
#include <vector>
#include <bits/stdc++.h>
using namespace std;
const int N = 1001;
int root[N];
vector <int> adj[N];
bool vis[N];
vector <int> comp;
int find(int x){
if (root[x] == x) return x;
return root[x] = find(root[x]);
}
void unite(int x, int y){
x = find(x); y = find(y);
if (x == y) return;
root[x] = y;
}
void dfs(int u){
vis[u] = true;
comp.push_back(u);
for (auto v : adj[u]){
if (!vis[v]) dfs(v);
}
}
int construct(vector<vector<int>> p) {
int n = p.size();
vector<vector<int>> ans(n, vector<int>(n, 0));
for (int i = 0; i < n; i++) root[i] = i;
for (int i = 0; i < n; i++){
for (int j = i + 1; j < n; j++){
if (p[i][j] == 1) unite(i, j);
if (p[i][j] == 3) return 0;
}
}
for (int i = 0; i < n; i++){
for (int j = i + 1; j < n; j++){
if (find(i) == find(j) && p[i][j] == 0) return 0;
}
}
for (int i = 0; i < n; i++){
if (find(i) != i){
ans[i][find(i)] = ans[find(i)][i] = 1;
}
}
for (int i = 0; i < n; i++){
for (int j = i + 1; j < n; j++){
if (p[i][j] == 2 && find(i) == i && find(j) == j) {
adj[i].push_back(j);
adj[j].push_back(i);
}
}
}
for (int i = 0; i < n; i++){
if (vis[i] || find(i) != i) continue;
comp.clear();
dfs(i);
if (comp.size() == 2) return 0;
for (auto x : comp){
for (auto y : comp){
if (x != y && p[x][y] != 2){
return 0;
}
}
}
for (int j = 0; j < comp.size() - 1; j++){
ans[comp[j]][comp[j + 1]] = ans[comp[j + 1]][comp[j]] = 1;
}
if (comp.size() != 1)
ans[comp[0]][comp.back()] = ans[comp.back()][comp[0]] = 1;
}
build(ans);
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... |