#include "parks.h"
#include <bits/stdc++.h>
using namespace std;
// trans rights
#define ll long long
#define f first
#define s second
#define endl '\n'
#define all(x) begin(x), end(x)
int n;
vector<int> u, v, a, b;
map<pair<int, int>, int> mp;
set<pair<int, int>> done;
vector<pair<int, int>> dirs = {{0, 2}, {2, 0}, {0, -2}, {-2, 0}};
vector<pair<int, int>> bloc[2] = {{{-1, 1}, {1, 1}, {1, -1}, {-1, -1}}, {{1, 1}, {1, -1}, {-1, -1}, {-1, 1}}};
void dfs(int x, int y, int ldir = 0) {
done.insert({x, y});
for (int i = 0; i < 4; i++) {
int ndir = (ldir + 3 + i) % 4;
int nx = x + dirs[ndir].f;
int ny = y + dirs[ndir].s;
if (mp.find({nx, ny}) == mp.end()) continue;
if (done.find({nx, ny}) != done.end()) continue;
int tx = x + bloc[0][ndir].f;
int ty = y + bloc[0][ndir].s;
if (done.find({tx, ty}) == done.end()) {
u.push_back(mp[{x, y}]);
v.push_back(mp[{nx, ny}]);
done.insert({tx, ty});
a.push_back(tx);
b.push_back(ty);
dfs(nx, ny, ndir);
continue;
}
tx = x + bloc[1][ndir].f;
ty = y + bloc[1][ndir].s;
if (done.find({tx, ty}) == done.end()) {
u.push_back(mp[{x, y}]);
v.push_back(mp[{nx, ny}]);
done.insert({tx, ty});
a.push_back(tx);
b.push_back(ty);
dfs(nx, ny, ndir);
}
}
}
int construct_roads(vector<int> xs, vector<int> ys) {
srand(6969);
n = xs.size();
for (int i = 0; i < n; i++) {
mp[{xs[i], ys[i]}] = i;
}
for (int tst = 0; tst < 7; tst++) {
if (tst == 0) dfs(xs[0], ys[0]);
else dfs(xs[rand() % n], ys[rand() % n]);
if (u.size() == n - 1) {
build(u, v, a, b);
return 1;
}
done.clear();
u.clear();
v.clear();
a.clear();
b.clear();
}
return 0;
}
Compilation message
parks.cpp: In function 'int construct_roads(std::vector<int>, std::vector<int>)':
parks.cpp:61:22: warning: comparison of integer expressions of different signedness: 'std::vector<int>::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
61 | if (u.size() == n - 1) {
| ~~~~~~~~~^~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
1 ms |
212 KB |
Output is correct |
3 |
Correct |
0 ms |
212 KB |
Output is correct |
4 |
Correct |
0 ms |
212 KB |
Output is correct |
5 |
Correct |
1 ms |
276 KB |
Output is correct |
6 |
Correct |
1 ms |
244 KB |
Output is correct |
7 |
Correct |
0 ms |
212 KB |
Output is correct |
8 |
Correct |
1 ms |
212 KB |
Output is correct |
9 |
Correct |
169 ms |
33660 KB |
Output is correct |
10 |
Correct |
18 ms |
3924 KB |
Output is correct |
11 |
Correct |
97 ms |
18836 KB |
Output is correct |
12 |
Correct |
22 ms |
5636 KB |
Output is correct |
13 |
Correct |
228 ms |
10764 KB |
Output is correct |
14 |
Correct |
2 ms |
468 KB |
Output is correct |
15 |
Correct |
3 ms |
468 KB |
Output is correct |
16 |
Correct |
198 ms |
28580 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
1 ms |
212 KB |
Output is correct |
3 |
Correct |
0 ms |
212 KB |
Output is correct |
4 |
Correct |
0 ms |
212 KB |
Output is correct |
5 |
Correct |
1 ms |
276 KB |
Output is correct |
6 |
Correct |
1 ms |
244 KB |
Output is correct |
7 |
Correct |
0 ms |
212 KB |
Output is correct |
8 |
Correct |
1 ms |
212 KB |
Output is correct |
9 |
Correct |
169 ms |
33660 KB |
Output is correct |
10 |
Correct |
18 ms |
3924 KB |
Output is correct |
11 |
Correct |
97 ms |
18836 KB |
Output is correct |
12 |
Correct |
22 ms |
5636 KB |
Output is correct |
13 |
Correct |
228 ms |
10764 KB |
Output is correct |
14 |
Correct |
2 ms |
468 KB |
Output is correct |
15 |
Correct |
3 ms |
468 KB |
Output is correct |
16 |
Correct |
198 ms |
28580 KB |
Output is correct |
17 |
Correct |
1 ms |
212 KB |
Output is correct |
18 |
Correct |
0 ms |
212 KB |
Output is correct |
19 |
Correct |
1 ms |
212 KB |
Output is correct |
20 |
Correct |
0 ms |
212 KB |
Output is correct |
21 |
Correct |
0 ms |
300 KB |
Output is correct |
22 |
Correct |
0 ms |
212 KB |
Output is correct |
23 |
Correct |
443 ms |
66392 KB |
Output is correct |
24 |
Correct |
1 ms |
256 KB |
Output is correct |
25 |
Correct |
3 ms |
724 KB |
Output is correct |
26 |
Correct |
11 ms |
900 KB |
Output is correct |
27 |
Correct |
6 ms |
724 KB |
Output is correct |
28 |
Correct |
167 ms |
27868 KB |
Output is correct |
29 |
Correct |
288 ms |
41668 KB |
Output is correct |
30 |
Correct |
337 ms |
55408 KB |
Output is correct |
31 |
Correct |
448 ms |
64100 KB |
Output is correct |
32 |
Correct |
1 ms |
212 KB |
Output is correct |
33 |
Correct |
1 ms |
212 KB |
Output is correct |
34 |
Correct |
1 ms |
212 KB |
Output is correct |
35 |
Correct |
0 ms |
212 KB |
Output is correct |
36 |
Correct |
1 ms |
212 KB |
Output is correct |
37 |
Correct |
0 ms |
212 KB |
Output is correct |
38 |
Correct |
1 ms |
212 KB |
Output is correct |
39 |
Correct |
0 ms |
212 KB |
Output is correct |
40 |
Correct |
0 ms |
212 KB |
Output is correct |
41 |
Incorrect |
0 ms |
212 KB |
Pair u[0]=0 @(2, 4) and v[0]=0 @(2, 4) does not form a valid edge (distance != 2) |
42 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
1 ms |
212 KB |
Output is correct |
3 |
Correct |
0 ms |
212 KB |
Output is correct |
4 |
Correct |
0 ms |
212 KB |
Output is correct |
5 |
Correct |
1 ms |
276 KB |
Output is correct |
6 |
Correct |
1 ms |
244 KB |
Output is correct |
7 |
Correct |
0 ms |
212 KB |
Output is correct |
8 |
Correct |
1 ms |
212 KB |
Output is correct |
9 |
Correct |
169 ms |
33660 KB |
Output is correct |
10 |
Correct |
18 ms |
3924 KB |
Output is correct |
11 |
Correct |
97 ms |
18836 KB |
Output is correct |
12 |
Correct |
22 ms |
5636 KB |
Output is correct |
13 |
Correct |
228 ms |
10764 KB |
Output is correct |
14 |
Correct |
2 ms |
468 KB |
Output is correct |
15 |
Correct |
3 ms |
468 KB |
Output is correct |
16 |
Correct |
198 ms |
28580 KB |
Output is correct |
17 |
Correct |
1 ms |
212 KB |
Output is correct |
18 |
Correct |
0 ms |
212 KB |
Output is correct |
19 |
Correct |
1 ms |
212 KB |
Output is correct |
20 |
Correct |
0 ms |
212 KB |
Output is correct |
21 |
Correct |
0 ms |
300 KB |
Output is correct |
22 |
Correct |
0 ms |
212 KB |
Output is correct |
23 |
Correct |
443 ms |
66392 KB |
Output is correct |
24 |
Correct |
1 ms |
256 KB |
Output is correct |
25 |
Correct |
3 ms |
724 KB |
Output is correct |
26 |
Correct |
11 ms |
900 KB |
Output is correct |
27 |
Correct |
6 ms |
724 KB |
Output is correct |
28 |
Correct |
167 ms |
27868 KB |
Output is correct |
29 |
Correct |
288 ms |
41668 KB |
Output is correct |
30 |
Correct |
337 ms |
55408 KB |
Output is correct |
31 |
Correct |
448 ms |
64100 KB |
Output is correct |
32 |
Correct |
1 ms |
212 KB |
Output is correct |
33 |
Correct |
1 ms |
212 KB |
Output is correct |
34 |
Correct |
1 ms |
212 KB |
Output is correct |
35 |
Correct |
0 ms |
212 KB |
Output is correct |
36 |
Correct |
1 ms |
212 KB |
Output is correct |
37 |
Correct |
0 ms |
212 KB |
Output is correct |
38 |
Correct |
1 ms |
212 KB |
Output is correct |
39 |
Correct |
0 ms |
212 KB |
Output is correct |
40 |
Correct |
0 ms |
212 KB |
Output is correct |
41 |
Incorrect |
0 ms |
212 KB |
Pair u[0]=0 @(2, 4) and v[0]=0 @(2, 4) does not form a valid edge (distance != 2) |
42 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
1 ms |
212 KB |
Output is correct |
3 |
Correct |
0 ms |
212 KB |
Output is correct |
4 |
Correct |
0 ms |
212 KB |
Output is correct |
5 |
Correct |
1 ms |
276 KB |
Output is correct |
6 |
Correct |
1 ms |
244 KB |
Output is correct |
7 |
Correct |
0 ms |
212 KB |
Output is correct |
8 |
Correct |
1 ms |
212 KB |
Output is correct |
9 |
Correct |
169 ms |
33660 KB |
Output is correct |
10 |
Correct |
18 ms |
3924 KB |
Output is correct |
11 |
Correct |
97 ms |
18836 KB |
Output is correct |
12 |
Correct |
22 ms |
5636 KB |
Output is correct |
13 |
Correct |
228 ms |
10764 KB |
Output is correct |
14 |
Correct |
2 ms |
468 KB |
Output is correct |
15 |
Correct |
3 ms |
468 KB |
Output is correct |
16 |
Correct |
198 ms |
28580 KB |
Output is correct |
17 |
Correct |
0 ms |
212 KB |
Output is correct |
18 |
Correct |
0 ms |
212 KB |
Output is correct |
19 |
Correct |
1 ms |
212 KB |
Output is correct |
20 |
Correct |
505 ms |
69072 KB |
Output is correct |
21 |
Correct |
511 ms |
64084 KB |
Output is correct |
22 |
Correct |
421 ms |
61180 KB |
Output is correct |
23 |
Correct |
356 ms |
51108 KB |
Output is correct |
24 |
Correct |
107 ms |
15908 KB |
Output is correct |
25 |
Correct |
105 ms |
15940 KB |
Output is correct |
26 |
Correct |
100 ms |
15952 KB |
Output is correct |
27 |
Correct |
320 ms |
44344 KB |
Output is correct |
28 |
Correct |
345 ms |
44320 KB |
Output is correct |
29 |
Correct |
500 ms |
44244 KB |
Output is correct |
30 |
Correct |
493 ms |
44272 KB |
Output is correct |
31 |
Correct |
0 ms |
212 KB |
Output is correct |
32 |
Correct |
30 ms |
4424 KB |
Output is correct |
33 |
Correct |
57 ms |
8120 KB |
Output is correct |
34 |
Correct |
404 ms |
64960 KB |
Output is correct |
35 |
Correct |
14 ms |
1620 KB |
Output is correct |
36 |
Correct |
49 ms |
5412 KB |
Output is correct |
37 |
Correct |
68 ms |
9276 KB |
Output is correct |
38 |
Correct |
151 ms |
18032 KB |
Output is correct |
39 |
Correct |
214 ms |
24580 KB |
Output is correct |
40 |
Correct |
297 ms |
31316 KB |
Output is correct |
41 |
Correct |
359 ms |
38036 KB |
Output is correct |
42 |
Correct |
482 ms |
44732 KB |
Output is correct |
43 |
Correct |
1 ms |
212 KB |
Output is correct |
44 |
Correct |
0 ms |
212 KB |
Output is correct |
45 |
Correct |
1 ms |
212 KB |
Output is correct |
46 |
Correct |
0 ms |
212 KB |
Output is correct |
47 |
Correct |
1 ms |
212 KB |
Output is correct |
48 |
Correct |
0 ms |
212 KB |
Output is correct |
49 |
Correct |
0 ms |
212 KB |
Output is correct |
50 |
Correct |
1 ms |
212 KB |
Output is correct |
51 |
Correct |
0 ms |
212 KB |
Output is correct |
52 |
Incorrect |
0 ms |
212 KB |
Pair u[0]=0 @(2, 4) and v[0]=0 @(2, 4) does not form a valid edge (distance != 2) |
53 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
1 ms |
212 KB |
Output is correct |
3 |
Correct |
0 ms |
212 KB |
Output is correct |
4 |
Correct |
0 ms |
212 KB |
Output is correct |
5 |
Correct |
1 ms |
276 KB |
Output is correct |
6 |
Correct |
1 ms |
244 KB |
Output is correct |
7 |
Correct |
0 ms |
212 KB |
Output is correct |
8 |
Correct |
1 ms |
212 KB |
Output is correct |
9 |
Correct |
169 ms |
33660 KB |
Output is correct |
10 |
Correct |
18 ms |
3924 KB |
Output is correct |
11 |
Correct |
97 ms |
18836 KB |
Output is correct |
12 |
Correct |
22 ms |
5636 KB |
Output is correct |
13 |
Correct |
228 ms |
10764 KB |
Output is correct |
14 |
Correct |
2 ms |
468 KB |
Output is correct |
15 |
Correct |
3 ms |
468 KB |
Output is correct |
16 |
Correct |
198 ms |
28580 KB |
Output is correct |
17 |
Correct |
465 ms |
69212 KB |
Output is correct |
18 |
Correct |
403 ms |
66776 KB |
Output is correct |
19 |
Correct |
427 ms |
69392 KB |
Output is correct |
20 |
Correct |
573 ms |
59640 KB |
Output is correct |
21 |
Correct |
399 ms |
51060 KB |
Output is correct |
22 |
Correct |
1 ms |
212 KB |
Output is correct |
23 |
Correct |
53 ms |
8392 KB |
Output is correct |
24 |
Correct |
51 ms |
3804 KB |
Output is correct |
25 |
Correct |
55 ms |
7880 KB |
Output is correct |
26 |
Correct |
92 ms |
11876 KB |
Output is correct |
27 |
Correct |
226 ms |
30224 KB |
Output is correct |
28 |
Correct |
297 ms |
38108 KB |
Output is correct |
29 |
Correct |
340 ms |
45980 KB |
Output is correct |
30 |
Correct |
430 ms |
53148 KB |
Output is correct |
31 |
Correct |
498 ms |
60956 KB |
Output is correct |
32 |
Correct |
431 ms |
64152 KB |
Output is correct |
33 |
Correct |
404 ms |
69208 KB |
Output is correct |
34 |
Correct |
16 ms |
1108 KB |
Output is correct |
35 |
Correct |
17 ms |
1620 KB |
Output is correct |
36 |
Correct |
184 ms |
27232 KB |
Output is correct |
37 |
Correct |
294 ms |
41404 KB |
Output is correct |
38 |
Correct |
414 ms |
55272 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
1 ms |
212 KB |
Output is correct |
3 |
Correct |
0 ms |
212 KB |
Output is correct |
4 |
Correct |
0 ms |
212 KB |
Output is correct |
5 |
Correct |
1 ms |
276 KB |
Output is correct |
6 |
Correct |
1 ms |
244 KB |
Output is correct |
7 |
Correct |
0 ms |
212 KB |
Output is correct |
8 |
Correct |
1 ms |
212 KB |
Output is correct |
9 |
Correct |
169 ms |
33660 KB |
Output is correct |
10 |
Correct |
18 ms |
3924 KB |
Output is correct |
11 |
Correct |
97 ms |
18836 KB |
Output is correct |
12 |
Correct |
22 ms |
5636 KB |
Output is correct |
13 |
Correct |
228 ms |
10764 KB |
Output is correct |
14 |
Correct |
2 ms |
468 KB |
Output is correct |
15 |
Correct |
3 ms |
468 KB |
Output is correct |
16 |
Correct |
198 ms |
28580 KB |
Output is correct |
17 |
Correct |
1 ms |
212 KB |
Output is correct |
18 |
Correct |
0 ms |
212 KB |
Output is correct |
19 |
Correct |
1 ms |
212 KB |
Output is correct |
20 |
Correct |
0 ms |
212 KB |
Output is correct |
21 |
Correct |
0 ms |
300 KB |
Output is correct |
22 |
Correct |
0 ms |
212 KB |
Output is correct |
23 |
Correct |
443 ms |
66392 KB |
Output is correct |
24 |
Correct |
1 ms |
256 KB |
Output is correct |
25 |
Correct |
3 ms |
724 KB |
Output is correct |
26 |
Correct |
11 ms |
900 KB |
Output is correct |
27 |
Correct |
6 ms |
724 KB |
Output is correct |
28 |
Correct |
167 ms |
27868 KB |
Output is correct |
29 |
Correct |
288 ms |
41668 KB |
Output is correct |
30 |
Correct |
337 ms |
55408 KB |
Output is correct |
31 |
Correct |
448 ms |
64100 KB |
Output is correct |
32 |
Correct |
1 ms |
212 KB |
Output is correct |
33 |
Correct |
1 ms |
212 KB |
Output is correct |
34 |
Correct |
1 ms |
212 KB |
Output is correct |
35 |
Correct |
0 ms |
212 KB |
Output is correct |
36 |
Correct |
1 ms |
212 KB |
Output is correct |
37 |
Correct |
0 ms |
212 KB |
Output is correct |
38 |
Correct |
1 ms |
212 KB |
Output is correct |
39 |
Correct |
0 ms |
212 KB |
Output is correct |
40 |
Correct |
0 ms |
212 KB |
Output is correct |
41 |
Incorrect |
0 ms |
212 KB |
Pair u[0]=0 @(2, 4) and v[0]=0 @(2, 4) does not form a valid edge (distance != 2) |
42 |
Halted |
0 ms |
0 KB |
- |