# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
655082 | benjaminkleyn | 슈퍼트리 잇기 (IOI20_supertrees) | C++17 | 191 ms | 22208 KiB |
이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
#include "supertrees.h"
using namespace std;
typedef long long ll;
int par[1000];
int find(int u)
{
if (par[u] == u)
return u;
return par[u] = find(par[u]);
}
void unite(int u, int v)
{
u = find(u), v = find(v);
par[v] = u;
}
vector<int> comp[1000];
int construct(vector<vector<int>> p) {
int n = p.size();
iota(par, par + n, 0);
for (int i = 0; i < n; i++)
for (int j = 0; j < n; j++)
{
if (p[i][j] > 0)
unite(i, j);
if (p[i][j] == 3)
return 0;
}
for (int i = 0; i < n; i++)
comp[find(i)].push_back(i);
vector<vector<int>> answer(n, vector<int>(n));
for (int k = 0; k < n; k++)
if (find(k) == k && comp[k].size() >= 2)
{
vector<set<int>> trees;
vector<int> cycle;
vector<bool> done(n);
for (int i : comp[k])
{
if (done[i]) continue;
done[i] = true;
set<int> tree;
tree.insert(i);
for (int j : comp[k])
if (p[i][j] == 1 && !done[j])
{
done[j] = true;
answer[i][j] = 1;
answer[j][i] = 1;
tree.insert(j);
}
trees.push_back(tree);
cycle.push_back(i);
}
for (set<int> tree : trees)
for (int i : tree)
{
for (int j : comp[k])
if (tree.find(j) == tree.end() && p[i][j] != 2)
return 0;
for (int j : tree)
if (p[i][j] != 1)
return 0;
}
for (int i : cycle)
for (int j : cycle)
if (i != j && p[i][j] != 2)
return 0;
if (cycle.size() == 2)
return 0;
if (cycle.size() == 1)
continue;
cycle.push_back(comp[k][0]);
for (int i = 0; i < cycle.size() - 1; i++)
{
answer[cycle[i]][cycle[i+1]] = 1;
answer[cycle[i+1]][cycle[i]] = 1;
}
}
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... |