이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
#include "supertrees.h"
using namespace std;
const int mxN = 1007;
int dsu[mxN];
bool mark[mxN], done[mxN];
vector<int> cmp[mxN];
int find(int x) {
return dsu[x] < 0 ? x : dsu[x] = find(dsu[x]);
}
bool unite(int x, int y) {
x = find(x), y = find(y);
if (x == y) {
return false;
}
if (dsu[x] > dsu[y]) {
swap(x, y);
}
dsu[x] += dsu[y];
dsu[y] = x;
return true;
}
int construct(vector<vector<int>> p) {
int n = p.size();
memset(dsu, -1, sizeof(dsu));
vector<vector<int>> ans(n, vector<int>(n));
for (int i = 0; i < n; ++i) {
cmp[i].push_back(i);
}
for (int i = 0; i < n; ++i) {
for (int j = 0; j < n; ++j) {
if (p[i][j] == 2) {
int x = find(i), y = find(j);
if (x != y) {
bool ok = true;
for (auto u : cmp[x]) {
for (auto v : cmp[y]) {
ok &= (p[u][v] == 2);
}
}
if (ok) {
unite(x, y);
for (auto c : cmp[y]) {
cmp[x].push_back(c);
}
}
}
}
}
}
for (int i = 0; i < n; ++i) {
int x = find(i);
if (done[x] || cmp[x].size() <= 2) {
continue;
}
done[x] = true;
/*
cout << x << "\n";
for (auto c : cmp[x]) {
cout << c << ' ';
}
cout << "\n";
*/
for (int j = 0; j < cmp[x].size() - 1; ++j) {
mark[cmp[x][j]] = true;
ans[cmp[x][j]][cmp[x][j+1]] = ans[cmp[x][j+1]][cmp[x][j]] = 1;
}
mark[cmp[x].back()] = true;
ans[cmp[x][0]][cmp[x].back()] = ans[cmp[x].back()][cmp[x][0]] = 1;
}
memset(dsu, -1, sizeof(dsu));
for (int i = 0; i < n; ++i) {
for (int j = i + 1; j < n; ++j) {
if (i != j && p[i][j] == 1) {
//assert(!(mark[i] && mark[j]));
if (unite(i, j)) {
ans[i][j] = ans[j][i] = 1;
}
}
}
}
build(ans);
return 1;
}
컴파일 시 표준 에러 (stderr) 메시지
supertrees.cpp: In function 'int construct(std::vector<std::vector<int> >)':
supertrees.cpp:78:27: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
78 | for (int j = 0; j < cmp[x].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... |