이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
#include "supertrees.h"
using namespace std;
const int Nmax = 1e3 + 10;
int n;
int b[Nmax][Nmax];
int p[Nmax][Nmax];
int root[3][Nmax], sz[3][Nmax];
vector <int> rt[Nmax];
int Find(int _, int u) {
return (u == root[_][u] ? u : root[_][u] = Find(_, root[_][u]));
}
void Union(int _, int u, int v) {
if ((u = Find(_, u)) == (v = Find(_, v))) return;
if (sz[_][u] < sz[_][v]) swap(u, v);
sz[_][u] += sz[_][v];
root[_][v] = u;
}
int construct(vector <vector <int> > p) {
int n = p.size();
vector <vector <int> > b(n, vector <int> (n, 0));
for (int i = 0; i < n; ++i)
for (int j = 0; j < n; ++j)
if (p[i][j] != p[j][i]) return 0;
for (int i = 0; i < n; ++i) if (p[i][i] != 1) return 0;
for (int i = 0; i < n; ++i) for (int j = 0; j < 3; ++j) root[j][i] = i, sz[j][i] = 1;
for (int i = 0; i < n; ++i)
for (int j = 0; j < n; ++j)
if (p[i][j] == 1) Union(0, i, j);
for (int i = 0; i < n; ++i)
for (int j = 0; j < n; ++j)
if (Find(0, i) == Find(0, j) && p[i][j] != 1) return 0;
for (int i = 0; i < n; ++i)
for (int j = 0; j < n; ++j) {
if (p[i][j] == 2) Union(1, Find(0, i), Find(0, j));
if (p[i][j] == 3) Union(2, Find(0, i), Find(0, j));
}
for (int i = 0; i < n; ++i)
for (int j = 0; j < n; ++j)
if (p[i][j] == 3 && Find(1, Find(0, i)) == Find(1, Find(0, j))) return 0;
for (int i = 0; i < n; ++i)
if (i != Find(0, i)) {
// cout << i << " " << Find(0, i) << "\n";
b[i][Find(0, i)] = b[Find(0, i)][i] = 1;
}
for (int i = 0; i < n; ++i) {
if (i == Find(0, i)) rt[Find(1, i)].push_back(i);
}
for (int i = 0; i < n; ++i) {
if (rt[i].size() <= 1) continue;
for (int j = 1; j < rt[i].size(); ++j) b[rt[i][j]][rt[i][j - 1]] = b[rt[i][j - 1]][rt[i][j]] = 1;
b[rt[i].front()][rt[i].back()] = b[rt[i].back()][rt[i].front()] = 1;
}
for (int i = 0; i < n; ++i) rt[i].clear();
for (int i = 0; i < n; ++i) {
if (i == Find(0, i)) rt[Find(2, i)].push_back(i);
}
for (int i = 0; i < n; ++i) {
if (rt[i].size() <= 1) continue;
if (rt[i].size() == 2) return 0;
for (int j = 1; j < rt[i].size(); ++j) b[rt[i][j]][rt[i][j - 1]] = b[rt[i][j - 1]][rt[i][j]] = 1;
b[rt[i].front()][rt[i].back()] = b[rt[i].back()][rt[i].front()] = 1;
b[rt[i][0]][rt[i][2]] = b[rt[i][2]][rt[i][0]] = 1;
}
build(b);
return 1;
}
컴파일 시 표준 에러 (stderr) 메시지
supertrees.cpp: In function 'int construct(std::vector<std::vector<int> >)':
supertrees.cpp:59:27: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
59 | for (int j = 1; j < rt[i].size(); ++j) b[rt[i][j]][rt[i][j - 1]] = b[rt[i][j - 1]][rt[i][j]] = 1;
| ~~^~~~~~~~~~~~~~
supertrees.cpp:69:27: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
69 | for (int j = 1; j < rt[i].size(); ++j) b[rt[i][j]][rt[i][j - 1]] = b[rt[i][j - 1]][rt[i][j]] = 1;
| ~~^~~~~~~~~~~~~~
# | 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... |