#include <bits/stdc++.h>
#include "parks.h"
using namespace std;
typedef long long ll;
typedef pair<ll, ll> pll;
typedef pair<int, int> pii;
int construct_roads(vector<int> x, vector<int> y) {
vector<int> u, v, a, b;
vector<tuple<int, int, int>> points;
map<pii, int> mp;
for (int i = 0; i < x.size(); i++)
{
points.push_back({x[i], y[i], i});
mp[{x[i], y[i]}] = i;
}
sort(points.begin(), points.end());
vector<vector<int>> adj(x.size());
for (auto &p : points) {
if (get<0>(p) == 2) {
if (mp.count({4, get<1>(p)})) {
u.push_back(get<2>(p));
v.push_back(mp[{4, get<1>(p)}]);
a.push_back(3);
b.push_back(get<1>(p)-1);
adj[get<2>(p)].push_back(mp[{4, get<1>(p)}]);
adj[mp[{4, get<1>(p)}]].push_back(get<2>(p));
}
}
if (mp.count({get<0>(p), get<1>(p)+2})) {
u.push_back(get<2>(p));
v.push_back(mp[{get<0>(p), get<1>(p)+2}]);
a.push_back(get<0>(p) == 2 ? 1 : 5);
b.push_back(get<1>(p)+1);
adj[get<2>(p)].push_back(mp[{get<0>(p), get<1>(p)+2}]);
adj[mp[{get<0>(p), get<1>(p)+2}]].push_back(get<2>(p));
}
}
vector<bool> vis(x.size(), 0);
vis[0] = 1;
queue<int> q; q.push(0);
while (!q.empty())
{
int cn = q.front();q.pop();
for (int i : adj[cn]) {
if (!vis[i]) {
vis[i] = 1;
q.push(i);
}
}
}
for (int i : vis) {
if (i == 0) return 0;
}
if (x.size() == 1) {
build({}, {}, {}, {});
return 1;
}
build(u, v, a, b);
return 1;
}
Compilation message
parks.cpp: In function 'int construct_roads(std::vector<int>, std::vector<int>)':
parks.cpp:14:23: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
14 | for (int i = 0; i < x.size(); i++)
| ~~^~~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
0 ms |
296 KB |
Output is correct |
3 |
Correct |
1 ms |
212 KB |
Output is correct |
4 |
Correct |
1 ms |
212 KB |
Output is correct |
5 |
Correct |
1 ms |
212 KB |
Output is correct |
6 |
Correct |
1 ms |
212 KB |
Output is correct |
7 |
Correct |
1 ms |
296 KB |
Output is correct |
8 |
Correct |
1 ms |
212 KB |
Output is correct |
9 |
Correct |
148 ms |
20352 KB |
Output is correct |
10 |
Correct |
11 ms |
2244 KB |
Output is correct |
11 |
Correct |
72 ms |
11080 KB |
Output is correct |
12 |
Correct |
18 ms |
3212 KB |
Output is correct |
13 |
Correct |
43 ms |
7724 KB |
Output is correct |
14 |
Correct |
1 ms |
468 KB |
Output is correct |
15 |
Correct |
2 ms |
596 KB |
Output is correct |
16 |
Correct |
149 ms |
20360 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
0 ms |
296 KB |
Output is correct |
3 |
Correct |
1 ms |
212 KB |
Output is correct |
4 |
Correct |
1 ms |
212 KB |
Output is correct |
5 |
Correct |
1 ms |
212 KB |
Output is correct |
6 |
Correct |
1 ms |
212 KB |
Output is correct |
7 |
Correct |
1 ms |
296 KB |
Output is correct |
8 |
Correct |
1 ms |
212 KB |
Output is correct |
9 |
Correct |
148 ms |
20352 KB |
Output is correct |
10 |
Correct |
11 ms |
2244 KB |
Output is correct |
11 |
Correct |
72 ms |
11080 KB |
Output is correct |
12 |
Correct |
18 ms |
3212 KB |
Output is correct |
13 |
Correct |
43 ms |
7724 KB |
Output is correct |
14 |
Correct |
1 ms |
468 KB |
Output is correct |
15 |
Correct |
2 ms |
596 KB |
Output is correct |
16 |
Correct |
149 ms |
20360 KB |
Output is correct |
17 |
Correct |
0 ms |
212 KB |
Output is correct |
18 |
Correct |
1 ms |
212 KB |
Output is correct |
19 |
Correct |
1 ms |
212 KB |
Output is correct |
20 |
Correct |
1 ms |
212 KB |
Output is correct |
21 |
Correct |
1 ms |
304 KB |
Output is correct |
22 |
Correct |
1 ms |
212 KB |
Output is correct |
23 |
Correct |
448 ms |
47936 KB |
Output is correct |
24 |
Correct |
1 ms |
212 KB |
Output is correct |
25 |
Correct |
2 ms |
564 KB |
Output is correct |
26 |
Correct |
3 ms |
824 KB |
Output is correct |
27 |
Correct |
4 ms |
980 KB |
Output is correct |
28 |
Correct |
146 ms |
18268 KB |
Output is correct |
29 |
Correct |
239 ms |
28544 KB |
Output is correct |
30 |
Correct |
351 ms |
36300 KB |
Output is correct |
31 |
Correct |
452 ms |
47884 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 |
1 ms |
212 KB |
Output is correct |
36 |
Correct |
1 ms |
296 KB |
Output is correct |
37 |
Correct |
1 ms |
212 KB |
Output is correct |
38 |
Correct |
0 ms |
296 KB |
Output is correct |
39 |
Correct |
1 ms |
212 KB |
Output is correct |
40 |
Correct |
0 ms |
300 KB |
Output is correct |
41 |
Correct |
0 ms |
212 KB |
Output is correct |
42 |
Correct |
1 ms |
296 KB |
Output is correct |
43 |
Correct |
2 ms |
596 KB |
Output is correct |
44 |
Correct |
3 ms |
724 KB |
Output is correct |
45 |
Correct |
167 ms |
20420 KB |
Output is correct |
46 |
Correct |
257 ms |
30588 KB |
Output is correct |
47 |
Correct |
251 ms |
30548 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
0 ms |
296 KB |
Output is correct |
3 |
Correct |
1 ms |
212 KB |
Output is correct |
4 |
Correct |
1 ms |
212 KB |
Output is correct |
5 |
Correct |
1 ms |
212 KB |
Output is correct |
6 |
Correct |
1 ms |
212 KB |
Output is correct |
7 |
Correct |
1 ms |
296 KB |
Output is correct |
8 |
Correct |
1 ms |
212 KB |
Output is correct |
9 |
Correct |
148 ms |
20352 KB |
Output is correct |
10 |
Correct |
11 ms |
2244 KB |
Output is correct |
11 |
Correct |
72 ms |
11080 KB |
Output is correct |
12 |
Correct |
18 ms |
3212 KB |
Output is correct |
13 |
Correct |
43 ms |
7724 KB |
Output is correct |
14 |
Correct |
1 ms |
468 KB |
Output is correct |
15 |
Correct |
2 ms |
596 KB |
Output is correct |
16 |
Correct |
149 ms |
20360 KB |
Output is correct |
17 |
Correct |
0 ms |
212 KB |
Output is correct |
18 |
Correct |
1 ms |
212 KB |
Output is correct |
19 |
Correct |
1 ms |
212 KB |
Output is correct |
20 |
Correct |
1 ms |
212 KB |
Output is correct |
21 |
Correct |
1 ms |
304 KB |
Output is correct |
22 |
Correct |
1 ms |
212 KB |
Output is correct |
23 |
Correct |
448 ms |
47936 KB |
Output is correct |
24 |
Correct |
1 ms |
212 KB |
Output is correct |
25 |
Correct |
2 ms |
564 KB |
Output is correct |
26 |
Correct |
3 ms |
824 KB |
Output is correct |
27 |
Correct |
4 ms |
980 KB |
Output is correct |
28 |
Correct |
146 ms |
18268 KB |
Output is correct |
29 |
Correct |
239 ms |
28544 KB |
Output is correct |
30 |
Correct |
351 ms |
36300 KB |
Output is correct |
31 |
Correct |
452 ms |
47884 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 |
1 ms |
212 KB |
Output is correct |
36 |
Correct |
1 ms |
296 KB |
Output is correct |
37 |
Correct |
1 ms |
212 KB |
Output is correct |
38 |
Correct |
0 ms |
296 KB |
Output is correct |
39 |
Correct |
1 ms |
212 KB |
Output is correct |
40 |
Correct |
0 ms |
300 KB |
Output is correct |
41 |
Correct |
0 ms |
212 KB |
Output is correct |
42 |
Correct |
1 ms |
296 KB |
Output is correct |
43 |
Correct |
2 ms |
596 KB |
Output is correct |
44 |
Correct |
3 ms |
724 KB |
Output is correct |
45 |
Correct |
167 ms |
20420 KB |
Output is correct |
46 |
Correct |
257 ms |
30588 KB |
Output is correct |
47 |
Correct |
251 ms |
30548 KB |
Output is correct |
48 |
Incorrect |
0 ms |
212 KB |
Solution announced impossible, but it is possible. |
49 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
0 ms |
296 KB |
Output is correct |
3 |
Correct |
1 ms |
212 KB |
Output is correct |
4 |
Correct |
1 ms |
212 KB |
Output is correct |
5 |
Correct |
1 ms |
212 KB |
Output is correct |
6 |
Correct |
1 ms |
212 KB |
Output is correct |
7 |
Correct |
1 ms |
296 KB |
Output is correct |
8 |
Correct |
1 ms |
212 KB |
Output is correct |
9 |
Correct |
148 ms |
20352 KB |
Output is correct |
10 |
Correct |
11 ms |
2244 KB |
Output is correct |
11 |
Correct |
72 ms |
11080 KB |
Output is correct |
12 |
Correct |
18 ms |
3212 KB |
Output is correct |
13 |
Correct |
43 ms |
7724 KB |
Output is correct |
14 |
Correct |
1 ms |
468 KB |
Output is correct |
15 |
Correct |
2 ms |
596 KB |
Output is correct |
16 |
Correct |
149 ms |
20360 KB |
Output is correct |
17 |
Incorrect |
1 ms |
212 KB |
Solution announced impossible, but it is possible. |
18 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
0 ms |
296 KB |
Output is correct |
3 |
Correct |
1 ms |
212 KB |
Output is correct |
4 |
Correct |
1 ms |
212 KB |
Output is correct |
5 |
Correct |
1 ms |
212 KB |
Output is correct |
6 |
Correct |
1 ms |
212 KB |
Output is correct |
7 |
Correct |
1 ms |
296 KB |
Output is correct |
8 |
Correct |
1 ms |
212 KB |
Output is correct |
9 |
Correct |
148 ms |
20352 KB |
Output is correct |
10 |
Correct |
11 ms |
2244 KB |
Output is correct |
11 |
Correct |
72 ms |
11080 KB |
Output is correct |
12 |
Correct |
18 ms |
3212 KB |
Output is correct |
13 |
Correct |
43 ms |
7724 KB |
Output is correct |
14 |
Correct |
1 ms |
468 KB |
Output is correct |
15 |
Correct |
2 ms |
596 KB |
Output is correct |
16 |
Correct |
149 ms |
20360 KB |
Output is correct |
17 |
Incorrect |
257 ms |
29768 KB |
Solution announced impossible, but it is possible. |
18 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
0 ms |
296 KB |
Output is correct |
3 |
Correct |
1 ms |
212 KB |
Output is correct |
4 |
Correct |
1 ms |
212 KB |
Output is correct |
5 |
Correct |
1 ms |
212 KB |
Output is correct |
6 |
Correct |
1 ms |
212 KB |
Output is correct |
7 |
Correct |
1 ms |
296 KB |
Output is correct |
8 |
Correct |
1 ms |
212 KB |
Output is correct |
9 |
Correct |
148 ms |
20352 KB |
Output is correct |
10 |
Correct |
11 ms |
2244 KB |
Output is correct |
11 |
Correct |
72 ms |
11080 KB |
Output is correct |
12 |
Correct |
18 ms |
3212 KB |
Output is correct |
13 |
Correct |
43 ms |
7724 KB |
Output is correct |
14 |
Correct |
1 ms |
468 KB |
Output is correct |
15 |
Correct |
2 ms |
596 KB |
Output is correct |
16 |
Correct |
149 ms |
20360 KB |
Output is correct |
17 |
Correct |
0 ms |
212 KB |
Output is correct |
18 |
Correct |
1 ms |
212 KB |
Output is correct |
19 |
Correct |
1 ms |
212 KB |
Output is correct |
20 |
Correct |
1 ms |
212 KB |
Output is correct |
21 |
Correct |
1 ms |
304 KB |
Output is correct |
22 |
Correct |
1 ms |
212 KB |
Output is correct |
23 |
Correct |
448 ms |
47936 KB |
Output is correct |
24 |
Correct |
1 ms |
212 KB |
Output is correct |
25 |
Correct |
2 ms |
564 KB |
Output is correct |
26 |
Correct |
3 ms |
824 KB |
Output is correct |
27 |
Correct |
4 ms |
980 KB |
Output is correct |
28 |
Correct |
146 ms |
18268 KB |
Output is correct |
29 |
Correct |
239 ms |
28544 KB |
Output is correct |
30 |
Correct |
351 ms |
36300 KB |
Output is correct |
31 |
Correct |
452 ms |
47884 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 |
1 ms |
212 KB |
Output is correct |
36 |
Correct |
1 ms |
296 KB |
Output is correct |
37 |
Correct |
1 ms |
212 KB |
Output is correct |
38 |
Correct |
0 ms |
296 KB |
Output is correct |
39 |
Correct |
1 ms |
212 KB |
Output is correct |
40 |
Correct |
0 ms |
300 KB |
Output is correct |
41 |
Correct |
0 ms |
212 KB |
Output is correct |
42 |
Correct |
1 ms |
296 KB |
Output is correct |
43 |
Correct |
2 ms |
596 KB |
Output is correct |
44 |
Correct |
3 ms |
724 KB |
Output is correct |
45 |
Correct |
167 ms |
20420 KB |
Output is correct |
46 |
Correct |
257 ms |
30588 KB |
Output is correct |
47 |
Correct |
251 ms |
30548 KB |
Output is correct |
48 |
Incorrect |
0 ms |
212 KB |
Solution announced impossible, but it is possible. |
49 |
Halted |
0 ms |
0 KB |
- |