/*
Mayoeba Yabureru
*/
#include "parks.h"
#include<bits/stdc++.h>
using namespace std;
static vector<int> _u, _v, _a, _b;
int construct_roads(vector<int> x, vector<int> y) {
int n = x.size();
vector<vector<int>> gr(n + 1);
vector<int> dsu(n + 1);
x.insert(x.begin(), 0);
y.insert(y.begin(), 0);
map<pair<int, int>, int> mp;
map<pair<int, int>, pair<int, int>> mpp;
for (int i = 1; i <= n; i ++) {
mp[{x[i], y[i]}] = i;
dsu[i] = i;
}
vector<int> u, v, a, b;
map<pair<int, int>, int> taken;
function<int(int)> fp = [&](int x) {
if (dsu[x] == x) return x;
return fp(dsu[x]);
};
for (int i = 1; i <= n; i ++) {
if (mp[{x[i] + 2, y[i]}]) {
int fx = fp(i), fy = fp(mp[{x[i] + 2, y[i]}]);
if (fx != fy) {
u.push_back(i), v.push_back(mp[{x[i] + 2, y[i]}]);
gr[i].push_back(mp[{x[i] + 2, y[i]}]);
gr[mp[{x[i] + 2, y[i]}]].push_back(i);
dsu[fx] = fy;
}
}
if (mp[{x[i], y[i] + 2}]) {
int fx = fp(i), fy = fp(mp[{x[i], y[i] + 2}]);
if (fx != fy) {
u.push_back(i), v.push_back(mp[{x[i], y[i] + 2}]);
gr[i].push_back(mp[{x[i], y[i] + 2}]);
gr[mp[{x[i], y[i] + 2}]].push_back(i);
dsu[fx] = fy;
}
}
}
int num = 0, st = 0;
vector<int> vis(n + 1);
for (int i = 1; i <= n; i ++) {
if (gr[i].size() == 1) {
st = i;
break;
}
}
function<void(int)> go = [&] (int v) {
num ++;
vis[v] = 1;
vector nx = {0, 2, 0, -2};
vector ny = {2, 0, -2, 0};
int ii = 0;
for (int i = 0; i < 4; i ++) {
int u = mp[{x[v] + nx[i], y[v] + ny[i]}];
if (u == 0) continue;
if (vis[u]) {
ii = (i + 1) % 4;
break;
}
}
int nummmm = 10;
while (nummmm --) {
int i = ii;
ii = (ii + 1) % 4;
int u = mp[{x[v] + nx[i], y[v] + ny[i]}];
if (u == 0 || vis[u]) continue;
if (x[v] != x[u]) {
int xx = v, uu = u;
if (x[xx] > x[uu]) {
if (taken[{x[uu] + 1, y[uu] - 1}] == 0) {
mpp[{uu, xx}] = {x[uu] + 1, y[uu] - 1};
taken[{x[uu] + 1, y[uu] - 1}] = 1;
}
else if (taken[{x[uu] + 1, y[uu] + 1}] == 0) {
mpp[{uu, xx}] = {x[uu] + 1, y[uu] + 1};
taken[{x[uu] + 1, y[uu] + 1}] = 1;
}
else assert(0);
}
else {
if (taken[{x[xx] + 1, y[xx] + 1}] == 0) {
mpp[{xx, uu}] = {x[xx] + 1, y[xx] + 1};
taken[{x[xx] + 1, y[xx] + 1}] = 1;
}
else if (taken[{x[xx] + 1, y[xx] - 1}] == 0) {
mpp[{xx, uu}] = {x[xx] + 1, y[xx] - 1};
taken[{x[xx] + 1, y[xx] - 1}] = 1;
}
else assert(0);
}
}
else {
int xx = v, uu = u;
if (y[xx] > y[uu]) {
if (taken[{x[uu] + 1, y[uu] + 1}] == 0) {
mpp[{uu, xx}] = {x[uu] + 1, y[uu] + 1};
taken[{x[uu] + 1, y[uu] + 1}] = 1;
}
else if (taken[{x[uu] - 1, y[uu] + 1}] == 0) {
mpp[{uu, xx}] = {x[uu] - 1, y[uu] + 1};
taken[{x[uu] - 1, y[uu] + 1}] = 1;
}
else assert(0);
}
else {
if (taken[{x[xx] - 1, y[xx] + 1}] == 0) {
mpp[{xx, uu}] = {x[xx] - 1, y[xx] + 1};
taken[{x[xx] - 1, y[xx] + 1}] = 1;
}
else if (taken[{x[xx] + 1, y[xx] + 1}] == 0) {
mpp[{xx, uu}] = {x[xx] + 1, y[xx] + 1};
taken[{x[xx] + 1, y[xx] + 1}] = 1;
}
else assert(0);
}
}
go(u);
}
};
go(st);
for (int i = 0; i < u.size(); i ++) {
a.push_back(mpp[{u[i], v[i]}].first);
b.push_back(mpp[{u[i], v[i]}].second);
u[i] --;
v[i] --;
}
if (num == n) {
build(u, v, a, b);
return 1;
}
return 0;
}
Compilation message
parks.cpp: In function 'int construct_roads(std::vector<int>, std::vector<int>)':
parks.cpp:132:23: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
132 | for (int i = 0; i < u.size(); i ++) {
| ~~^~~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
1 ms |
344 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
1 ms |
348 KB |
Output is correct |
6 |
Correct |
1 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 |
593 ms |
88956 KB |
Output is correct |
10 |
Correct |
30 ms |
9196 KB |
Output is correct |
11 |
Correct |
213 ms |
48224 KB |
Output is correct |
12 |
Correct |
45 ms |
13648 KB |
Output is correct |
13 |
Correct |
118 ms |
29448 KB |
Output is correct |
14 |
Correct |
2 ms |
860 KB |
Output is correct |
15 |
Correct |
5 ms |
1116 KB |
Output is correct |
16 |
Correct |
556 ms |
82756 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
1 ms |
344 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
1 ms |
348 KB |
Output is correct |
6 |
Correct |
1 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 |
593 ms |
88956 KB |
Output is correct |
10 |
Correct |
30 ms |
9196 KB |
Output is correct |
11 |
Correct |
213 ms |
48224 KB |
Output is correct |
12 |
Correct |
45 ms |
13648 KB |
Output is correct |
13 |
Correct |
118 ms |
29448 KB |
Output is correct |
14 |
Correct |
2 ms |
860 KB |
Output is correct |
15 |
Correct |
5 ms |
1116 KB |
Output is correct |
16 |
Correct |
556 ms |
82756 KB |
Output is correct |
17 |
Correct |
0 ms |
348 KB |
Output is correct |
18 |
Correct |
1 ms |
348 KB |
Output is correct |
19 |
Incorrect |
1 ms |
440 KB |
a[0] = 0 is not an odd integer |
20 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
1 ms |
344 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
1 ms |
348 KB |
Output is correct |
6 |
Correct |
1 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 |
593 ms |
88956 KB |
Output is correct |
10 |
Correct |
30 ms |
9196 KB |
Output is correct |
11 |
Correct |
213 ms |
48224 KB |
Output is correct |
12 |
Correct |
45 ms |
13648 KB |
Output is correct |
13 |
Correct |
118 ms |
29448 KB |
Output is correct |
14 |
Correct |
2 ms |
860 KB |
Output is correct |
15 |
Correct |
5 ms |
1116 KB |
Output is correct |
16 |
Correct |
556 ms |
82756 KB |
Output is correct |
17 |
Correct |
0 ms |
348 KB |
Output is correct |
18 |
Correct |
1 ms |
348 KB |
Output is correct |
19 |
Incorrect |
1 ms |
440 KB |
a[0] = 0 is not an odd integer |
20 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
1 ms |
344 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
1 ms |
348 KB |
Output is correct |
6 |
Correct |
1 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 |
593 ms |
88956 KB |
Output is correct |
10 |
Correct |
30 ms |
9196 KB |
Output is correct |
11 |
Correct |
213 ms |
48224 KB |
Output is correct |
12 |
Correct |
45 ms |
13648 KB |
Output is correct |
13 |
Correct |
118 ms |
29448 KB |
Output is correct |
14 |
Correct |
2 ms |
860 KB |
Output is correct |
15 |
Correct |
5 ms |
1116 KB |
Output is correct |
16 |
Correct |
556 ms |
82756 KB |
Output is correct |
17 |
Correct |
1 ms |
344 KB |
Output is correct |
18 |
Correct |
0 ms |
348 KB |
Output is correct |
19 |
Correct |
0 ms |
348 KB |
Output is correct |
20 |
Correct |
1053 ms |
166056 KB |
Output is correct |
21 |
Correct |
1107 ms |
165680 KB |
Output is correct |
22 |
Correct |
1073 ms |
162380 KB |
Output is correct |
23 |
Correct |
1147 ms |
149288 KB |
Output is correct |
24 |
Correct |
479 ms |
49204 KB |
Output is correct |
25 |
Correct |
596 ms |
58548 KB |
Output is correct |
26 |
Correct |
584 ms |
58416 KB |
Output is correct |
27 |
Correct |
1063 ms |
77872 KB |
Output is correct |
28 |
Correct |
1073 ms |
77616 KB |
Output is correct |
29 |
Correct |
1259 ms |
77860 KB |
Output is correct |
30 |
Correct |
1238 ms |
77872 KB |
Output is correct |
31 |
Correct |
1 ms |
348 KB |
Output is correct |
32 |
Correct |
49 ms |
7784 KB |
Output is correct |
33 |
Correct |
125 ms |
25160 KB |
Output is correct |
34 |
Correct |
1115 ms |
165960 KB |
Output is correct |
35 |
Correct |
21 ms |
3416 KB |
Output is correct |
36 |
Correct |
107 ms |
14624 KB |
Output is correct |
37 |
Correct |
257 ms |
28236 KB |
Output is correct |
38 |
Correct |
320 ms |
30164 KB |
Output is correct |
39 |
Correct |
474 ms |
41196 KB |
Output is correct |
40 |
Correct |
671 ms |
52024 KB |
Output is correct |
41 |
Correct |
834 ms |
63044 KB |
Output is correct |
42 |
Correct |
1087 ms |
74288 KB |
Output is correct |
43 |
Correct |
0 ms |
348 KB |
Output is correct |
44 |
Correct |
0 ms |
348 KB |
Output is correct |
45 |
Correct |
0 ms |
348 KB |
Output is correct |
46 |
Correct |
0 ms |
348 KB |
Output is correct |
47 |
Correct |
0 ms |
344 KB |
Output is correct |
48 |
Correct |
0 ms |
348 KB |
Output is correct |
49 |
Correct |
0 ms |
348 KB |
Output is correct |
50 |
Correct |
0 ms |
348 KB |
Output is correct |
51 |
Correct |
0 ms |
348 KB |
Output is correct |
52 |
Correct |
0 ms |
348 KB |
Output is correct |
53 |
Correct |
1 ms |
348 KB |
Output is correct |
54 |
Correct |
4 ms |
1372 KB |
Output is correct |
55 |
Correct |
5 ms |
1368 KB |
Output is correct |
56 |
Correct |
473 ms |
64028 KB |
Output is correct |
57 |
Correct |
756 ms |
94028 KB |
Output is correct |
58 |
Correct |
828 ms |
81932 KB |
Output is correct |
59 |
Correct |
1 ms |
344 KB |
Output is correct |
60 |
Correct |
0 ms |
348 KB |
Output is correct |
61 |
Correct |
1 ms |
344 KB |
Output is correct |
62 |
Correct |
1305 ms |
171228 KB |
Output is correct |
63 |
Correct |
1253 ms |
165000 KB |
Output is correct |
64 |
Correct |
1223 ms |
167224 KB |
Output is correct |
65 |
Correct |
8 ms |
1884 KB |
Output is correct |
66 |
Correct |
14 ms |
3124 KB |
Output is correct |
67 |
Correct |
472 ms |
53156 KB |
Output is correct |
68 |
Correct |
845 ms |
93632 KB |
Output is correct |
69 |
Correct |
1183 ms |
117696 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
1 ms |
344 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
1 ms |
348 KB |
Output is correct |
6 |
Correct |
1 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 |
593 ms |
88956 KB |
Output is correct |
10 |
Correct |
30 ms |
9196 KB |
Output is correct |
11 |
Correct |
213 ms |
48224 KB |
Output is correct |
12 |
Correct |
45 ms |
13648 KB |
Output is correct |
13 |
Correct |
118 ms |
29448 KB |
Output is correct |
14 |
Correct |
2 ms |
860 KB |
Output is correct |
15 |
Correct |
5 ms |
1116 KB |
Output is correct |
16 |
Correct |
556 ms |
82756 KB |
Output is correct |
17 |
Correct |
1263 ms |
174596 KB |
Output is correct |
18 |
Incorrect |
1323 ms |
171064 KB |
a[11866] = 0 is not an odd integer |
19 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
1 ms |
344 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
1 ms |
348 KB |
Output is correct |
6 |
Correct |
1 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 |
593 ms |
88956 KB |
Output is correct |
10 |
Correct |
30 ms |
9196 KB |
Output is correct |
11 |
Correct |
213 ms |
48224 KB |
Output is correct |
12 |
Correct |
45 ms |
13648 KB |
Output is correct |
13 |
Correct |
118 ms |
29448 KB |
Output is correct |
14 |
Correct |
2 ms |
860 KB |
Output is correct |
15 |
Correct |
5 ms |
1116 KB |
Output is correct |
16 |
Correct |
556 ms |
82756 KB |
Output is correct |
17 |
Correct |
0 ms |
348 KB |
Output is correct |
18 |
Correct |
1 ms |
348 KB |
Output is correct |
19 |
Incorrect |
1 ms |
440 KB |
a[0] = 0 is not an odd integer |
20 |
Halted |
0 ms |
0 KB |
- |