#include <bits/stdc++.h>
#include "parks.h"
using namespace std;
int construct_roads(vector<int> xs, vector<int> ys) {
int n = xs.size();
map<pair<int, int>, int> points;
for (int i = 0; i < n; ++i)
points[make_pair(xs[i], ys[i])] = i;
vector<int> rep(n); int comps = n;
for (int i = 0; i < n; ++i)
rep[i] = i;
function<int (int)> find = [&rep, &find](int u) {
if (rep[u] == u) return u;
return rep[u] = find(rep[u]);
};
function<void (int, int)> une = [&rep, &comps, &find](int u, int v) {
u = find(u); v = find(v);
if (u == v) return;
rep[u] = v;
--comps;
};
vector<int> us, vs;
for (int i = 0; i < n; ++i) {
pair<int, int> lft{xs[i], ys[i] + 2}, up{xs[i] + 2, ys[i]};
if (points.find(lft) != points.end()) {
us.push_back(i);
vs.push_back(points[lft]);
une(us.back(), vs.back());
}
if (points.find(up) != points.end()) {
us.push_back(i);
vs.push_back(points[up]);
une(us.back(), vs.back());
}
}
if (comps > 1) return 0;
map<pair<int, int>, int> mp;
vector<pair<int, int>> benches;
vector<vector<pair<int, int>>> graph;
function<int (int, int)> vertex = [&mp, &graph, &benches](int x, int y) {
pair<int, int> p{x, y};
if (mp.find(p) == mp.end()) {
benches.push_back(p);
mp[p] = graph.size();
graph.emplace_back();
}
return mp[p];
};
function<void (int, int, int)> add_edge = [&graph](int u, int v, int idx) {
graph[u].emplace_back(v, idx);
graph[v].emplace_back(u, idx);
};
for (int i = 0; i < us.size(); ++i) {
int x1 = xs[us[i]], y1 = ys[us[i]];
int x2 = xs[vs[i]], y2 = ys[vs[i]];
if (x1 == x2) {
if (y1 > y2) swap(y1, y2);
add_edge(vertex(x1 + 1, y1 + 1), vertex(x1 - 1, y1 + 1), i);
}
else {
if (x1 > x2) swap(x1, x2);
add_edge(vertex(x1 + 1, y1 + 1), vertex(x1 + 1, y1 - 1), i);
}
}
vector<bool> marc(benches.size());
vector<int> as(us.size()), bs(us.size());
for (int i = 0; i < benches.size(); ++i) if (!marc[i]) {
int u = i;
while (!marc[u]) {
marc[u] = true;
for (auto [v, idx]: graph[u]) if (!marc[v]){
as[idx] = benches[u].first;
bs[idx] = benches[u].second;
u = v;
break;
}
}
}
build(us, vs, as, bs);
return 1;
}
Compilation message
parks.cpp: In function 'int construct_roads(std::vector<int>, std::vector<int>)':
parks.cpp:68:20: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
68 | for (int i = 0; i < us.size(); ++i) {
| ~~^~~~~~~~~~~
parks.cpp:84:20: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
84 | for (int i = 0; i < benches.size(); ++i) if (!marc[i]) {
| ~~^~~~~~~~~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
2 |
Correct |
0 ms |
600 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
0 ms |
348 KB |
Output is correct |
6 |
Correct |
0 ms |
348 KB |
Output is correct |
7 |
Correct |
0 ms |
348 KB |
Output is correct |
8 |
Correct |
0 ms |
348 KB |
Output is correct |
9 |
Correct |
264 ms |
39596 KB |
Output is correct |
10 |
Correct |
16 ms |
4236 KB |
Output is correct |
11 |
Correct |
94 ms |
21232 KB |
Output is correct |
12 |
Correct |
23 ms |
6032 KB |
Output is correct |
13 |
Correct |
25 ms |
4824 KB |
Output is correct |
14 |
Correct |
1 ms |
348 KB |
Output is correct |
15 |
Correct |
1 ms |
604 KB |
Output is correct |
16 |
Correct |
279 ms |
40232 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
2 |
Correct |
0 ms |
600 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
0 ms |
348 KB |
Output is correct |
6 |
Correct |
0 ms |
348 KB |
Output is correct |
7 |
Correct |
0 ms |
348 KB |
Output is correct |
8 |
Correct |
0 ms |
348 KB |
Output is correct |
9 |
Correct |
264 ms |
39596 KB |
Output is correct |
10 |
Correct |
16 ms |
4236 KB |
Output is correct |
11 |
Correct |
94 ms |
21232 KB |
Output is correct |
12 |
Correct |
23 ms |
6032 KB |
Output is correct |
13 |
Correct |
25 ms |
4824 KB |
Output is correct |
14 |
Correct |
1 ms |
348 KB |
Output is correct |
15 |
Correct |
1 ms |
604 KB |
Output is correct |
16 |
Correct |
279 ms |
40232 KB |
Output is correct |
17 |
Incorrect |
0 ms |
344 KB |
a[1] = 0 is not an odd integer |
18 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
2 |
Correct |
0 ms |
600 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
0 ms |
348 KB |
Output is correct |
6 |
Correct |
0 ms |
348 KB |
Output is correct |
7 |
Correct |
0 ms |
348 KB |
Output is correct |
8 |
Correct |
0 ms |
348 KB |
Output is correct |
9 |
Correct |
264 ms |
39596 KB |
Output is correct |
10 |
Correct |
16 ms |
4236 KB |
Output is correct |
11 |
Correct |
94 ms |
21232 KB |
Output is correct |
12 |
Correct |
23 ms |
6032 KB |
Output is correct |
13 |
Correct |
25 ms |
4824 KB |
Output is correct |
14 |
Correct |
1 ms |
348 KB |
Output is correct |
15 |
Correct |
1 ms |
604 KB |
Output is correct |
16 |
Correct |
279 ms |
40232 KB |
Output is correct |
17 |
Incorrect |
0 ms |
344 KB |
a[1] = 0 is not an odd integer |
18 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
2 |
Correct |
0 ms |
600 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
0 ms |
348 KB |
Output is correct |
6 |
Correct |
0 ms |
348 KB |
Output is correct |
7 |
Correct |
0 ms |
348 KB |
Output is correct |
8 |
Correct |
0 ms |
348 KB |
Output is correct |
9 |
Correct |
264 ms |
39596 KB |
Output is correct |
10 |
Correct |
16 ms |
4236 KB |
Output is correct |
11 |
Correct |
94 ms |
21232 KB |
Output is correct |
12 |
Correct |
23 ms |
6032 KB |
Output is correct |
13 |
Correct |
25 ms |
4824 KB |
Output is correct |
14 |
Correct |
1 ms |
348 KB |
Output is correct |
15 |
Correct |
1 ms |
604 KB |
Output is correct |
16 |
Correct |
279 ms |
40232 KB |
Output is correct |
17 |
Incorrect |
0 ms |
344 KB |
a[1] = 0 is not an odd integer |
18 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
2 |
Correct |
0 ms |
600 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
0 ms |
348 KB |
Output is correct |
6 |
Correct |
0 ms |
348 KB |
Output is correct |
7 |
Correct |
0 ms |
348 KB |
Output is correct |
8 |
Correct |
0 ms |
348 KB |
Output is correct |
9 |
Correct |
264 ms |
39596 KB |
Output is correct |
10 |
Correct |
16 ms |
4236 KB |
Output is correct |
11 |
Correct |
94 ms |
21232 KB |
Output is correct |
12 |
Correct |
23 ms |
6032 KB |
Output is correct |
13 |
Correct |
25 ms |
4824 KB |
Output is correct |
14 |
Correct |
1 ms |
348 KB |
Output is correct |
15 |
Correct |
1 ms |
604 KB |
Output is correct |
16 |
Correct |
279 ms |
40232 KB |
Output is correct |
17 |
Incorrect |
701 ms |
78448 KB |
a[144961] = 0 is not an odd integer |
18 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
2 |
Correct |
0 ms |
600 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
0 ms |
348 KB |
Output is correct |
6 |
Correct |
0 ms |
348 KB |
Output is correct |
7 |
Correct |
0 ms |
348 KB |
Output is correct |
8 |
Correct |
0 ms |
348 KB |
Output is correct |
9 |
Correct |
264 ms |
39596 KB |
Output is correct |
10 |
Correct |
16 ms |
4236 KB |
Output is correct |
11 |
Correct |
94 ms |
21232 KB |
Output is correct |
12 |
Correct |
23 ms |
6032 KB |
Output is correct |
13 |
Correct |
25 ms |
4824 KB |
Output is correct |
14 |
Correct |
1 ms |
348 KB |
Output is correct |
15 |
Correct |
1 ms |
604 KB |
Output is correct |
16 |
Correct |
279 ms |
40232 KB |
Output is correct |
17 |
Incorrect |
0 ms |
344 KB |
a[1] = 0 is not an odd integer |
18 |
Halted |
0 ms |
0 KB |
- |