이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <iostream>
#include <vector>
#include "supertrees.h"
using namespace std;
vector<int> v[1005], vv[1005];
int p[1005];
vector<vector<int>> res;
int Find(int x) {
if (x == p[x]) return x;
return p[x] = Find(p[x]);
}
void Merge(int x, int y, int fl) {
x = Find(x);
y = Find(y);
if (x == y) return;
if (v[x].size() < v[y].size()) {
swap(x, y);
}
for (int w : v[y]) v[x].push_back(w);
v[y].clear();
if (fl == 0) res[x][y] = res[y][x] = 1;
p[y] = x;
if (fl == 1) {
for (int w : vv[y]) vv[x].push_back(w);
}
}
void build(vector<vector<int>> b);
int construct(vector<vector<int>> a) {
int n = a.size();
res = vector<vector<int>>(n, vector<int>(n, 0));
for (int i = 0; i < n; i++) {
p[i] = i;
v[i].clear(); vv[i].clear();
v[i].push_back(i);
}
for (int i = 0; i < n; i++) {
for (int j = 0; j < n; j++) {
if (a[i][j] == 1) {
Merge(i, j, 0);
}
}
}
for (int i = 0; i < n; i++) {
if (Find(i) == i) {
for (int w : v[i]) {
for (int ww : v[i]) {
if (a[w][ww] != 1) return 0;
}
}
vv[i].push_back(i);
}
}
for (int i = 0; i < n; i++) {
for (int j = 0; j < n; j++) {
if (a[i][j] == 2) {
Merge(i, j, 1);
}
}
}
for (int i = 0; i < n; i++) {
if (Find(i) == i) {
for (int j = 0; j < vv[i].size() - 1; j++) {
res[vv[i][j]][vv[i][j + 1]] = res[vv[i][j + 1]][vv[i][j]] = 1;
}
if (vv[i].size() != 1) res[vv[i][0]][vv[i].back()] = res[vv[i].back()][vv[i][0]] = 1;
if (vv[i].size() == 2) return 0;
}
}
for (int i = 0; i < n; i++) {
for (int j = 0; j < n; j++) {
if (a[i][j] && Find(i) != Find(j)) return 0;
if (a[i][j] == 0 && Find(i) == Find(j)) return 0;
}
}
build(res);
return 1;
}
컴파일 시 표준 에러 (stderr) 메시지
supertrees.cpp: In function 'int construct(std::vector<std::vector<int> >)':
supertrees.cpp:62:31: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
62 | for (int j = 0; j < vv[i].size() - 1; j++) {
| ~~^~~~~~~~~~~~~~~~~~
# | 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... |