#include "parks.h"
#include<bits/stdc++.h>
using namespace std;
bitset<200100> have[7];
int at[7][200100];
int construct1(int row) {
vector<int>u,v,x,y;
int prev = 0;
for(int i = 2; i <= 200000; i+=2) {
if(have[row][i]) {
if(prev) {
if(i-prev>2)
return 0;
u.push_back(at[row][i]);
v.push_back(at[row][i-2]);
x.push_back(row+1);
y.push_back(i-1);
}
prev = i;
}
}
build(u,v,x,y);
return 1;
}
int p[200100];
int abp(int n) {
if(p[n]==n) return n;
return p[n]=abp(p[n]);
}
int n;
int construct2(int row1, int row2) {
int prev1 = 0, prev2 = 0;
vector<pair<pair<int, int>, pair<int, int>>> edges;
for(int i = 2; i <= 200000; i+=2) {
if(have[row2][i]&&i>2){
if(have[row2][i-2])
edges.push_back({{at[row2][i], at[row2][i-2]}, {row2+1, i-1}});
}
if(have[row1][i]) {
if(i>2) {
if(have[row1][i-2])
edges.push_back({{at[row1][i], at[row1][i-2]}, {row1-1, i-1}});
}
if(have[row2][i])
edges.push_back({{at[row1][i], at[row2][i]}, {row1+1, i-1}});
}
}
iota(p,p+200100,0);
vector<int> u,v,x,y;
for(auto i: edges)
u.push_back(i.first.first), v.push_back(i.first.second),x.push_back(i.second.first),y.push_back(i.second.second);
int cnt = 0;
for(int i = 0; i < edges.size(); i++)
if(abp(u[i])!=abp(v[i]))
p[p[u[i]]]=p[v[i]],cnt++;
if(cnt!=n-1) return 0;
build(u,v,x,y);
return 1;
}
int construct_roads(vector<int> x, vector<int> y) {
n = x.size();
for(int i = 0; i < n; i++)
have[x[i]][y[i]] = 1,at[x[i]][y[i]]=i;
int a = have[2].count(), b = have[4].count(), c = have[6].count();
if(!a&&!b) return construct1(6);
if(!a&&!c) return construct1(4);
if(!c&&!b) return construct1(2);
if(!b) return 0;
if(!c) return construct2(2,4);
if(!a) return construct2(4,6);
vector<pair<pair<int, int>, pair<int, int>>> edges,edges2;
bool app=0;
for(int i = 2; i <= 200000; i+=2) {
if(have[6][i]&&have[6][i-2])
edges.push_back({{at[6][i-2],at[6][i]}, {7,i-1}});
if(have[4][i]){
if(have[6][i])
edges.push_back({{at[4][i], at[6][i]}, {5, i+(app?1:-1)}}),app=1;
if(have[4][i-2])
edges2.push_back({{at[4][i], at[4][i-2]}, {3, i-1}});
}
if(have[2][i]) {
if(have[2][i-2])
edges.push_back({{at[2][i], at[2][i-2]}, {1, i-1}});
if(have[4][i])
edges.push_back({{at[2][i], at[4][i]}, {3, i+(app?1:-1)}}),app=1;
}
}
for(auto i: edges2)
edges.push_back(i);
iota(p,p+200100,0);
vector<int> u,v,X,Y;
int cnt = 0;
for(int i = 0; i < edges.size(); i++)
if(abp(edges[i].first.first)!=abp(edges[i].first.second)){
p[p[edges[i].first.first]]=p[edges[i].first.second],cnt++,
u.push_back(edges[i].first.first), v.push_back(edges[i].first.second),
X.push_back(edges[i].second.first), Y.push_back(edges[i].second.second);
if(have[X.back()][Y.back()]) {
X.back()+=2;
}
have[X.back()][Y.back()]=1;
}
if(u.size()!=n-1) return 0;
build(u,v,X,Y);
return 1;
}
Compilation message
parks.cpp: In function 'int construct2(int, int)':
parks.cpp:53:22: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<std::pair<int, int>, std::pair<int, int> > >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
53 | for(int i = 0; i < edges.size(); i++)
| ~~^~~~~~~~~~~~~~
parks.cpp:32:9: warning: unused variable 'prev1' [-Wunused-variable]
32 | int prev1 = 0, prev2 = 0;
| ^~~~~
parks.cpp:32:20: warning: unused variable 'prev2' [-Wunused-variable]
32 | int prev1 = 0, prev2 = 0;
| ^~~~~
parks.cpp: In function 'int construct_roads(std::vector<int>, std::vector<int>)':
parks.cpp:94:22: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<std::pair<int, int>, std::pair<int, int> > >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
94 | for(int i = 0; i < edges.size(); i++)
| ~~^~~~~~~~~~~~~~
parks.cpp:104:16: warning: comparison of integer expressions of different signedness: 'std::vector<int>::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
104 | if(u.size()!=n-1) return 0;
| ~~~~~~~~^~~~~
# |
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 |
1 ms |
212 KB |
Output is correct |
5 |
Correct |
0 ms |
212 KB |
Output is correct |
6 |
Correct |
0 ms |
212 KB |
Output is correct |
7 |
Correct |
0 ms |
212 KB |
Output is correct |
8 |
Correct |
1 ms |
212 KB |
Output is correct |
9 |
Correct |
46 ms |
7540 KB |
Output is correct |
10 |
Correct |
4 ms |
1236 KB |
Output is correct |
11 |
Correct |
21 ms |
4172 KB |
Output is correct |
12 |
Correct |
6 ms |
1620 KB |
Output is correct |
13 |
Correct |
7 ms |
2132 KB |
Output is correct |
14 |
Correct |
1 ms |
340 KB |
Output is correct |
15 |
Correct |
1 ms |
340 KB |
Output is correct |
16 |
Correct |
46 ms |
7476 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 |
1 ms |
212 KB |
Output is correct |
5 |
Correct |
0 ms |
212 KB |
Output is correct |
6 |
Correct |
0 ms |
212 KB |
Output is correct |
7 |
Correct |
0 ms |
212 KB |
Output is correct |
8 |
Correct |
1 ms |
212 KB |
Output is correct |
9 |
Correct |
46 ms |
7540 KB |
Output is correct |
10 |
Correct |
4 ms |
1236 KB |
Output is correct |
11 |
Correct |
21 ms |
4172 KB |
Output is correct |
12 |
Correct |
6 ms |
1620 KB |
Output is correct |
13 |
Correct |
7 ms |
2132 KB |
Output is correct |
14 |
Correct |
1 ms |
340 KB |
Output is correct |
15 |
Correct |
1 ms |
340 KB |
Output is correct |
16 |
Correct |
46 ms |
7476 KB |
Output is correct |
17 |
Correct |
1 ms |
1108 KB |
Output is correct |
18 |
Correct |
1 ms |
1108 KB |
Output is correct |
19 |
Correct |
1 ms |
1112 KB |
Output is correct |
20 |
Correct |
1 ms |
1108 KB |
Output is correct |
21 |
Correct |
1 ms |
1108 KB |
Output is correct |
22 |
Correct |
1 ms |
1108 KB |
Output is correct |
23 |
Correct |
117 ms |
27444 KB |
Output is correct |
24 |
Correct |
1 ms |
1108 KB |
Output is correct |
25 |
Correct |
2 ms |
1236 KB |
Output is correct |
26 |
Correct |
2 ms |
1364 KB |
Output is correct |
27 |
Correct |
2 ms |
1492 KB |
Output is correct |
28 |
Correct |
45 ms |
10564 KB |
Output is correct |
29 |
Correct |
76 ms |
16204 KB |
Output is correct |
30 |
Correct |
91 ms |
20220 KB |
Output is correct |
31 |
Correct |
115 ms |
27440 KB |
Output is correct |
32 |
Correct |
1 ms |
212 KB |
Output is correct |
33 |
Correct |
1 ms |
1108 KB |
Output is correct |
34 |
Correct |
1 ms |
1108 KB |
Output is correct |
35 |
Correct |
1 ms |
1108 KB |
Output is correct |
36 |
Correct |
1 ms |
1108 KB |
Output is correct |
37 |
Correct |
1 ms |
1108 KB |
Output is correct |
38 |
Correct |
1 ms |
1108 KB |
Output is correct |
39 |
Correct |
1 ms |
1008 KB |
Output is correct |
40 |
Correct |
1 ms |
1108 KB |
Output is correct |
41 |
Correct |
1 ms |
1108 KB |
Output is correct |
42 |
Correct |
1 ms |
1108 KB |
Output is correct |
43 |
Correct |
1 ms |
1236 KB |
Output is correct |
44 |
Correct |
2 ms |
1364 KB |
Output is correct |
45 |
Correct |
42 ms |
10436 KB |
Output is correct |
46 |
Correct |
74 ms |
15396 KB |
Output is correct |
47 |
Correct |
75 ms |
15416 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 |
1 ms |
212 KB |
Output is correct |
5 |
Correct |
0 ms |
212 KB |
Output is correct |
6 |
Correct |
0 ms |
212 KB |
Output is correct |
7 |
Correct |
0 ms |
212 KB |
Output is correct |
8 |
Correct |
1 ms |
212 KB |
Output is correct |
9 |
Correct |
46 ms |
7540 KB |
Output is correct |
10 |
Correct |
4 ms |
1236 KB |
Output is correct |
11 |
Correct |
21 ms |
4172 KB |
Output is correct |
12 |
Correct |
6 ms |
1620 KB |
Output is correct |
13 |
Correct |
7 ms |
2132 KB |
Output is correct |
14 |
Correct |
1 ms |
340 KB |
Output is correct |
15 |
Correct |
1 ms |
340 KB |
Output is correct |
16 |
Correct |
46 ms |
7476 KB |
Output is correct |
17 |
Correct |
1 ms |
1108 KB |
Output is correct |
18 |
Correct |
1 ms |
1108 KB |
Output is correct |
19 |
Correct |
1 ms |
1112 KB |
Output is correct |
20 |
Correct |
1 ms |
1108 KB |
Output is correct |
21 |
Correct |
1 ms |
1108 KB |
Output is correct |
22 |
Correct |
1 ms |
1108 KB |
Output is correct |
23 |
Correct |
117 ms |
27444 KB |
Output is correct |
24 |
Correct |
1 ms |
1108 KB |
Output is correct |
25 |
Correct |
2 ms |
1236 KB |
Output is correct |
26 |
Correct |
2 ms |
1364 KB |
Output is correct |
27 |
Correct |
2 ms |
1492 KB |
Output is correct |
28 |
Correct |
45 ms |
10564 KB |
Output is correct |
29 |
Correct |
76 ms |
16204 KB |
Output is correct |
30 |
Correct |
91 ms |
20220 KB |
Output is correct |
31 |
Correct |
115 ms |
27440 KB |
Output is correct |
32 |
Correct |
1 ms |
212 KB |
Output is correct |
33 |
Correct |
1 ms |
1108 KB |
Output is correct |
34 |
Correct |
1 ms |
1108 KB |
Output is correct |
35 |
Correct |
1 ms |
1108 KB |
Output is correct |
36 |
Correct |
1 ms |
1108 KB |
Output is correct |
37 |
Correct |
1 ms |
1108 KB |
Output is correct |
38 |
Correct |
1 ms |
1108 KB |
Output is correct |
39 |
Correct |
1 ms |
1008 KB |
Output is correct |
40 |
Correct |
1 ms |
1108 KB |
Output is correct |
41 |
Correct |
1 ms |
1108 KB |
Output is correct |
42 |
Correct |
1 ms |
1108 KB |
Output is correct |
43 |
Correct |
1 ms |
1236 KB |
Output is correct |
44 |
Correct |
2 ms |
1364 KB |
Output is correct |
45 |
Correct |
42 ms |
10436 KB |
Output is correct |
46 |
Correct |
74 ms |
15396 KB |
Output is correct |
47 |
Correct |
75 ms |
15416 KB |
Output is correct |
48 |
Correct |
1 ms |
1108 KB |
Output is correct |
49 |
Correct |
1 ms |
1108 KB |
Output is correct |
50 |
Correct |
1 ms |
1108 KB |
Output is correct |
51 |
Correct |
1 ms |
1108 KB |
Output is correct |
52 |
Correct |
2 ms |
1108 KB |
Output is correct |
53 |
Correct |
1 ms |
1108 KB |
Output is correct |
54 |
Correct |
1 ms |
1108 KB |
Output is correct |
55 |
Runtime error |
55 ms |
28600 KB |
Execution killed with signal 11 |
56 |
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 |
1 ms |
212 KB |
Output is correct |
5 |
Correct |
0 ms |
212 KB |
Output is correct |
6 |
Correct |
0 ms |
212 KB |
Output is correct |
7 |
Correct |
0 ms |
212 KB |
Output is correct |
8 |
Correct |
1 ms |
212 KB |
Output is correct |
9 |
Correct |
46 ms |
7540 KB |
Output is correct |
10 |
Correct |
4 ms |
1236 KB |
Output is correct |
11 |
Correct |
21 ms |
4172 KB |
Output is correct |
12 |
Correct |
6 ms |
1620 KB |
Output is correct |
13 |
Correct |
7 ms |
2132 KB |
Output is correct |
14 |
Correct |
1 ms |
340 KB |
Output is correct |
15 |
Correct |
1 ms |
340 KB |
Output is correct |
16 |
Correct |
46 ms |
7476 KB |
Output is correct |
17 |
Runtime error |
1 ms |
340 KB |
Execution killed with signal 11 |
18 |
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 |
1 ms |
212 KB |
Output is correct |
5 |
Correct |
0 ms |
212 KB |
Output is correct |
6 |
Correct |
0 ms |
212 KB |
Output is correct |
7 |
Correct |
0 ms |
212 KB |
Output is correct |
8 |
Correct |
1 ms |
212 KB |
Output is correct |
9 |
Correct |
46 ms |
7540 KB |
Output is correct |
10 |
Correct |
4 ms |
1236 KB |
Output is correct |
11 |
Correct |
21 ms |
4172 KB |
Output is correct |
12 |
Correct |
6 ms |
1620 KB |
Output is correct |
13 |
Correct |
7 ms |
2132 KB |
Output is correct |
14 |
Correct |
1 ms |
340 KB |
Output is correct |
15 |
Correct |
1 ms |
340 KB |
Output is correct |
16 |
Correct |
46 ms |
7476 KB |
Output is correct |
17 |
Runtime error |
31 ms |
6748 KB |
Execution killed with signal 11 |
18 |
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 |
1 ms |
212 KB |
Output is correct |
5 |
Correct |
0 ms |
212 KB |
Output is correct |
6 |
Correct |
0 ms |
212 KB |
Output is correct |
7 |
Correct |
0 ms |
212 KB |
Output is correct |
8 |
Correct |
1 ms |
212 KB |
Output is correct |
9 |
Correct |
46 ms |
7540 KB |
Output is correct |
10 |
Correct |
4 ms |
1236 KB |
Output is correct |
11 |
Correct |
21 ms |
4172 KB |
Output is correct |
12 |
Correct |
6 ms |
1620 KB |
Output is correct |
13 |
Correct |
7 ms |
2132 KB |
Output is correct |
14 |
Correct |
1 ms |
340 KB |
Output is correct |
15 |
Correct |
1 ms |
340 KB |
Output is correct |
16 |
Correct |
46 ms |
7476 KB |
Output is correct |
17 |
Correct |
1 ms |
1108 KB |
Output is correct |
18 |
Correct |
1 ms |
1108 KB |
Output is correct |
19 |
Correct |
1 ms |
1112 KB |
Output is correct |
20 |
Correct |
1 ms |
1108 KB |
Output is correct |
21 |
Correct |
1 ms |
1108 KB |
Output is correct |
22 |
Correct |
1 ms |
1108 KB |
Output is correct |
23 |
Correct |
117 ms |
27444 KB |
Output is correct |
24 |
Correct |
1 ms |
1108 KB |
Output is correct |
25 |
Correct |
2 ms |
1236 KB |
Output is correct |
26 |
Correct |
2 ms |
1364 KB |
Output is correct |
27 |
Correct |
2 ms |
1492 KB |
Output is correct |
28 |
Correct |
45 ms |
10564 KB |
Output is correct |
29 |
Correct |
76 ms |
16204 KB |
Output is correct |
30 |
Correct |
91 ms |
20220 KB |
Output is correct |
31 |
Correct |
115 ms |
27440 KB |
Output is correct |
32 |
Correct |
1 ms |
212 KB |
Output is correct |
33 |
Correct |
1 ms |
1108 KB |
Output is correct |
34 |
Correct |
1 ms |
1108 KB |
Output is correct |
35 |
Correct |
1 ms |
1108 KB |
Output is correct |
36 |
Correct |
1 ms |
1108 KB |
Output is correct |
37 |
Correct |
1 ms |
1108 KB |
Output is correct |
38 |
Correct |
1 ms |
1108 KB |
Output is correct |
39 |
Correct |
1 ms |
1008 KB |
Output is correct |
40 |
Correct |
1 ms |
1108 KB |
Output is correct |
41 |
Correct |
1 ms |
1108 KB |
Output is correct |
42 |
Correct |
1 ms |
1108 KB |
Output is correct |
43 |
Correct |
1 ms |
1236 KB |
Output is correct |
44 |
Correct |
2 ms |
1364 KB |
Output is correct |
45 |
Correct |
42 ms |
10436 KB |
Output is correct |
46 |
Correct |
74 ms |
15396 KB |
Output is correct |
47 |
Correct |
75 ms |
15416 KB |
Output is correct |
48 |
Correct |
1 ms |
1108 KB |
Output is correct |
49 |
Correct |
1 ms |
1108 KB |
Output is correct |
50 |
Correct |
1 ms |
1108 KB |
Output is correct |
51 |
Correct |
1 ms |
1108 KB |
Output is correct |
52 |
Correct |
2 ms |
1108 KB |
Output is correct |
53 |
Correct |
1 ms |
1108 KB |
Output is correct |
54 |
Correct |
1 ms |
1108 KB |
Output is correct |
55 |
Runtime error |
55 ms |
28600 KB |
Execution killed with signal 11 |
56 |
Halted |
0 ms |
0 KB |
- |