이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
#include "supertrees.h"
using namespace std;
void build(vector<vector<int>> b);
struct DSU {
vector<int> link, siz;
DSU (int n) : link(n), siz(n, 1) {
iota(link.begin(), link.end(), 0ll);
}
int get(int x) {
if (link[x] == x) {
return x;
}
return link[x] = get(link[x]);
}
bool unite(int a, int b) {
a = get(a), b = get(b);
if (a == b) {
return false;
}
if (siz[a] < siz[b]) {
swap(a, b);
}
link[b] = a;
siz[a] += siz[b];
return true;
}
bool same(int a, int b) {
return (get(a) == get(b));
}
};
int construct(vector<vector<int>> p) {
vector<vector<int>> b(p.size(), vector<int>(p.size()));
DSU ds(p.size());
bool one = true, two = true;
for (int i = 0; i < p.size(); i++) {
for (int j = i + 1; j < p.size(); j++) {
if (p[i][j] != 0 && p[i][j] != 2) {
two = false;
}
if (p[i][j] != 0 && p[i][j] != 1) {
one = false;
}
}
}
if (one) {
for (int i = 0; i < p.size(); i++) {
for (int j = i + 1; j < p.size(); j++) {
if (p[i][j] != 0) {
ds.unite(i, j);
}
}
}
for (int i = 0; i < p.size(); i++) {
for (int j = i + 1; j < p.size(); j++) {
if (p[i][j] == 0 && ds.same(i, j)) {
return 0;
} else if (p[i][j] == 1 && !ds.same(i, j)) {
return 0;
}
}
}
vector<vector<int>> conncomps(p.size());
for (int i = 0; i < p.size(); i++) {
conncomps[ds.get(i)].push_back(i);
}
for (int i = 0; i < conncomps.size(); i++) {
for (int j = 0; j < (int) conncomps[i].size() - 1; j++) {
b[conncomps[i][j]][conncomps[i][j + 1]] = 1;
b[conncomps[i][j + 1]][conncomps[i][j]] = 1;
}
}
build(b);
return 1;
}
for (int i = 0; i < p.size(); i++) {
for (int j = i + 1; j < p.size(); j++) {
if (p[i][j] != 0) {
ds.unite(i, j);
}
}
}
for (int i = 0; i < p.size(); i++) {
for (int j = i + 1; j < p.size(); j++) {
if (p[i][j] == 0 && ds.same(i, j)) {
return 0;
} else if (p[i][j] == 1 && !ds.same(i, j)) {
return 0;
}
}
}
vector<vector<int>> conncomps(p.size());
for (int i = 0; i < p.size(); i++) {
conncomps[ds.get(i)].push_back(i);
}
for (int i = 0; i < conncomps.size(); i++) {
if (conncomps[i].size() < 2) {
continue;
}
if (conncomps[i].size() == 2) {
return 0;
}
for (int j = 0; j < conncomps[i].size(); j++) {
b[conncomps[i][j]][conncomps[i][(j + 1) % conncomps[i].size()]] = 1;
b[conncomps[i][(j + 1) % conncomps[i].size()]][conncomps[i][j]] = 1;
}
}
build(b);
return 1;
}
컴파일 시 표준 에러 (stderr) 메시지
supertrees.cpp: In function 'int construct(std::vector<std::vector<int> >)':
supertrees.cpp:47:20: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::vector<int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
47 | for (int i = 0; i < p.size(); i++) {
| ~~^~~~~~~~~~
supertrees.cpp:48:25: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::vector<int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
48 | for (int j = i + 1; j < p.size(); j++) {
| ~~^~~~~~~~~~
supertrees.cpp:59:21: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::vector<int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
59 | for (int i = 0; i < p.size(); i++) {
| ~~^~~~~~~~~~
supertrees.cpp:60:27: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::vector<int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
60 | for (int j = i + 1; j < p.size(); j++) {
| ~~^~~~~~~~~~
supertrees.cpp:67:21: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::vector<int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
67 | for (int i = 0; i < p.size(); i++) {
| ~~^~~~~~~~~~
supertrees.cpp:68:26: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::vector<int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
68 | for (int j = i + 1; j < p.size(); j++) {
| ~~^~~~~~~~~~
supertrees.cpp:78:21: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::vector<int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
78 | for (int i = 0; i < p.size(); i++) {
| ~~^~~~~~~~~~
supertrees.cpp:82:21: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::vector<int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
82 | for (int i = 0; i < conncomps.size(); i++) {
| ~~^~~~~~~~~~~~~~~~~~
supertrees.cpp:92:21: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::vector<int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
92 | for (int i = 0; i < p.size(); i++) {
| ~~^~~~~~~~~~
supertrees.cpp:93:26: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::vector<int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
93 | for (int j = i + 1; j < p.size(); j++) {
| ~~^~~~~~~~~~
supertrees.cpp:100:21: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::vector<int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
100 | for (int i = 0; i < p.size(); i++) {
| ~~^~~~~~~~~~
supertrees.cpp:101:26: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::vector<int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
101 | for (int j = i + 1; j < p.size(); j++) {
| ~~^~~~~~~~~~
supertrees.cpp:111:21: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::vector<int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
111 | for (int i = 0; i < p.size(); i++) {
| ~~^~~~~~~~~~
supertrees.cpp:115:21: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::vector<int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
115 | for (int i = 0; i < conncomps.size(); i++) {
| ~~^~~~~~~~~~~~~~~~~~
supertrees.cpp:122:21: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
122 | for (int j = 0; j < conncomps[i].size(); j++) {
| ~~^~~~~~~~~~~~~~~~~~~~~
supertrees.cpp:46:19: warning: variable 'two' set but not used [-Wunused-but-set-variable]
46 | bool one = true, two = true;
| ^~~
# | 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... |