이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include "parks.h"
#include <bits/stdc++.h>
using namespace std;
struct ds {
vector<int> fa;
ds(int n) {
fa.resize(n);
iota(fa.begin(), fa.end(), 0);
}
int gfa(int x) {
return fa[x] == x ? x : fa[x] = gfa(fa[x]);
}
void unite(int x, int y) {
x = gfa(x), y = gfa(y);
if (x == y) return;
fa[x] = y;
}
};
//void build(vector<int> v, vector<int> u, vector<int> a, vector<int> b) {}
int construct_roads(std::vector<int> x, std::vector<int> y) {
if (x.size() == 1) {
build({}, {}, {}, {});
return 1;
}
int n = x.size();
int mn = *min_element(x.begin(), x.end());
int mx = *max_element(x.begin(), x.end());
if (mn == 2 && mx == 2) {
int p[n];
for (int i = 0; i < n; i++) p[i] = i;
sort(p, p + n, [&](int i, int j) {
return y[i] < y[j];
});
for (int i = 0; i + 1 < n; i++)
if (y[p[i]] + 2 != y[p[i + 1]])
return 0;
vector<int> u, v, a, b;
for (int i = 0; i + 1 < n; i++) {
u.push_back(p[i]);
v.push_back(p[i + 1]);
a.push_back(x[i] - 1);
b.push_back(y[p[i]] + 1);
}
build(u, v, a, b);
return 1;
}
if (mn == 2 && mx == 4) {
map<pair<int, int>, int> id;
for (int i = 0; i < n; i++) {
id[{x[i], y[i]}] = i + 1;
}
ds d(n);
for (int i = 0; i < n; i++) {
if (id[{x[i] + 2, y[i]}]) {
d.unite(i, id[{x[i] + 2, y[i]}] - 1);
}
if (id[{x[i], y[i] + 2}]) {
d.unite(i, id[{x[i], y[i] + 2}] - 1);
}
}
for (int i = 0; i < n; i++)
if (d.gfa(i) != d.gfa(0))
return 0;
vector<int> u, v, a, b;
for (int i = 0; i < n; i++) {
if (id[{x[i] + 2, y[i]}]) {
u.push_back(i);
v.push_back(id[{x[i] + 2, y[i]}] - 1);
a.push_back(x[i] + 1);
b.push_back(y[i] + 1);
}
if (id[{x[i], y[i] + 2}]) {
u.push_back(i);
v.push_back(id[{x[i], y[i] + 2}] - 1);
a.push_back(x[i] == 2 ? x[i] - 1 : x[i] + 1);
b.push_back(y[i] + 1);
}
}
build(u, v, a, b);
return 1;
}
}
컴파일 시 표준 에러 (stderr) 메시지
parks.cpp: In function 'int construct_roads(std::vector<int>, std::vector<int>)':
parks.cpp:85:1: warning: control reaches end of non-void function [-Wreturn-type]
85 | }
| ^
# | 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... |