/*
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<pair<int, int>, pair<int, int>>, int> connected;
map<pair<int, int>, int> taken;
for (int i = 1; i <= n; i ++) {
if (x[i] == 2 && mp[{x[i], y[i] + 2}]) {
connected[{{x[i], y[i]}, {x[i], y[i] + 2}}] = 1;
u.push_back(i), v.push_back(mp[{x[i], y[i] + 2}]);
a.push_back(x[i] - 1), b.push_back(y[i] + 1);
taken[{x[i] - 1, y[i] + 1}] = 1;
gr[i].push_back(mp[{x[i], y[i] + 2}]);
gr[mp[{x[i], y[i] + 2}]].push_back(i);
}
else if (x[i] == 6 && mp[{x[i], y[i] + 2}]) {
connected[{{x[i], y[i]}, {x[i], y[i] + 2}}] = 1;
u.push_back(i), v.push_back(mp[{x[i], y[i] + 2}]);
a.push_back(x[i] + 1), b.push_back(y[i] + 1);
taken[{x[i] + 1, y[i] + 1}] = 1;
gr[i].push_back(mp[{x[i], y[i] + 2}]);
gr[mp[{x[i], y[i] + 2}]].push_back(i);
}
else if (x[i] == 4 && mp[{x[i], y[i] + 2}]) {
connected[{{x[i], y[i]}, {x[i], y[i] + 2}}] = 1;
u.push_back(i), v.push_back(mp[{x[i], y[i] + 2}]);
if (y[i] % 4 == 2) a.push_back(x[i] + 1);
else a.push_back(x[i] - 1);
b.push_back(y[i] + 1);
taken[{a.back(), b.back()}] = 1;
gr[i].push_back(mp[{x[i], y[i] + 2}]);
gr[mp[{x[i], y[i] + 2}]].push_back(i);
}
}
for (int i = 1; i <= n; i ++) {
if (x[i] == 2 && mp[{x[i] + 2, y[i]}]) {
if (connected[{{x[i], y[i] - 2}, {x[i] + 2, y[i] - 2}}] == 1) continue;
if (connected[{{x[i], y[i] + 2}, {x[i] + 2, y[i] + 2}}] == 1) continue;
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);
connected[{{x[i], y[i]}, {x[i] + 2, y[i]}}] = 1;
gr[i].push_back(mp[{x[i] + 2, y[i]}]);
gr[mp[{x[i] + 2, y[i]}]].push_back(i);
}
else if (x[i] == 6 && mp[{x[i] - 2, y[i]}]) {
if (connected[{{x[i], y[i] - 2}, {x[i] - 2, y[i] - 2}}] == 1) continue;
if (connected[{{x[i], y[i] + 2}, {x[i] - 2, y[i] + 2}}] == 1) continue;
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);
connected[{{x[i], y[i]}, {x[i] - 2, y[i]}}] = 1;
gr[i].push_back(mp[{x[i] - 2, y[i]}]);
gr[mp[{x[i] - 2, y[i]}]].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:88:23: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
88 | for (int i = 0; i < u.size(); i ++) {
| ~~^~~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
1 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 |
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 |
295 ms |
44276 KB |
Output is correct |
10 |
Correct |
14 ms |
4900 KB |
Output is correct |
11 |
Correct |
88 ms |
24232 KB |
Output is correct |
12 |
Correct |
19 ms |
7000 KB |
Output is correct |
13 |
Correct |
58 ms |
17668 KB |
Output is correct |
14 |
Correct |
2 ms |
604 KB |
Output is correct |
15 |
Correct |
3 ms |
1116 KB |
Output is correct |
16 |
Correct |
298 ms |
41852 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
1 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 |
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 |
295 ms |
44276 KB |
Output is correct |
10 |
Correct |
14 ms |
4900 KB |
Output is correct |
11 |
Correct |
88 ms |
24232 KB |
Output is correct |
12 |
Correct |
19 ms |
7000 KB |
Output is correct |
13 |
Correct |
58 ms |
17668 KB |
Output is correct |
14 |
Correct |
2 ms |
604 KB |
Output is correct |
15 |
Correct |
3 ms |
1116 KB |
Output is correct |
16 |
Correct |
298 ms |
41852 KB |
Output is correct |
17 |
Correct |
0 ms |
348 KB |
Output is correct |
18 |
Correct |
0 ms |
436 KB |
Output is correct |
19 |
Correct |
1 ms |
348 KB |
Output is correct |
20 |
Correct |
0 ms |
348 KB |
Output is correct |
21 |
Correct |
1 ms |
348 KB |
Output is correct |
22 |
Correct |
0 ms |
348 KB |
Output is correct |
23 |
Correct |
942 ms |
86704 KB |
Output is correct |
24 |
Correct |
1 ms |
348 KB |
Output is correct |
25 |
Correct |
3 ms |
860 KB |
Output is correct |
26 |
Correct |
5 ms |
1372 KB |
Output is correct |
27 |
Correct |
7 ms |
1680 KB |
Output is correct |
28 |
Correct |
256 ms |
35352 KB |
Output is correct |
29 |
Correct |
465 ms |
52628 KB |
Output is correct |
30 |
Correct |
710 ms |
70252 KB |
Output is correct |
31 |
Correct |
944 ms |
87468 KB |
Output is correct |
32 |
Correct |
1 ms |
344 KB |
Output is correct |
33 |
Correct |
0 ms |
348 KB |
Output is correct |
34 |
Correct |
1 ms |
348 KB |
Output is correct |
35 |
Correct |
0 ms |
348 KB |
Output is correct |
36 |
Correct |
1 ms |
348 KB |
Output is correct |
37 |
Correct |
0 ms |
348 KB |
Output is correct |
38 |
Correct |
0 ms |
348 KB |
Output is correct |
39 |
Correct |
0 ms |
348 KB |
Output is correct |
40 |
Correct |
0 ms |
348 KB |
Output is correct |
41 |
Correct |
1 ms |
348 KB |
Output is correct |
42 |
Correct |
1 ms |
348 KB |
Output is correct |
43 |
Correct |
3 ms |
1160 KB |
Output is correct |
44 |
Correct |
5 ms |
1372 KB |
Output is correct |
45 |
Correct |
411 ms |
40508 KB |
Output is correct |
46 |
Correct |
618 ms |
58916 KB |
Output is correct |
47 |
Correct |
674 ms |
58592 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
1 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 |
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 |
295 ms |
44276 KB |
Output is correct |
10 |
Correct |
14 ms |
4900 KB |
Output is correct |
11 |
Correct |
88 ms |
24232 KB |
Output is correct |
12 |
Correct |
19 ms |
7000 KB |
Output is correct |
13 |
Correct |
58 ms |
17668 KB |
Output is correct |
14 |
Correct |
2 ms |
604 KB |
Output is correct |
15 |
Correct |
3 ms |
1116 KB |
Output is correct |
16 |
Correct |
298 ms |
41852 KB |
Output is correct |
17 |
Correct |
0 ms |
348 KB |
Output is correct |
18 |
Correct |
0 ms |
436 KB |
Output is correct |
19 |
Correct |
1 ms |
348 KB |
Output is correct |
20 |
Correct |
0 ms |
348 KB |
Output is correct |
21 |
Correct |
1 ms |
348 KB |
Output is correct |
22 |
Correct |
0 ms |
348 KB |
Output is correct |
23 |
Correct |
942 ms |
86704 KB |
Output is correct |
24 |
Correct |
1 ms |
348 KB |
Output is correct |
25 |
Correct |
3 ms |
860 KB |
Output is correct |
26 |
Correct |
5 ms |
1372 KB |
Output is correct |
27 |
Correct |
7 ms |
1680 KB |
Output is correct |
28 |
Correct |
256 ms |
35352 KB |
Output is correct |
29 |
Correct |
465 ms |
52628 KB |
Output is correct |
30 |
Correct |
710 ms |
70252 KB |
Output is correct |
31 |
Correct |
944 ms |
87468 KB |
Output is correct |
32 |
Correct |
1 ms |
344 KB |
Output is correct |
33 |
Correct |
0 ms |
348 KB |
Output is correct |
34 |
Correct |
1 ms |
348 KB |
Output is correct |
35 |
Correct |
0 ms |
348 KB |
Output is correct |
36 |
Correct |
1 ms |
348 KB |
Output is correct |
37 |
Correct |
0 ms |
348 KB |
Output is correct |
38 |
Correct |
0 ms |
348 KB |
Output is correct |
39 |
Correct |
0 ms |
348 KB |
Output is correct |
40 |
Correct |
0 ms |
348 KB |
Output is correct |
41 |
Correct |
1 ms |
348 KB |
Output is correct |
42 |
Correct |
1 ms |
348 KB |
Output is correct |
43 |
Correct |
3 ms |
1160 KB |
Output is correct |
44 |
Correct |
5 ms |
1372 KB |
Output is correct |
45 |
Correct |
411 ms |
40508 KB |
Output is correct |
46 |
Correct |
618 ms |
58916 KB |
Output is correct |
47 |
Correct |
674 ms |
58592 KB |
Output is correct |
48 |
Correct |
1 ms |
348 KB |
Output is correct |
49 |
Correct |
1 ms |
436 KB |
Output is correct |
50 |
Correct |
1 ms |
348 KB |
Output is correct |
51 |
Correct |
0 ms |
348 KB |
Output is correct |
52 |
Correct |
1 ms |
344 KB |
Output is correct |
53 |
Correct |
0 ms |
348 KB |
Output is correct |
54 |
Correct |
1 ms |
348 KB |
Output is correct |
55 |
Correct |
1162 ms |
88000 KB |
Output is correct |
56 |
Correct |
1 ms |
348 KB |
Output is correct |
57 |
Correct |
3 ms |
1268 KB |
Output is correct |
58 |
Correct |
19 ms |
3148 KB |
Output is correct |
59 |
Correct |
33 ms |
3924 KB |
Output is correct |
60 |
Correct |
397 ms |
45440 KB |
Output is correct |
61 |
Correct |
601 ms |
61548 KB |
Output is correct |
62 |
Correct |
824 ms |
72716 KB |
Output is correct |
63 |
Correct |
1261 ms |
89648 KB |
Output is correct |
64 |
Correct |
0 ms |
344 KB |
Output is correct |
65 |
Correct |
1 ms |
348 KB |
Output is correct |
66 |
Correct |
0 ms |
348 KB |
Output is correct |
67 |
Correct |
782 ms |
79340 KB |
Output is correct |
68 |
Correct |
740 ms |
79408 KB |
Output is correct |
69 |
Correct |
817 ms |
80540 KB |
Output is correct |
70 |
Correct |
9 ms |
1880 KB |
Output is correct |
71 |
Correct |
14 ms |
3164 KB |
Output is correct |
72 |
Correct |
356 ms |
39960 KB |
Output is correct |
73 |
Correct |
599 ms |
61216 KB |
Output is correct |
74 |
Correct |
971 ms |
79604 KB |
Output is correct |
75 |
Correct |
941 ms |
88372 KB |
Output is correct |
76 |
Correct |
732 ms |
82744 KB |
Output is correct |
77 |
Correct |
9 ms |
2136 KB |
Output is correct |
78 |
Correct |
16 ms |
3676 KB |
Output is correct |
79 |
Correct |
351 ms |
41588 KB |
Output is correct |
80 |
Correct |
645 ms |
62396 KB |
Output is correct |
81 |
Correct |
981 ms |
83248 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
1 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 |
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 |
295 ms |
44276 KB |
Output is correct |
10 |
Correct |
14 ms |
4900 KB |
Output is correct |
11 |
Correct |
88 ms |
24232 KB |
Output is correct |
12 |
Correct |
19 ms |
7000 KB |
Output is correct |
13 |
Correct |
58 ms |
17668 KB |
Output is correct |
14 |
Correct |
2 ms |
604 KB |
Output is correct |
15 |
Correct |
3 ms |
1116 KB |
Output is correct |
16 |
Correct |
298 ms |
41852 KB |
Output is correct |
17 |
Incorrect |
1 ms |
344 KB |
Solution announced impossible, but it is possible. |
18 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
1 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 |
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 |
295 ms |
44276 KB |
Output is correct |
10 |
Correct |
14 ms |
4900 KB |
Output is correct |
11 |
Correct |
88 ms |
24232 KB |
Output is correct |
12 |
Correct |
19 ms |
7000 KB |
Output is correct |
13 |
Correct |
58 ms |
17668 KB |
Output is correct |
14 |
Correct |
2 ms |
604 KB |
Output is correct |
15 |
Correct |
3 ms |
1116 KB |
Output is correct |
16 |
Correct |
298 ms |
41852 KB |
Output is correct |
17 |
Incorrect |
216 ms |
33176 KB |
Solution announced impossible, but it is possible. |
18 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
1 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 |
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 |
295 ms |
44276 KB |
Output is correct |
10 |
Correct |
14 ms |
4900 KB |
Output is correct |
11 |
Correct |
88 ms |
24232 KB |
Output is correct |
12 |
Correct |
19 ms |
7000 KB |
Output is correct |
13 |
Correct |
58 ms |
17668 KB |
Output is correct |
14 |
Correct |
2 ms |
604 KB |
Output is correct |
15 |
Correct |
3 ms |
1116 KB |
Output is correct |
16 |
Correct |
298 ms |
41852 KB |
Output is correct |
17 |
Correct |
0 ms |
348 KB |
Output is correct |
18 |
Correct |
0 ms |
436 KB |
Output is correct |
19 |
Correct |
1 ms |
348 KB |
Output is correct |
20 |
Correct |
0 ms |
348 KB |
Output is correct |
21 |
Correct |
1 ms |
348 KB |
Output is correct |
22 |
Correct |
0 ms |
348 KB |
Output is correct |
23 |
Correct |
942 ms |
86704 KB |
Output is correct |
24 |
Correct |
1 ms |
348 KB |
Output is correct |
25 |
Correct |
3 ms |
860 KB |
Output is correct |
26 |
Correct |
5 ms |
1372 KB |
Output is correct |
27 |
Correct |
7 ms |
1680 KB |
Output is correct |
28 |
Correct |
256 ms |
35352 KB |
Output is correct |
29 |
Correct |
465 ms |
52628 KB |
Output is correct |
30 |
Correct |
710 ms |
70252 KB |
Output is correct |
31 |
Correct |
944 ms |
87468 KB |
Output is correct |
32 |
Correct |
1 ms |
344 KB |
Output is correct |
33 |
Correct |
0 ms |
348 KB |
Output is correct |
34 |
Correct |
1 ms |
348 KB |
Output is correct |
35 |
Correct |
0 ms |
348 KB |
Output is correct |
36 |
Correct |
1 ms |
348 KB |
Output is correct |
37 |
Correct |
0 ms |
348 KB |
Output is correct |
38 |
Correct |
0 ms |
348 KB |
Output is correct |
39 |
Correct |
0 ms |
348 KB |
Output is correct |
40 |
Correct |
0 ms |
348 KB |
Output is correct |
41 |
Correct |
1 ms |
348 KB |
Output is correct |
42 |
Correct |
1 ms |
348 KB |
Output is correct |
43 |
Correct |
3 ms |
1160 KB |
Output is correct |
44 |
Correct |
5 ms |
1372 KB |
Output is correct |
45 |
Correct |
411 ms |
40508 KB |
Output is correct |
46 |
Correct |
618 ms |
58916 KB |
Output is correct |
47 |
Correct |
674 ms |
58592 KB |
Output is correct |
48 |
Correct |
1 ms |
348 KB |
Output is correct |
49 |
Correct |
1 ms |
436 KB |
Output is correct |
50 |
Correct |
1 ms |
348 KB |
Output is correct |
51 |
Correct |
0 ms |
348 KB |
Output is correct |
52 |
Correct |
1 ms |
344 KB |
Output is correct |
53 |
Correct |
0 ms |
348 KB |
Output is correct |
54 |
Correct |
1 ms |
348 KB |
Output is correct |
55 |
Correct |
1162 ms |
88000 KB |
Output is correct |
56 |
Correct |
1 ms |
348 KB |
Output is correct |
57 |
Correct |
3 ms |
1268 KB |
Output is correct |
58 |
Correct |
19 ms |
3148 KB |
Output is correct |
59 |
Correct |
33 ms |
3924 KB |
Output is correct |
60 |
Correct |
397 ms |
45440 KB |
Output is correct |
61 |
Correct |
601 ms |
61548 KB |
Output is correct |
62 |
Correct |
824 ms |
72716 KB |
Output is correct |
63 |
Correct |
1261 ms |
89648 KB |
Output is correct |
64 |
Correct |
0 ms |
344 KB |
Output is correct |
65 |
Correct |
1 ms |
348 KB |
Output is correct |
66 |
Correct |
0 ms |
348 KB |
Output is correct |
67 |
Correct |
782 ms |
79340 KB |
Output is correct |
68 |
Correct |
740 ms |
79408 KB |
Output is correct |
69 |
Correct |
817 ms |
80540 KB |
Output is correct |
70 |
Correct |
9 ms |
1880 KB |
Output is correct |
71 |
Correct |
14 ms |
3164 KB |
Output is correct |
72 |
Correct |
356 ms |
39960 KB |
Output is correct |
73 |
Correct |
599 ms |
61216 KB |
Output is correct |
74 |
Correct |
971 ms |
79604 KB |
Output is correct |
75 |
Correct |
941 ms |
88372 KB |
Output is correct |
76 |
Correct |
732 ms |
82744 KB |
Output is correct |
77 |
Correct |
9 ms |
2136 KB |
Output is correct |
78 |
Correct |
16 ms |
3676 KB |
Output is correct |
79 |
Correct |
351 ms |
41588 KB |
Output is correct |
80 |
Correct |
645 ms |
62396 KB |
Output is correct |
81 |
Correct |
981 ms |
83248 KB |
Output is correct |
82 |
Incorrect |
1 ms |
344 KB |
Solution announced impossible, but it is possible. |
83 |
Halted |
0 ms |
0 KB |
- |