/*
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;
map<pair<int, int>, int> connected;
function<int(int)> fp = [&](int x) {
if (dsu[x] == x) return x;
return dsu[x] = fp(dsu[x]);
};
for (int i = 1; i <= n; i ++) {
vector nx = {0, 2, 0, -2}, ny = {2, 0, -2, 0};
for (int j = 0; j < 4; j ++) {
int xx = x[i] + nx[j], yy = y[i] + ny[j];
if (mp[{xx, yy}]) {
int fx = fp(i), fy = fp(mp[{xx, yy}]);
if (fx != fy) {
if (x[i] < xx || y[i] < yy) {
u.push_back(i);
v.push_back(mp[{xx, yy}]);
}
else {
v.push_back(i);
u.push_back(mp[{xx, yy}]);
}
gr[i].push_back(mp[{xx, yy}]);
gr[mp[{xx, yy}]].push_back(i);
dsu[fx] = fy;
connected[{i, mp[{xx, yy}]}] = 1;
connected[{mp[{xx, yy}], i}] = 1;
}
}
}
}
int num = 0, st = 1;
vector<int> vis(n + 1);
function<void(int)> go = [&] (int v) {
num ++;
vis[v] = 1;
vector nx = {0, 2, 0, -2}, 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] || connected[{u, v}] == 0) 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:130:23: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
130 | 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 |
0 ms |
348 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 |
823 ms |
96172 KB |
Output is correct |
10 |
Correct |
37 ms |
10352 KB |
Output is correct |
11 |
Correct |
230 ms |
54312 KB |
Output is correct |
12 |
Correct |
50 ms |
15440 KB |
Output is correct |
13 |
Correct |
147 ms |
35536 KB |
Output is correct |
14 |
Correct |
3 ms |
860 KB |
Output is correct |
15 |
Correct |
5 ms |
1372 KB |
Output is correct |
16 |
Correct |
726 ms |
79352 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
348 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 |
823 ms |
96172 KB |
Output is correct |
10 |
Correct |
37 ms |
10352 KB |
Output is correct |
11 |
Correct |
230 ms |
54312 KB |
Output is correct |
12 |
Correct |
50 ms |
15440 KB |
Output is correct |
13 |
Correct |
147 ms |
35536 KB |
Output is correct |
14 |
Correct |
3 ms |
860 KB |
Output is correct |
15 |
Correct |
5 ms |
1372 KB |
Output is correct |
16 |
Correct |
726 ms |
79352 KB |
Output is correct |
17 |
Correct |
0 ms |
348 KB |
Output is correct |
18 |
Correct |
0 ms |
348 KB |
Output is correct |
19 |
Correct |
0 ms |
348 KB |
Output is correct |
20 |
Correct |
0 ms |
348 KB |
Output is correct |
21 |
Correct |
0 ms |
348 KB |
Output is correct |
22 |
Correct |
1 ms |
348 KB |
Output is correct |
23 |
Correct |
1780 ms |
145968 KB |
Output is correct |
24 |
Correct |
0 ms |
348 KB |
Output is correct |
25 |
Correct |
4 ms |
1116 KB |
Output is correct |
26 |
Correct |
9 ms |
1884 KB |
Output is correct |
27 |
Correct |
12 ms |
2140 KB |
Output is correct |
28 |
Correct |
612 ms |
60248 KB |
Output is correct |
29 |
Correct |
1029 ms |
84640 KB |
Output is correct |
30 |
Correct |
1685 ms |
117712 KB |
Output is correct |
31 |
Correct |
2100 ms |
141644 KB |
Output is correct |
32 |
Correct |
0 ms |
348 KB |
Output is correct |
33 |
Correct |
0 ms |
348 KB |
Output is correct |
34 |
Correct |
0 ms |
348 KB |
Output is correct |
35 |
Correct |
0 ms |
348 KB |
Output is correct |
36 |
Correct |
0 ms |
348 KB |
Output is correct |
37 |
Correct |
0 ms |
348 KB |
Output is correct |
38 |
Correct |
0 ms |
344 KB |
Output is correct |
39 |
Correct |
0 ms |
348 KB |
Output is correct |
40 |
Correct |
0 ms |
348 KB |
Output is correct |
41 |
Correct |
0 ms |
348 KB |
Output is correct |
42 |
Correct |
0 ms |
348 KB |
Output is correct |
43 |
Correct |
6 ms |
1488 KB |
Output is correct |
44 |
Correct |
8 ms |
1704 KB |
Output is correct |
45 |
Correct |
783 ms |
79228 KB |
Output is correct |
46 |
Correct |
1307 ms |
116812 KB |
Output is correct |
47 |
Correct |
1311 ms |
114256 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
348 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 |
823 ms |
96172 KB |
Output is correct |
10 |
Correct |
37 ms |
10352 KB |
Output is correct |
11 |
Correct |
230 ms |
54312 KB |
Output is correct |
12 |
Correct |
50 ms |
15440 KB |
Output is correct |
13 |
Correct |
147 ms |
35536 KB |
Output is correct |
14 |
Correct |
3 ms |
860 KB |
Output is correct |
15 |
Correct |
5 ms |
1372 KB |
Output is correct |
16 |
Correct |
726 ms |
79352 KB |
Output is correct |
17 |
Correct |
0 ms |
348 KB |
Output is correct |
18 |
Correct |
0 ms |
348 KB |
Output is correct |
19 |
Correct |
0 ms |
348 KB |
Output is correct |
20 |
Correct |
0 ms |
348 KB |
Output is correct |
21 |
Correct |
0 ms |
348 KB |
Output is correct |
22 |
Correct |
1 ms |
348 KB |
Output is correct |
23 |
Correct |
1780 ms |
145968 KB |
Output is correct |
24 |
Correct |
0 ms |
348 KB |
Output is correct |
25 |
Correct |
4 ms |
1116 KB |
Output is correct |
26 |
Correct |
9 ms |
1884 KB |
Output is correct |
27 |
Correct |
12 ms |
2140 KB |
Output is correct |
28 |
Correct |
612 ms |
60248 KB |
Output is correct |
29 |
Correct |
1029 ms |
84640 KB |
Output is correct |
30 |
Correct |
1685 ms |
117712 KB |
Output is correct |
31 |
Correct |
2100 ms |
141644 KB |
Output is correct |
32 |
Correct |
0 ms |
348 KB |
Output is correct |
33 |
Correct |
0 ms |
348 KB |
Output is correct |
34 |
Correct |
0 ms |
348 KB |
Output is correct |
35 |
Correct |
0 ms |
348 KB |
Output is correct |
36 |
Correct |
0 ms |
348 KB |
Output is correct |
37 |
Correct |
0 ms |
348 KB |
Output is correct |
38 |
Correct |
0 ms |
344 KB |
Output is correct |
39 |
Correct |
0 ms |
348 KB |
Output is correct |
40 |
Correct |
0 ms |
348 KB |
Output is correct |
41 |
Correct |
0 ms |
348 KB |
Output is correct |
42 |
Correct |
0 ms |
348 KB |
Output is correct |
43 |
Correct |
6 ms |
1488 KB |
Output is correct |
44 |
Correct |
8 ms |
1704 KB |
Output is correct |
45 |
Correct |
783 ms |
79228 KB |
Output is correct |
46 |
Correct |
1307 ms |
116812 KB |
Output is correct |
47 |
Correct |
1311 ms |
114256 KB |
Output is correct |
48 |
Correct |
0 ms |
344 KB |
Output is correct |
49 |
Correct |
1 ms |
348 KB |
Output is correct |
50 |
Correct |
1 ms |
348 KB |
Output is correct |
51 |
Runtime error |
1 ms |
436 KB |
Execution killed with signal 6 |
52 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
348 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 |
823 ms |
96172 KB |
Output is correct |
10 |
Correct |
37 ms |
10352 KB |
Output is correct |
11 |
Correct |
230 ms |
54312 KB |
Output is correct |
12 |
Correct |
50 ms |
15440 KB |
Output is correct |
13 |
Correct |
147 ms |
35536 KB |
Output is correct |
14 |
Correct |
3 ms |
860 KB |
Output is correct |
15 |
Correct |
5 ms |
1372 KB |
Output is correct |
16 |
Correct |
726 ms |
79352 KB |
Output is correct |
17 |
Correct |
0 ms |
348 KB |
Output is correct |
18 |
Correct |
0 ms |
348 KB |
Output is correct |
19 |
Correct |
0 ms |
348 KB |
Output is correct |
20 |
Correct |
1782 ms |
186416 KB |
Output is correct |
21 |
Correct |
1849 ms |
169456 KB |
Output is correct |
22 |
Correct |
1681 ms |
159492 KB |
Output is correct |
23 |
Correct |
1502 ms |
143988 KB |
Output is correct |
24 |
Correct |
524 ms |
47408 KB |
Output is correct |
25 |
Correct |
1027 ms |
81968 KB |
Output is correct |
26 |
Correct |
1051 ms |
81988 KB |
Output is correct |
27 |
Correct |
1833 ms |
101164 KB |
Output is correct |
28 |
Correct |
1718 ms |
101176 KB |
Output is correct |
29 |
Correct |
1933 ms |
101172 KB |
Output is correct |
30 |
Correct |
1907 ms |
101144 KB |
Output is correct |
31 |
Correct |
1 ms |
348 KB |
Output is correct |
32 |
Correct |
68 ms |
10068 KB |
Output is correct |
33 |
Correct |
147 ms |
23876 KB |
Output is correct |
34 |
Correct |
1701 ms |
167296 KB |
Output is correct |
35 |
Correct |
34 ms |
4696 KB |
Output is correct |
36 |
Correct |
191 ms |
20360 KB |
Output is correct |
37 |
Correct |
448 ms |
40020 KB |
Output is correct |
38 |
Correct |
539 ms |
39156 KB |
Output is correct |
39 |
Correct |
787 ms |
53540 KB |
Output is correct |
40 |
Correct |
1107 ms |
67960 KB |
Output is correct |
41 |
Correct |
1436 ms |
82344 KB |
Output is correct |
42 |
Correct |
1732 ms |
96680 KB |
Output is correct |
43 |
Correct |
1 ms |
348 KB |
Output is correct |
44 |
Correct |
0 ms |
348 KB |
Output is correct |
45 |
Correct |
0 ms |
344 KB |
Output is correct |
46 |
Correct |
0 ms |
348 KB |
Output is correct |
47 |
Correct |
0 ms |
348 KB |
Output is correct |
48 |
Correct |
0 ms |
348 KB |
Output is correct |
49 |
Correct |
0 ms |
348 KB |
Output is correct |
50 |
Correct |
1 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 |
6 ms |
1628 KB |
Output is correct |
55 |
Correct |
8 ms |
1884 KB |
Output is correct |
56 |
Correct |
745 ms |
79028 KB |
Output is correct |
57 |
Correct |
1266 ms |
116748 KB |
Output is correct |
58 |
Correct |
1233 ms |
114092 KB |
Output is correct |
59 |
Correct |
0 ms |
348 KB |
Output is correct |
60 |
Correct |
0 ms |
348 KB |
Output is correct |
61 |
Correct |
0 ms |
348 KB |
Output is correct |
62 |
Correct |
1942 ms |
163836 KB |
Output is correct |
63 |
Correct |
1988 ms |
170752 KB |
Output is correct |
64 |
Correct |
1942 ms |
180120 KB |
Output is correct |
65 |
Correct |
12 ms |
2392 KB |
Output is correct |
66 |
Correct |
26 ms |
4476 KB |
Output is correct |
67 |
Correct |
729 ms |
64808 KB |
Output is correct |
68 |
Correct |
1298 ms |
105444 KB |
Output is correct |
69 |
Correct |
1835 ms |
129588 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
348 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 |
823 ms |
96172 KB |
Output is correct |
10 |
Correct |
37 ms |
10352 KB |
Output is correct |
11 |
Correct |
230 ms |
54312 KB |
Output is correct |
12 |
Correct |
50 ms |
15440 KB |
Output is correct |
13 |
Correct |
147 ms |
35536 KB |
Output is correct |
14 |
Correct |
3 ms |
860 KB |
Output is correct |
15 |
Correct |
5 ms |
1372 KB |
Output is correct |
16 |
Correct |
726 ms |
79352 KB |
Output is correct |
17 |
Correct |
1963 ms |
190000 KB |
Output is correct |
18 |
Correct |
1971 ms |
153648 KB |
Output is correct |
19 |
Correct |
1750 ms |
170548 KB |
Output is correct |
20 |
Correct |
1743 ms |
97100 KB |
Output is correct |
21 |
Correct |
1566 ms |
95528 KB |
Output is correct |
22 |
Correct |
0 ms |
348 KB |
Output is correct |
23 |
Correct |
174 ms |
17512 KB |
Output is correct |
24 |
Correct |
78 ms |
9144 KB |
Output is correct |
25 |
Correct |
287 ms |
28968 KB |
Output is correct |
26 |
Correct |
561 ms |
48288 KB |
Output is correct |
27 |
Correct |
711 ms |
50500 KB |
Output is correct |
28 |
Correct |
1006 ms |
62760 KB |
Output is correct |
29 |
Correct |
1198 ms |
75340 KB |
Output is correct |
30 |
Correct |
1596 ms |
87456 KB |
Output is correct |
31 |
Correct |
1849 ms |
99996 KB |
Output is correct |
32 |
Correct |
1929 ms |
142252 KB |
Output is correct |
33 |
Correct |
1945 ms |
185552 KB |
Output is correct |
34 |
Correct |
16 ms |
3164 KB |
Output is correct |
35 |
Correct |
30 ms |
5212 KB |
Output is correct |
36 |
Correct |
746 ms |
68972 KB |
Output is correct |
37 |
Correct |
1288 ms |
105712 KB |
Output is correct |
38 |
Correct |
1885 ms |
140592 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
348 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 |
823 ms |
96172 KB |
Output is correct |
10 |
Correct |
37 ms |
10352 KB |
Output is correct |
11 |
Correct |
230 ms |
54312 KB |
Output is correct |
12 |
Correct |
50 ms |
15440 KB |
Output is correct |
13 |
Correct |
147 ms |
35536 KB |
Output is correct |
14 |
Correct |
3 ms |
860 KB |
Output is correct |
15 |
Correct |
5 ms |
1372 KB |
Output is correct |
16 |
Correct |
726 ms |
79352 KB |
Output is correct |
17 |
Correct |
0 ms |
348 KB |
Output is correct |
18 |
Correct |
0 ms |
348 KB |
Output is correct |
19 |
Correct |
0 ms |
348 KB |
Output is correct |
20 |
Correct |
0 ms |
348 KB |
Output is correct |
21 |
Correct |
0 ms |
348 KB |
Output is correct |
22 |
Correct |
1 ms |
348 KB |
Output is correct |
23 |
Correct |
1780 ms |
145968 KB |
Output is correct |
24 |
Correct |
0 ms |
348 KB |
Output is correct |
25 |
Correct |
4 ms |
1116 KB |
Output is correct |
26 |
Correct |
9 ms |
1884 KB |
Output is correct |
27 |
Correct |
12 ms |
2140 KB |
Output is correct |
28 |
Correct |
612 ms |
60248 KB |
Output is correct |
29 |
Correct |
1029 ms |
84640 KB |
Output is correct |
30 |
Correct |
1685 ms |
117712 KB |
Output is correct |
31 |
Correct |
2100 ms |
141644 KB |
Output is correct |
32 |
Correct |
0 ms |
348 KB |
Output is correct |
33 |
Correct |
0 ms |
348 KB |
Output is correct |
34 |
Correct |
0 ms |
348 KB |
Output is correct |
35 |
Correct |
0 ms |
348 KB |
Output is correct |
36 |
Correct |
0 ms |
348 KB |
Output is correct |
37 |
Correct |
0 ms |
348 KB |
Output is correct |
38 |
Correct |
0 ms |
344 KB |
Output is correct |
39 |
Correct |
0 ms |
348 KB |
Output is correct |
40 |
Correct |
0 ms |
348 KB |
Output is correct |
41 |
Correct |
0 ms |
348 KB |
Output is correct |
42 |
Correct |
0 ms |
348 KB |
Output is correct |
43 |
Correct |
6 ms |
1488 KB |
Output is correct |
44 |
Correct |
8 ms |
1704 KB |
Output is correct |
45 |
Correct |
783 ms |
79228 KB |
Output is correct |
46 |
Correct |
1307 ms |
116812 KB |
Output is correct |
47 |
Correct |
1311 ms |
114256 KB |
Output is correct |
48 |
Correct |
0 ms |
344 KB |
Output is correct |
49 |
Correct |
1 ms |
348 KB |
Output is correct |
50 |
Correct |
1 ms |
348 KB |
Output is correct |
51 |
Runtime error |
1 ms |
436 KB |
Execution killed with signal 6 |
52 |
Halted |
0 ms |
0 KB |
- |