이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
/**
* author: tourist
* created:
**/
#include "supertrees.h"
#include <bits/stdc++.h>
using namespace std;
#ifdef LOCAL
#include "algo/debug.h"
#else
#define debug(...) 42
#endif
void build(vector<vector<int>> b);
class dsu {
public:
vector<int> p;
int n;
dsu(int _n) : n(_n) {
p.resize(n);
iota(p.begin(), p.end(), 0);
}
int get(int x) {
return ((p[x] == x) ? x : (p[x] = get(p[x])));
}
bool unite(int u, int v) {
u = get(u); v = get(v);
if (u != v) {
p[v] = u;
return true;
}
return false;
}
};
int construct(vector<vector<int>> p) {
int n = p.size();
dsu ds(n);
for (int i = 0; i < n; i++) {
for (int j = i + 1; j < n; j++) {
if (p[i][j] > 0) {
ds.unite(i, j);
}
}
}
for (int i = 0; i < n; i++) {
for (int j = i + 1; j < n; j++) {
if (!p[i][j]) {
if (ds.unite(i, j)) {
return 0;
}
}
}
}
dsu two(n), one(n);
for (int i = 0; i < n; i++) {
for (int j = i + 1; j < n; j++) {
if (p[i][j] == 1) {
one.unite(i, j);
}
if (p[i][j] == 2) {
two.unite(i, j);
}
}
}
vector<vector<int>> b(n, vector<int>(n));
vector<vector<int>> comps(n);
for (int i = 0; i < n; i++) {
comps[one.get(i)].push_back(i);
}
for (int i = 0; i < n; i++) {
for (int j = 0; j + 1 < comps[i].size(); j++) {
b[comps[i][j + 1]][comps[i][j]] = true;
b[comps[i][j]][comps[i][j + 1]] = true;
}
}
for (int i = 0; i < n; i++) {
comps[i].clear();
}
for (int i = 0; i < n; i++) {
comps[two.get(i)].push_back(i);
}
for (int i = 0; i < n; i++) {
for (int j = 0; j < comps[i].size(); j++) {
b[comps[i][(j + 1) % comps[i].size()]][comps[i][j]] = true;
b[comps[i][j]][comps[i][(j + 1) % comps[i].size()]] = true;
}
}
build(b);
}
컴파일 시 표준 에러 (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 + 1 < comps[i].size(); j++) {
| ~~~~~~^~~~~~~~~~~~~~~~~
supertrees.cpp:90:23: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
90 | for (int j = 0; j < comps[i].size(); j++) {
| ~~^~~~~~~~~~~~~~~~~
supertrees.cpp:44:11: warning: control reaches end of non-void function [-Wreturn-type]
44 | dsu ds(n);
| ^
# | 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... |