/*
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);
x.insert(x.begin(), 0);
y.insert(y.begin(), 0);
map<pair<int, int>, int> mp;
for (int i = 1; i <= n; i ++) mp[{x[i], y[i]}] = i;
vector<int> u, v, a, b;
map<pair<int, int>, int> taken;
for (int i = 1; i <= n; i ++) {
if (mp[{x[i] + 2, y[i]}]) {
u.push_back(i), v.push_back(mp[{x[i] + 2, y[i]}]);
if (taken[{x[i] + 1, y[i] + 1}] == 0) {
a.push_back(x[i] + 1), b.push_back(y[i] + 1);
taken[{x[i] + 1, y[i] + 1}] = 1;
}
else if (taken[{x[i] + 1, y[i] - 1}] == 0) {
a.push_back(x[i] + 1), b.push_back(y[i] - 1);
taken[{x[i] + 1, y[i] - 1}] = 1;
}
else assert(0);
gr[i].push_back(mp[{x[i] + 2, y[i]}]);
gr[mp[{x[i] + 2, y[i]}]].push_back(i);
}
if (mp[{x[i], y[i] + 2}]) {
u.push_back(i), v.push_back(mp[{x[i], y[i] + 2}]);
if (taken[{x[i] + 1, y[i] + 1}] == 0) {
a.push_back(x[i] + 1), b.push_back(y[i] + 1);
taken[{x[i] + 1, y[i] + 1}] = 1;
}
else if (taken[{x[i] - 1, y[i] + 1}] == 0) {
a.push_back(x[i] - 1), b.push_back(y[i] + 1);
taken[{x[i] - 1, y[i] + 1}] = 1;
}
else assert(0);
gr[i].push_back(mp[{x[i], y[i] + 2}]);
gr[mp[{x[i], y[i] + 2}]].push_back(i);
}
}
for (int i = 0; i < u.size(); i ++) {
u[i] --;
v[i] --;
}
int num = 0;
vector<int> vis(n + 1);
function<void(int)> go = [&] (int x) {
num ++;
vis[x] = 1;
for (auto u : gr[x]) {
if (vis[u]) continue;
go(u);
}
};
go(1);
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:53:23: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
53 | for (int i = 0; i < u.size(); i ++) {
| ~~^~~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
344 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 |
250 ms |
38048 KB |
Output is correct |
10 |
Correct |
12 ms |
4208 KB |
Output is correct |
11 |
Correct |
72 ms |
20912 KB |
Output is correct |
12 |
Correct |
17 ms |
5980 KB |
Output is correct |
13 |
Correct |
49 ms |
14884 KB |
Output is correct |
14 |
Correct |
1 ms |
604 KB |
Output is correct |
15 |
Correct |
3 ms |
860 KB |
Output is correct |
16 |
Correct |
263 ms |
35564 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
344 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 |
250 ms |
38048 KB |
Output is correct |
10 |
Correct |
12 ms |
4208 KB |
Output is correct |
11 |
Correct |
72 ms |
20912 KB |
Output is correct |
12 |
Correct |
17 ms |
5980 KB |
Output is correct |
13 |
Correct |
49 ms |
14884 KB |
Output is correct |
14 |
Correct |
1 ms |
604 KB |
Output is correct |
15 |
Correct |
3 ms |
860 KB |
Output is correct |
16 |
Correct |
263 ms |
35564 KB |
Output is correct |
17 |
Correct |
1 ms |
348 KB |
Output is correct |
18 |
Correct |
0 ms |
348 KB |
Output is correct |
19 |
Correct |
1 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 |
0 ms |
348 KB |
Output is correct |
23 |
Correct |
844 ms |
76768 KB |
Output is correct |
24 |
Correct |
0 ms |
348 KB |
Output is correct |
25 |
Correct |
2 ms |
860 KB |
Output is correct |
26 |
Correct |
5 ms |
1248 KB |
Output is correct |
27 |
Correct |
8 ms |
1628 KB |
Output is correct |
28 |
Correct |
241 ms |
31256 KB |
Output is correct |
29 |
Correct |
399 ms |
46156 KB |
Output is correct |
30 |
Correct |
616 ms |
62568 KB |
Output is correct |
31 |
Correct |
811 ms |
76068 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 |
604 KB |
Output is correct |
39 |
Correct |
0 ms |
344 KB |
Output is correct |
40 |
Correct |
0 ms |
348 KB |
Output is correct |
41 |
Correct |
1 ms |
348 KB |
Output is correct |
42 |
Correct |
0 ms |
348 KB |
Output is correct |
43 |
Correct |
4 ms |
860 KB |
Output is correct |
44 |
Correct |
4 ms |
1116 KB |
Output is correct |
45 |
Correct |
264 ms |
35136 KB |
Output is correct |
46 |
Correct |
468 ms |
51424 KB |
Output is correct |
47 |
Correct |
495 ms |
50912 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
344 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 |
250 ms |
38048 KB |
Output is correct |
10 |
Correct |
12 ms |
4208 KB |
Output is correct |
11 |
Correct |
72 ms |
20912 KB |
Output is correct |
12 |
Correct |
17 ms |
5980 KB |
Output is correct |
13 |
Correct |
49 ms |
14884 KB |
Output is correct |
14 |
Correct |
1 ms |
604 KB |
Output is correct |
15 |
Correct |
3 ms |
860 KB |
Output is correct |
16 |
Correct |
263 ms |
35564 KB |
Output is correct |
17 |
Correct |
1 ms |
348 KB |
Output is correct |
18 |
Correct |
0 ms |
348 KB |
Output is correct |
19 |
Correct |
1 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 |
0 ms |
348 KB |
Output is correct |
23 |
Correct |
844 ms |
76768 KB |
Output is correct |
24 |
Correct |
0 ms |
348 KB |
Output is correct |
25 |
Correct |
2 ms |
860 KB |
Output is correct |
26 |
Correct |
5 ms |
1248 KB |
Output is correct |
27 |
Correct |
8 ms |
1628 KB |
Output is correct |
28 |
Correct |
241 ms |
31256 KB |
Output is correct |
29 |
Correct |
399 ms |
46156 KB |
Output is correct |
30 |
Correct |
616 ms |
62568 KB |
Output is correct |
31 |
Correct |
811 ms |
76068 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 |
604 KB |
Output is correct |
39 |
Correct |
0 ms |
344 KB |
Output is correct |
40 |
Correct |
0 ms |
348 KB |
Output is correct |
41 |
Correct |
1 ms |
348 KB |
Output is correct |
42 |
Correct |
0 ms |
348 KB |
Output is correct |
43 |
Correct |
4 ms |
860 KB |
Output is correct |
44 |
Correct |
4 ms |
1116 KB |
Output is correct |
45 |
Correct |
264 ms |
35136 KB |
Output is correct |
46 |
Correct |
468 ms |
51424 KB |
Output is correct |
47 |
Correct |
495 ms |
50912 KB |
Output is correct |
48 |
Correct |
1 ms |
344 KB |
Output is correct |
49 |
Correct |
0 ms |
344 KB |
Output is correct |
50 |
Runtime error |
1 ms |
604 KB |
Execution killed with signal 6 |
51 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
344 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 |
250 ms |
38048 KB |
Output is correct |
10 |
Correct |
12 ms |
4208 KB |
Output is correct |
11 |
Correct |
72 ms |
20912 KB |
Output is correct |
12 |
Correct |
17 ms |
5980 KB |
Output is correct |
13 |
Correct |
49 ms |
14884 KB |
Output is correct |
14 |
Correct |
1 ms |
604 KB |
Output is correct |
15 |
Correct |
3 ms |
860 KB |
Output is correct |
16 |
Correct |
263 ms |
35564 KB |
Output is correct |
17 |
Correct |
0 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 |
613 ms |
70964 KB |
Output is correct |
21 |
Correct |
725 ms |
74532 KB |
Output is correct |
22 |
Correct |
660 ms |
66864 KB |
Output is correct |
23 |
Correct |
550 ms |
61728 KB |
Output is correct |
24 |
Correct |
420 ms |
48120 KB |
Output is correct |
25 |
Correct |
714 ms |
57648 KB |
Output is correct |
26 |
Correct |
702 ms |
57752 KB |
Output is correct |
27 |
Runtime error |
112 ms |
44520 KB |
Execution killed with signal 6 |
28 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
344 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 |
250 ms |
38048 KB |
Output is correct |
10 |
Correct |
12 ms |
4208 KB |
Output is correct |
11 |
Correct |
72 ms |
20912 KB |
Output is correct |
12 |
Correct |
17 ms |
5980 KB |
Output is correct |
13 |
Correct |
49 ms |
14884 KB |
Output is correct |
14 |
Correct |
1 ms |
604 KB |
Output is correct |
15 |
Correct |
3 ms |
860 KB |
Output is correct |
16 |
Correct |
263 ms |
35564 KB |
Output is correct |
17 |
Correct |
730 ms |
76856 KB |
Output is correct |
18 |
Runtime error |
607 ms |
109616 KB |
Execution killed with signal 6 |
19 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
344 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 |
250 ms |
38048 KB |
Output is correct |
10 |
Correct |
12 ms |
4208 KB |
Output is correct |
11 |
Correct |
72 ms |
20912 KB |
Output is correct |
12 |
Correct |
17 ms |
5980 KB |
Output is correct |
13 |
Correct |
49 ms |
14884 KB |
Output is correct |
14 |
Correct |
1 ms |
604 KB |
Output is correct |
15 |
Correct |
3 ms |
860 KB |
Output is correct |
16 |
Correct |
263 ms |
35564 KB |
Output is correct |
17 |
Correct |
1 ms |
348 KB |
Output is correct |
18 |
Correct |
0 ms |
348 KB |
Output is correct |
19 |
Correct |
1 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 |
0 ms |
348 KB |
Output is correct |
23 |
Correct |
844 ms |
76768 KB |
Output is correct |
24 |
Correct |
0 ms |
348 KB |
Output is correct |
25 |
Correct |
2 ms |
860 KB |
Output is correct |
26 |
Correct |
5 ms |
1248 KB |
Output is correct |
27 |
Correct |
8 ms |
1628 KB |
Output is correct |
28 |
Correct |
241 ms |
31256 KB |
Output is correct |
29 |
Correct |
399 ms |
46156 KB |
Output is correct |
30 |
Correct |
616 ms |
62568 KB |
Output is correct |
31 |
Correct |
811 ms |
76068 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 |
604 KB |
Output is correct |
39 |
Correct |
0 ms |
344 KB |
Output is correct |
40 |
Correct |
0 ms |
348 KB |
Output is correct |
41 |
Correct |
1 ms |
348 KB |
Output is correct |
42 |
Correct |
0 ms |
348 KB |
Output is correct |
43 |
Correct |
4 ms |
860 KB |
Output is correct |
44 |
Correct |
4 ms |
1116 KB |
Output is correct |
45 |
Correct |
264 ms |
35136 KB |
Output is correct |
46 |
Correct |
468 ms |
51424 KB |
Output is correct |
47 |
Correct |
495 ms |
50912 KB |
Output is correct |
48 |
Correct |
1 ms |
344 KB |
Output is correct |
49 |
Correct |
0 ms |
344 KB |
Output is correct |
50 |
Runtime error |
1 ms |
604 KB |
Execution killed with signal 6 |
51 |
Halted |
0 ms |
0 KB |
- |