#include<bits/stdc++.h>
#include "parks.h"
#define MAXN 200007
using namespace std;
struct bench{
int from,to;
int a,b;
};
int L,M,R;
int n,dsu[MAXN],up[MAXN],down[MAXN],curr;
vector< pair<int,int> > l,m,r;
vector<bench> sol;
vector<int> A,B,C,D;
int root(int x){
if(dsu[x]==x)return x;
dsu[x]=root(dsu[x]);
return dsu[x];
}
void mergev(int x,int y){
dsu[root(x)]=root(y);
}
int construct_roads(vector<int> x,vector<int> y){
n=int(x.size());
for(int i=0;i<n;i++){
dsu[i]=i;
if(x[i]==2){
l.push_back({y[i],i});
down[y[i]]=i+1;
}
if(x[i]==4)m.push_back({y[i],i});
if(x[i]==6){
r.push_back({y[i],i});
up[y[i]]=i+1;
}
}
sort(l.begin(),l.end());
sort(m.begin(),m.end());
sort(r.begin(),r.end());
L=int(l.size()); M=int(m.size()); R=int(r.size());
for(int i=0;i<L-1;i++){
if(l[i].first+2==l[i+1].first){
mergev(l[i].second,l[i+1].second);
sol.push_back({l[i].second,l[i+1].second,1,l[i].first+1});
}
}
for(int i=0;i<R-1;i++){
if(r[i].first+2==r[i+1].first){
mergev(r[i].second,r[i+1].second);
sol.push_back({r[i].second,r[i+1].second,7,r[i].first+1});
}
}
for(int i=0;i<M-1;i++){
if(m[i].first+2==m[i+1].first){
mergev(m[i].second,m[i+1].second);
if(m[i].first%4==0)sol.push_back({m[i].second,m[i+1].second,3,m[i].first+1});
if(m[i].first%4==2)sol.push_back({m[i].second,m[i+1].second,5,m[i].first+1});
}
}
for(int i=0;i<M;i++){
if(down[m[i].first]!=0){
curr=down[m[i].first]-1;
if(root(curr)==root(m[i].second))continue;
mergev(curr,m[i].second);
if(m[i].first%4==0)sol.push_back({curr,m[i].second,3,m[i].first-1});
if(m[i].first%4==2)sol.push_back({curr,m[i].second,3,m[i].first+1});
}
}
for(int i=0;i<M;i++){
if(up[m[i].first]!=0){
curr=up[m[i].first]-1;
if(root(curr)==root(m[i].second))continue;
mergev(curr,m[i].second);
if(m[i].first%4==0)sol.push_back({m[i].second,curr,5,m[i].first+1});
if(m[i].first%4==2)sol.push_back({m[i].second,curr,5,m[i].first-1});
}
}
for(int i=0;i<n;i++){
if(root(i)!=root(0))return 0;
}
for(int i=0;i<sol.size();i++){
A.push_back(sol[i].from);
B.push_back(sol[i].to);
C.push_back(sol[i].a);
D.push_back(sol[i].b);
}
build(A,B,C,D);
return 1;
}
/*
int main(){
construct_roads({4, 4, 6, 4, 2}, {4, 6, 4, 2, 4});
}
*/
Compilation message
parks.cpp: In function 'int construct_roads(std::vector<int>, std::vector<int>)':
parks.cpp:98:18: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<bench>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
98 | for(int i=0;i<sol.size();i++){
| ~^~~~~~~~~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
1 ms |
304 KB |
Output is correct |
3 |
Correct |
1 ms |
212 KB |
Output is correct |
4 |
Correct |
0 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 |
1 ms |
212 KB |
Output is correct |
8 |
Correct |
1 ms |
212 KB |
Output is correct |
9 |
Correct |
55 ms |
13708 KB |
Output is correct |
10 |
Correct |
5 ms |
1744 KB |
Output is correct |
11 |
Correct |
24 ms |
7512 KB |
Output is correct |
12 |
Correct |
8 ms |
2384 KB |
Output is correct |
13 |
Correct |
8 ms |
3404 KB |
Output is correct |
14 |
Correct |
1 ms |
340 KB |
Output is correct |
15 |
Correct |
1 ms |
468 KB |
Output is correct |
16 |
Correct |
52 ms |
13164 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
1 ms |
304 KB |
Output is correct |
3 |
Correct |
1 ms |
212 KB |
Output is correct |
4 |
Correct |
0 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 |
1 ms |
212 KB |
Output is correct |
8 |
Correct |
1 ms |
212 KB |
Output is correct |
9 |
Correct |
55 ms |
13708 KB |
Output is correct |
10 |
Correct |
5 ms |
1744 KB |
Output is correct |
11 |
Correct |
24 ms |
7512 KB |
Output is correct |
12 |
Correct |
8 ms |
2384 KB |
Output is correct |
13 |
Correct |
8 ms |
3404 KB |
Output is correct |
14 |
Correct |
1 ms |
340 KB |
Output is correct |
15 |
Correct |
1 ms |
468 KB |
Output is correct |
16 |
Correct |
52 ms |
13164 KB |
Output is correct |
17 |
Correct |
1 ms |
212 KB |
Output is correct |
18 |
Correct |
0 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 |
212 KB |
Output is correct |
22 |
Correct |
1 ms |
212 KB |
Output is correct |
23 |
Correct |
112 ms |
25512 KB |
Output is correct |
24 |
Correct |
1 ms |
212 KB |
Output is correct |
25 |
Correct |
1 ms |
468 KB |
Output is correct |
26 |
Correct |
1 ms |
468 KB |
Output is correct |
27 |
Correct |
1 ms |
576 KB |
Output is correct |
28 |
Correct |
41 ms |
10528 KB |
Output is correct |
29 |
Correct |
61 ms |
15032 KB |
Output is correct |
30 |
Correct |
87 ms |
20996 KB |
Output is correct |
31 |
Correct |
105 ms |
25484 KB |
Output is correct |
32 |
Correct |
1 ms |
212 KB |
Output is correct |
33 |
Correct |
1 ms |
212 KB |
Output is correct |
34 |
Correct |
0 ms |
308 KB |
Output is correct |
35 |
Correct |
1 ms |
212 KB |
Output is correct |
36 |
Correct |
0 ms |
304 KB |
Output is correct |
37 |
Correct |
1 ms |
340 KB |
Output is correct |
38 |
Correct |
1 ms |
212 KB |
Output is correct |
39 |
Correct |
1 ms |
212 KB |
Output is correct |
40 |
Correct |
1 ms |
212 KB |
Output is correct |
41 |
Correct |
1 ms |
212 KB |
Output is correct |
42 |
Correct |
1 ms |
212 KB |
Output is correct |
43 |
Correct |
1 ms |
468 KB |
Output is correct |
44 |
Correct |
1 ms |
572 KB |
Output is correct |
45 |
Correct |
51 ms |
12372 KB |
Output is correct |
46 |
Correct |
80 ms |
18776 KB |
Output is correct |
47 |
Correct |
76 ms |
18692 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
1 ms |
304 KB |
Output is correct |
3 |
Correct |
1 ms |
212 KB |
Output is correct |
4 |
Correct |
0 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 |
1 ms |
212 KB |
Output is correct |
8 |
Correct |
1 ms |
212 KB |
Output is correct |
9 |
Correct |
55 ms |
13708 KB |
Output is correct |
10 |
Correct |
5 ms |
1744 KB |
Output is correct |
11 |
Correct |
24 ms |
7512 KB |
Output is correct |
12 |
Correct |
8 ms |
2384 KB |
Output is correct |
13 |
Correct |
8 ms |
3404 KB |
Output is correct |
14 |
Correct |
1 ms |
340 KB |
Output is correct |
15 |
Correct |
1 ms |
468 KB |
Output is correct |
16 |
Correct |
52 ms |
13164 KB |
Output is correct |
17 |
Correct |
1 ms |
212 KB |
Output is correct |
18 |
Correct |
0 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 |
212 KB |
Output is correct |
22 |
Correct |
1 ms |
212 KB |
Output is correct |
23 |
Correct |
112 ms |
25512 KB |
Output is correct |
24 |
Correct |
1 ms |
212 KB |
Output is correct |
25 |
Correct |
1 ms |
468 KB |
Output is correct |
26 |
Correct |
1 ms |
468 KB |
Output is correct |
27 |
Correct |
1 ms |
576 KB |
Output is correct |
28 |
Correct |
41 ms |
10528 KB |
Output is correct |
29 |
Correct |
61 ms |
15032 KB |
Output is correct |
30 |
Correct |
87 ms |
20996 KB |
Output is correct |
31 |
Correct |
105 ms |
25484 KB |
Output is correct |
32 |
Correct |
1 ms |
212 KB |
Output is correct |
33 |
Correct |
1 ms |
212 KB |
Output is correct |
34 |
Correct |
0 ms |
308 KB |
Output is correct |
35 |
Correct |
1 ms |
212 KB |
Output is correct |
36 |
Correct |
0 ms |
304 KB |
Output is correct |
37 |
Correct |
1 ms |
340 KB |
Output is correct |
38 |
Correct |
1 ms |
212 KB |
Output is correct |
39 |
Correct |
1 ms |
212 KB |
Output is correct |
40 |
Correct |
1 ms |
212 KB |
Output is correct |
41 |
Correct |
1 ms |
212 KB |
Output is correct |
42 |
Correct |
1 ms |
212 KB |
Output is correct |
43 |
Correct |
1 ms |
468 KB |
Output is correct |
44 |
Correct |
1 ms |
572 KB |
Output is correct |
45 |
Correct |
51 ms |
12372 KB |
Output is correct |
46 |
Correct |
80 ms |
18776 KB |
Output is correct |
47 |
Correct |
76 ms |
18692 KB |
Output is correct |
48 |
Correct |
1 ms |
212 KB |
Output is correct |
49 |
Correct |
1 ms |
212 KB |
Output is correct |
50 |
Correct |
0 ms |
212 KB |
Output is correct |
51 |
Correct |
1 ms |
212 KB |
Output is correct |
52 |
Correct |
1 ms |
212 KB |
Output is correct |
53 |
Correct |
1 ms |
256 KB |
Output is correct |
54 |
Correct |
0 ms |
212 KB |
Output is correct |
55 |
Correct |
104 ms |
25228 KB |
Output is correct |
56 |
Correct |
1 ms |
212 KB |
Output is correct |
57 |
Correct |
1 ms |
448 KB |
Output is correct |
58 |
Correct |
3 ms |
1108 KB |
Output is correct |
59 |
Correct |
3 ms |
1108 KB |
Output is correct |
60 |
Correct |
49 ms |
12528 KB |
Output is correct |
61 |
Correct |
70 ms |
17908 KB |
Output is correct |
62 |
Correct |
90 ms |
21544 KB |
Output is correct |
63 |
Correct |
123 ms |
25360 KB |
Output is correct |
64 |
Correct |
1 ms |
212 KB |
Output is correct |
65 |
Correct |
1 ms |
212 KB |
Output is correct |
66 |
Correct |
1 ms |
212 KB |
Output is correct |
67 |
Correct |
104 ms |
25868 KB |
Output is correct |
68 |
Correct |
108 ms |
26312 KB |
Output is correct |
69 |
Correct |
103 ms |
25528 KB |
Output is correct |
70 |
Correct |
2 ms |
596 KB |
Output is correct |
71 |
Correct |
3 ms |
980 KB |
Output is correct |
72 |
Correct |
50 ms |
12448 KB |
Output is correct |
73 |
Correct |
86 ms |
19668 KB |
Output is correct |
74 |
Correct |
108 ms |
25064 KB |
Output is correct |
75 |
Correct |
105 ms |
25612 KB |
Output is correct |
76 |
Correct |
104 ms |
26240 KB |
Output is correct |
77 |
Correct |
2 ms |
724 KB |
Output is correct |
78 |
Correct |
3 ms |
1108 KB |
Output is correct |
79 |
Correct |
50 ms |
12288 KB |
Output is correct |
80 |
Correct |
90 ms |
19484 KB |
Output is correct |
81 |
Correct |
118 ms |
24916 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
1 ms |
304 KB |
Output is correct |
3 |
Correct |
1 ms |
212 KB |
Output is correct |
4 |
Correct |
0 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 |
1 ms |
212 KB |
Output is correct |
8 |
Correct |
1 ms |
212 KB |
Output is correct |
9 |
Correct |
55 ms |
13708 KB |
Output is correct |
10 |
Correct |
5 ms |
1744 KB |
Output is correct |
11 |
Correct |
24 ms |
7512 KB |
Output is correct |
12 |
Correct |
8 ms |
2384 KB |
Output is correct |
13 |
Correct |
8 ms |
3404 KB |
Output is correct |
14 |
Correct |
1 ms |
340 KB |
Output is correct |
15 |
Correct |
1 ms |
468 KB |
Output is correct |
16 |
Correct |
52 ms |
13164 KB |
Output is correct |
17 |
Incorrect |
1 ms |
212 KB |
Solution announced impossible, but it is possible. |
18 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
1 ms |
304 KB |
Output is correct |
3 |
Correct |
1 ms |
212 KB |
Output is correct |
4 |
Correct |
0 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 |
1 ms |
212 KB |
Output is correct |
8 |
Correct |
1 ms |
212 KB |
Output is correct |
9 |
Correct |
55 ms |
13708 KB |
Output is correct |
10 |
Correct |
5 ms |
1744 KB |
Output is correct |
11 |
Correct |
24 ms |
7512 KB |
Output is correct |
12 |
Correct |
8 ms |
2384 KB |
Output is correct |
13 |
Correct |
8 ms |
3404 KB |
Output is correct |
14 |
Correct |
1 ms |
340 KB |
Output is correct |
15 |
Correct |
1 ms |
468 KB |
Output is correct |
16 |
Correct |
52 ms |
13164 KB |
Output is correct |
17 |
Incorrect |
36 ms |
8508 KB |
Solution announced impossible, but it is possible. |
18 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
1 ms |
304 KB |
Output is correct |
3 |
Correct |
1 ms |
212 KB |
Output is correct |
4 |
Correct |
0 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 |
1 ms |
212 KB |
Output is correct |
8 |
Correct |
1 ms |
212 KB |
Output is correct |
9 |
Correct |
55 ms |
13708 KB |
Output is correct |
10 |
Correct |
5 ms |
1744 KB |
Output is correct |
11 |
Correct |
24 ms |
7512 KB |
Output is correct |
12 |
Correct |
8 ms |
2384 KB |
Output is correct |
13 |
Correct |
8 ms |
3404 KB |
Output is correct |
14 |
Correct |
1 ms |
340 KB |
Output is correct |
15 |
Correct |
1 ms |
468 KB |
Output is correct |
16 |
Correct |
52 ms |
13164 KB |
Output is correct |
17 |
Correct |
1 ms |
212 KB |
Output is correct |
18 |
Correct |
0 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 |
212 KB |
Output is correct |
22 |
Correct |
1 ms |
212 KB |
Output is correct |
23 |
Correct |
112 ms |
25512 KB |
Output is correct |
24 |
Correct |
1 ms |
212 KB |
Output is correct |
25 |
Correct |
1 ms |
468 KB |
Output is correct |
26 |
Correct |
1 ms |
468 KB |
Output is correct |
27 |
Correct |
1 ms |
576 KB |
Output is correct |
28 |
Correct |
41 ms |
10528 KB |
Output is correct |
29 |
Correct |
61 ms |
15032 KB |
Output is correct |
30 |
Correct |
87 ms |
20996 KB |
Output is correct |
31 |
Correct |
105 ms |
25484 KB |
Output is correct |
32 |
Correct |
1 ms |
212 KB |
Output is correct |
33 |
Correct |
1 ms |
212 KB |
Output is correct |
34 |
Correct |
0 ms |
308 KB |
Output is correct |
35 |
Correct |
1 ms |
212 KB |
Output is correct |
36 |
Correct |
0 ms |
304 KB |
Output is correct |
37 |
Correct |
1 ms |
340 KB |
Output is correct |
38 |
Correct |
1 ms |
212 KB |
Output is correct |
39 |
Correct |
1 ms |
212 KB |
Output is correct |
40 |
Correct |
1 ms |
212 KB |
Output is correct |
41 |
Correct |
1 ms |
212 KB |
Output is correct |
42 |
Correct |
1 ms |
212 KB |
Output is correct |
43 |
Correct |
1 ms |
468 KB |
Output is correct |
44 |
Correct |
1 ms |
572 KB |
Output is correct |
45 |
Correct |
51 ms |
12372 KB |
Output is correct |
46 |
Correct |
80 ms |
18776 KB |
Output is correct |
47 |
Correct |
76 ms |
18692 KB |
Output is correct |
48 |
Correct |
1 ms |
212 KB |
Output is correct |
49 |
Correct |
1 ms |
212 KB |
Output is correct |
50 |
Correct |
0 ms |
212 KB |
Output is correct |
51 |
Correct |
1 ms |
212 KB |
Output is correct |
52 |
Correct |
1 ms |
212 KB |
Output is correct |
53 |
Correct |
1 ms |
256 KB |
Output is correct |
54 |
Correct |
0 ms |
212 KB |
Output is correct |
55 |
Correct |
104 ms |
25228 KB |
Output is correct |
56 |
Correct |
1 ms |
212 KB |
Output is correct |
57 |
Correct |
1 ms |
448 KB |
Output is correct |
58 |
Correct |
3 ms |
1108 KB |
Output is correct |
59 |
Correct |
3 ms |
1108 KB |
Output is correct |
60 |
Correct |
49 ms |
12528 KB |
Output is correct |
61 |
Correct |
70 ms |
17908 KB |
Output is correct |
62 |
Correct |
90 ms |
21544 KB |
Output is correct |
63 |
Correct |
123 ms |
25360 KB |
Output is correct |
64 |
Correct |
1 ms |
212 KB |
Output is correct |
65 |
Correct |
1 ms |
212 KB |
Output is correct |
66 |
Correct |
1 ms |
212 KB |
Output is correct |
67 |
Correct |
104 ms |
25868 KB |
Output is correct |
68 |
Correct |
108 ms |
26312 KB |
Output is correct |
69 |
Correct |
103 ms |
25528 KB |
Output is correct |
70 |
Correct |
2 ms |
596 KB |
Output is correct |
71 |
Correct |
3 ms |
980 KB |
Output is correct |
72 |
Correct |
50 ms |
12448 KB |
Output is correct |
73 |
Correct |
86 ms |
19668 KB |
Output is correct |
74 |
Correct |
108 ms |
25064 KB |
Output is correct |
75 |
Correct |
105 ms |
25612 KB |
Output is correct |
76 |
Correct |
104 ms |
26240 KB |
Output is correct |
77 |
Correct |
2 ms |
724 KB |
Output is correct |
78 |
Correct |
3 ms |
1108 KB |
Output is correct |
79 |
Correct |
50 ms |
12288 KB |
Output is correct |
80 |
Correct |
90 ms |
19484 KB |
Output is correct |
81 |
Correct |
118 ms |
24916 KB |
Output is correct |
82 |
Incorrect |
1 ms |
212 KB |
Solution announced impossible, but it is possible. |
83 |
Halted |
0 ms |
0 KB |
- |