#include "parks.h"
#include <bits/stdc++.h>
using namespace std;
vector<pair<int,int>> cons[200001];
int mask_l[200001];
vector<int> u;
vector<int> v;
vector<int> a;
vector<int> b;
struct dsu{
int sz = 0;
vector<int> pr;
int p(int v){
if(pr[v] == v) return v;
return pr[v] = p(pr[v]);
}
void un(int u,int v){
u = p(u);
v = p(v);
if(u == v) return;
pr[u] = v;
sz++;
}
} D;
struct edge{
int x;
int y;
int type; // 0 - vert, 1 - hor;
int a;
int b;
};
int construct_roads(vector<int> x, vector<int> y) {
int n = x.size();
D.pr.resize(n);
for (int i = 0; i < n; ++i)
{
D.pr[i] = i;
}
vector<edge> E;
vector<pair<int,pair<int,int>>> x_d;
vector<pair<int,pair<int,int>>> y_d;
for (int i = 0; i < n; ++i)
{
x_d.push_back({x[i],{y[i],i}});
y_d.push_back({y[i],{x[i],i}});
}
sort(x_d.begin(), x_d.end());
sort(y_d.begin(), y_d.end());
for (int i = 1; i < n; ++i)
{
if(x_d[i].first == x_d[i-1].first and x_d[i].second.first-2 == x_d[i-1].second.first){
E.push_back({x_d[i-1].first,x_d[i-1].second.first,0,x_d[i-1].second.second,x_d[i].second.second});
D.un(x_d[i-1].second.second,x_d[i].second.second);
}
}
for (int i = 1; i < n; ++i)
{
if(y_d[i].first == y_d[i-1].first and y_d[i].second.first-2 == y_d[i-1].second.first){
E.push_back({y_d[i-1].second.first,y_d[i-1].first,1,y_d[i-1].second.second,y_d[i].second.second});
D.un(y_d[i-1].second.second,y_d[i].second.second);
}
}
if(D.sz != n-1) return 0;
set<pair<int,int>> lines;
set<pair<int,int>> points;
sort(E.begin(),E.end(),[](auto a,auto b){
if(a.x != b.x) return a.x < b.x;
if(a.type != b.type) return a.type < b.type;
return a.y < b.y;
});
for (int i = 0; i < E.size(); ++i)
{
if(E[i].type == 0) lines.insert({E[i].x,E[i].y});
}
for (int i = 0; i < E.size(); ++i)
{
//cout << E[i].x << " " << E[i].y << " --\n";
if(E[i].type == 0){
if(points.count({E[i].x-1,E[i].y+1}) == 0){
u.push_back(E[i].a);
v.push_back(E[i].b);
a.push_back(E[i].x-1);
b.push_back(E[i].y+1);
points.insert({E[i].x-1,E[i].y+1});
}
else if(points.count({E[i].x+1,E[i].y+1}) == 0){
u.push_back(E[i].a);
v.push_back(E[i].b);
a.push_back(E[i].x+1);
b.push_back(E[i].y+1);
points.insert({E[i].x+1,E[i].y+1});
}
else return 0;
}
else{
int top = 0;
if(points.count({E[i].x+1,E[i].y-1})) top = 1;
else if(points.count({E[i].x+1,E[i].y+1})) top = 2;
if(top == 0 and lines.count({E[i].x+2,E[i].y-2})) top = 2;
if(top == 0 and lines.count({E[i].x+2,E[i].y})) top = 1;
if(top%2 == 0){
u.push_back(E[i].a);
v.push_back(E[i].b);
a.push_back(E[i].x+1);
b.push_back(E[i].y-1);
points.insert({E[i].x+1,E[i].y-1});
}
else{
u.push_back(E[i].a);
v.push_back(E[i].b);
a.push_back(E[i].x+1);
b.push_back(E[i].y+1);
points.insert({E[i].x+1,E[i].y+1});
}
}
}
//if(points.size() != n-1) return 0;
build(u,v,a,b);
return 1;
}
Compilation message
parks.cpp: In function 'int construct_roads(std::vector<int>, std::vector<int>)':
parks.cpp:71:20: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<edge>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
71 | for (int i = 0; i < E.size(); ++i)
| ~~^~~~~~~~~~
parks.cpp:75:20: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<edge>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
75 | for (int i = 0; i < E.size(); ++i)
| ~~^~~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
4948 KB |
Output is correct |
2 |
Correct |
2 ms |
4948 KB |
Output is correct |
3 |
Correct |
2 ms |
4948 KB |
Output is correct |
4 |
Correct |
2 ms |
4948 KB |
Output is correct |
5 |
Correct |
2 ms |
4948 KB |
Output is correct |
6 |
Correct |
3 ms |
4948 KB |
Output is correct |
7 |
Correct |
2 ms |
4948 KB |
Output is correct |
8 |
Correct |
2 ms |
4948 KB |
Output is correct |
9 |
Correct |
104 ms |
25472 KB |
Output is correct |
10 |
Correct |
11 ms |
7056 KB |
Output is correct |
11 |
Correct |
50 ms |
16020 KB |
Output is correct |
12 |
Correct |
16 ms |
7988 KB |
Output is correct |
13 |
Correct |
15 ms |
8844 KB |
Output is correct |
14 |
Correct |
3 ms |
5076 KB |
Output is correct |
15 |
Correct |
3 ms |
5076 KB |
Output is correct |
16 |
Correct |
114 ms |
25476 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
4948 KB |
Output is correct |
2 |
Correct |
2 ms |
4948 KB |
Output is correct |
3 |
Correct |
2 ms |
4948 KB |
Output is correct |
4 |
Correct |
2 ms |
4948 KB |
Output is correct |
5 |
Correct |
2 ms |
4948 KB |
Output is correct |
6 |
Correct |
3 ms |
4948 KB |
Output is correct |
7 |
Correct |
2 ms |
4948 KB |
Output is correct |
8 |
Correct |
2 ms |
4948 KB |
Output is correct |
9 |
Correct |
104 ms |
25472 KB |
Output is correct |
10 |
Correct |
11 ms |
7056 KB |
Output is correct |
11 |
Correct |
50 ms |
16020 KB |
Output is correct |
12 |
Correct |
16 ms |
7988 KB |
Output is correct |
13 |
Correct |
15 ms |
8844 KB |
Output is correct |
14 |
Correct |
3 ms |
5076 KB |
Output is correct |
15 |
Correct |
3 ms |
5076 KB |
Output is correct |
16 |
Correct |
114 ms |
25476 KB |
Output is correct |
17 |
Correct |
2 ms |
4948 KB |
Output is correct |
18 |
Correct |
2 ms |
4948 KB |
Output is correct |
19 |
Correct |
2 ms |
4948 KB |
Output is correct |
20 |
Correct |
2 ms |
4948 KB |
Output is correct |
21 |
Correct |
3 ms |
4948 KB |
Output is correct |
22 |
Correct |
3 ms |
4948 KB |
Output is correct |
23 |
Correct |
313 ms |
59468 KB |
Output is correct |
24 |
Correct |
3 ms |
4948 KB |
Output is correct |
25 |
Correct |
4 ms |
5332 KB |
Output is correct |
26 |
Correct |
3 ms |
5332 KB |
Output is correct |
27 |
Correct |
4 ms |
5384 KB |
Output is correct |
28 |
Correct |
119 ms |
26332 KB |
Output is correct |
29 |
Correct |
196 ms |
37304 KB |
Output is correct |
30 |
Correct |
228 ms |
47756 KB |
Output is correct |
31 |
Correct |
292 ms |
59464 KB |
Output is correct |
32 |
Correct |
2 ms |
4948 KB |
Output is correct |
33 |
Correct |
3 ms |
4948 KB |
Output is correct |
34 |
Correct |
3 ms |
4948 KB |
Output is correct |
35 |
Correct |
2 ms |
4884 KB |
Output is correct |
36 |
Correct |
3 ms |
4948 KB |
Output is correct |
37 |
Correct |
3 ms |
4948 KB |
Output is correct |
38 |
Correct |
3 ms |
4948 KB |
Output is correct |
39 |
Correct |
2 ms |
4948 KB |
Output is correct |
40 |
Correct |
2 ms |
4948 KB |
Output is correct |
41 |
Correct |
2 ms |
4948 KB |
Output is correct |
42 |
Correct |
2 ms |
4960 KB |
Output is correct |
43 |
Correct |
3 ms |
5076 KB |
Output is correct |
44 |
Correct |
3 ms |
5204 KB |
Output is correct |
45 |
Correct |
108 ms |
23984 KB |
Output is correct |
46 |
Correct |
166 ms |
33192 KB |
Output is correct |
47 |
Correct |
166 ms |
33236 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
4948 KB |
Output is correct |
2 |
Correct |
2 ms |
4948 KB |
Output is correct |
3 |
Correct |
2 ms |
4948 KB |
Output is correct |
4 |
Correct |
2 ms |
4948 KB |
Output is correct |
5 |
Correct |
2 ms |
4948 KB |
Output is correct |
6 |
Correct |
3 ms |
4948 KB |
Output is correct |
7 |
Correct |
2 ms |
4948 KB |
Output is correct |
8 |
Correct |
2 ms |
4948 KB |
Output is correct |
9 |
Correct |
104 ms |
25472 KB |
Output is correct |
10 |
Correct |
11 ms |
7056 KB |
Output is correct |
11 |
Correct |
50 ms |
16020 KB |
Output is correct |
12 |
Correct |
16 ms |
7988 KB |
Output is correct |
13 |
Correct |
15 ms |
8844 KB |
Output is correct |
14 |
Correct |
3 ms |
5076 KB |
Output is correct |
15 |
Correct |
3 ms |
5076 KB |
Output is correct |
16 |
Correct |
114 ms |
25476 KB |
Output is correct |
17 |
Correct |
2 ms |
4948 KB |
Output is correct |
18 |
Correct |
2 ms |
4948 KB |
Output is correct |
19 |
Correct |
2 ms |
4948 KB |
Output is correct |
20 |
Correct |
2 ms |
4948 KB |
Output is correct |
21 |
Correct |
3 ms |
4948 KB |
Output is correct |
22 |
Correct |
3 ms |
4948 KB |
Output is correct |
23 |
Correct |
313 ms |
59468 KB |
Output is correct |
24 |
Correct |
3 ms |
4948 KB |
Output is correct |
25 |
Correct |
4 ms |
5332 KB |
Output is correct |
26 |
Correct |
3 ms |
5332 KB |
Output is correct |
27 |
Correct |
4 ms |
5384 KB |
Output is correct |
28 |
Correct |
119 ms |
26332 KB |
Output is correct |
29 |
Correct |
196 ms |
37304 KB |
Output is correct |
30 |
Correct |
228 ms |
47756 KB |
Output is correct |
31 |
Correct |
292 ms |
59464 KB |
Output is correct |
32 |
Correct |
2 ms |
4948 KB |
Output is correct |
33 |
Correct |
3 ms |
4948 KB |
Output is correct |
34 |
Correct |
3 ms |
4948 KB |
Output is correct |
35 |
Correct |
2 ms |
4884 KB |
Output is correct |
36 |
Correct |
3 ms |
4948 KB |
Output is correct |
37 |
Correct |
3 ms |
4948 KB |
Output is correct |
38 |
Correct |
3 ms |
4948 KB |
Output is correct |
39 |
Correct |
2 ms |
4948 KB |
Output is correct |
40 |
Correct |
2 ms |
4948 KB |
Output is correct |
41 |
Correct |
2 ms |
4948 KB |
Output is correct |
42 |
Correct |
2 ms |
4960 KB |
Output is correct |
43 |
Correct |
3 ms |
5076 KB |
Output is correct |
44 |
Correct |
3 ms |
5204 KB |
Output is correct |
45 |
Correct |
108 ms |
23984 KB |
Output is correct |
46 |
Correct |
166 ms |
33192 KB |
Output is correct |
47 |
Correct |
166 ms |
33236 KB |
Output is correct |
48 |
Correct |
3 ms |
4948 KB |
Output is correct |
49 |
Correct |
3 ms |
4948 KB |
Output is correct |
50 |
Correct |
2 ms |
4948 KB |
Output is correct |
51 |
Incorrect |
2 ms |
4948 KB |
Tree @(5, 5) appears more than once: for edges on positions 4 and 5 |
52 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
4948 KB |
Output is correct |
2 |
Correct |
2 ms |
4948 KB |
Output is correct |
3 |
Correct |
2 ms |
4948 KB |
Output is correct |
4 |
Correct |
2 ms |
4948 KB |
Output is correct |
5 |
Correct |
2 ms |
4948 KB |
Output is correct |
6 |
Correct |
3 ms |
4948 KB |
Output is correct |
7 |
Correct |
2 ms |
4948 KB |
Output is correct |
8 |
Correct |
2 ms |
4948 KB |
Output is correct |
9 |
Correct |
104 ms |
25472 KB |
Output is correct |
10 |
Correct |
11 ms |
7056 KB |
Output is correct |
11 |
Correct |
50 ms |
16020 KB |
Output is correct |
12 |
Correct |
16 ms |
7988 KB |
Output is correct |
13 |
Correct |
15 ms |
8844 KB |
Output is correct |
14 |
Correct |
3 ms |
5076 KB |
Output is correct |
15 |
Correct |
3 ms |
5076 KB |
Output is correct |
16 |
Correct |
114 ms |
25476 KB |
Output is correct |
17 |
Correct |
3 ms |
4972 KB |
Output is correct |
18 |
Correct |
2 ms |
4948 KB |
Output is correct |
19 |
Correct |
2 ms |
4948 KB |
Output is correct |
20 |
Correct |
226 ms |
41344 KB |
Output is correct |
21 |
Correct |
220 ms |
41272 KB |
Output is correct |
22 |
Correct |
217 ms |
41292 KB |
Output is correct |
23 |
Correct |
173 ms |
35080 KB |
Output is correct |
24 |
Correct |
71 ms |
13752 KB |
Output is correct |
25 |
Correct |
75 ms |
21240 KB |
Output is correct |
26 |
Correct |
75 ms |
21304 KB |
Output is correct |
27 |
Correct |
255 ms |
45948 KB |
Output is correct |
28 |
Correct |
223 ms |
45880 KB |
Output is correct |
29 |
Correct |
211 ms |
36528 KB |
Output is correct |
30 |
Correct |
223 ms |
36584 KB |
Output is correct |
31 |
Correct |
3 ms |
4952 KB |
Output is correct |
32 |
Incorrect |
18 ms |
7496 KB |
Tree @(185697, 20413) appears more than once: for edges on positions 109 and 116 |
33 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
4948 KB |
Output is correct |
2 |
Correct |
2 ms |
4948 KB |
Output is correct |
3 |
Correct |
2 ms |
4948 KB |
Output is correct |
4 |
Correct |
2 ms |
4948 KB |
Output is correct |
5 |
Correct |
2 ms |
4948 KB |
Output is correct |
6 |
Correct |
3 ms |
4948 KB |
Output is correct |
7 |
Correct |
2 ms |
4948 KB |
Output is correct |
8 |
Correct |
2 ms |
4948 KB |
Output is correct |
9 |
Correct |
104 ms |
25472 KB |
Output is correct |
10 |
Correct |
11 ms |
7056 KB |
Output is correct |
11 |
Correct |
50 ms |
16020 KB |
Output is correct |
12 |
Correct |
16 ms |
7988 KB |
Output is correct |
13 |
Correct |
15 ms |
8844 KB |
Output is correct |
14 |
Correct |
3 ms |
5076 KB |
Output is correct |
15 |
Correct |
3 ms |
5076 KB |
Output is correct |
16 |
Correct |
114 ms |
25476 KB |
Output is correct |
17 |
Correct |
236 ms |
41868 KB |
Output is correct |
18 |
Correct |
223 ms |
41908 KB |
Output is correct |
19 |
Incorrect |
224 ms |
41256 KB |
Tree @(100001, 50003) appears more than once: for edges on positions 199994 and 199995 |
20 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
4948 KB |
Output is correct |
2 |
Correct |
2 ms |
4948 KB |
Output is correct |
3 |
Correct |
2 ms |
4948 KB |
Output is correct |
4 |
Correct |
2 ms |
4948 KB |
Output is correct |
5 |
Correct |
2 ms |
4948 KB |
Output is correct |
6 |
Correct |
3 ms |
4948 KB |
Output is correct |
7 |
Correct |
2 ms |
4948 KB |
Output is correct |
8 |
Correct |
2 ms |
4948 KB |
Output is correct |
9 |
Correct |
104 ms |
25472 KB |
Output is correct |
10 |
Correct |
11 ms |
7056 KB |
Output is correct |
11 |
Correct |
50 ms |
16020 KB |
Output is correct |
12 |
Correct |
16 ms |
7988 KB |
Output is correct |
13 |
Correct |
15 ms |
8844 KB |
Output is correct |
14 |
Correct |
3 ms |
5076 KB |
Output is correct |
15 |
Correct |
3 ms |
5076 KB |
Output is correct |
16 |
Correct |
114 ms |
25476 KB |
Output is correct |
17 |
Correct |
2 ms |
4948 KB |
Output is correct |
18 |
Correct |
2 ms |
4948 KB |
Output is correct |
19 |
Correct |
2 ms |
4948 KB |
Output is correct |
20 |
Correct |
2 ms |
4948 KB |
Output is correct |
21 |
Correct |
3 ms |
4948 KB |
Output is correct |
22 |
Correct |
3 ms |
4948 KB |
Output is correct |
23 |
Correct |
313 ms |
59468 KB |
Output is correct |
24 |
Correct |
3 ms |
4948 KB |
Output is correct |
25 |
Correct |
4 ms |
5332 KB |
Output is correct |
26 |
Correct |
3 ms |
5332 KB |
Output is correct |
27 |
Correct |
4 ms |
5384 KB |
Output is correct |
28 |
Correct |
119 ms |
26332 KB |
Output is correct |
29 |
Correct |
196 ms |
37304 KB |
Output is correct |
30 |
Correct |
228 ms |
47756 KB |
Output is correct |
31 |
Correct |
292 ms |
59464 KB |
Output is correct |
32 |
Correct |
2 ms |
4948 KB |
Output is correct |
33 |
Correct |
3 ms |
4948 KB |
Output is correct |
34 |
Correct |
3 ms |
4948 KB |
Output is correct |
35 |
Correct |
2 ms |
4884 KB |
Output is correct |
36 |
Correct |
3 ms |
4948 KB |
Output is correct |
37 |
Correct |
3 ms |
4948 KB |
Output is correct |
38 |
Correct |
3 ms |
4948 KB |
Output is correct |
39 |
Correct |
2 ms |
4948 KB |
Output is correct |
40 |
Correct |
2 ms |
4948 KB |
Output is correct |
41 |
Correct |
2 ms |
4948 KB |
Output is correct |
42 |
Correct |
2 ms |
4960 KB |
Output is correct |
43 |
Correct |
3 ms |
5076 KB |
Output is correct |
44 |
Correct |
3 ms |
5204 KB |
Output is correct |
45 |
Correct |
108 ms |
23984 KB |
Output is correct |
46 |
Correct |
166 ms |
33192 KB |
Output is correct |
47 |
Correct |
166 ms |
33236 KB |
Output is correct |
48 |
Correct |
3 ms |
4948 KB |
Output is correct |
49 |
Correct |
3 ms |
4948 KB |
Output is correct |
50 |
Correct |
2 ms |
4948 KB |
Output is correct |
51 |
Incorrect |
2 ms |
4948 KB |
Tree @(5, 5) appears more than once: for edges on positions 4 and 5 |
52 |
Halted |
0 ms |
0 KB |
- |