#include "parks.h"
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef vector<vi> vii;
typedef pair<int,int> pi;
typedef vector<pi> pii;
typedef tuple<int,int,int> tii;
#define REP(i,a,b) for(int i=a;i<b;i++)
#define F first
#define S second
#define PB push_back
#define MP make_pair
#define LSOne(s) ((s)&(-s))
ll INF=1e18+10;
int inf=1e9+10;
ll M=1e9+7;
map<pi,pi> p;
map<pi,int> s,num,used;
pi parent(pi x){
if(p[x]==x)return x;
return p[x]=parent(p[x]);
}
void join(pi x,pi y){
x=parent(x);
y=parent(y);
if(x==y)return;
if(s[x]<s[y])swap(x,y);
s[x]+=s[y];
p[y]=x;
}
int construct_roads(std::vector<int> x, std::vector<int> y) {
int n=x.size();
int mx=0;
REP(i,0,n)mx=max(mx,x[i]);
if(mx==2){
pii a;
REP(i,0,n)a.PB({y[i],i});
sort(a.begin(),a.end());
vii ans(4);
REP(i,0,n-1){
if(a[i].F+2!=a[i+1].F)return 0;
ans[0].PB(a[i].S);
ans[1].PB(a[i+1].S);
ans[2].PB(3);
ans[3].PB(a[i].F+1);
}
build(ans[0],ans[1],ans[2],ans[3]);
return 1;
}
if(mx==4){
REP(i,0,n)s[{x[i],y[i]}]=1;
REP(i,0,n)p[{x[i],y[i]}]={x[i],y[i]};
REP(i,0,n)num[{x[i],y[i]}]=i;
vii ans(4);
REP(i,2,5){
REP(j,2,200001){
if(j<200000&&s[{i,j}]>0&&s[{i,j+2}]>0){
join({i,j},{i,j+2});
ans[0].PB(num[{i,j}]);
ans[1].PB(num[{i,j+2}]);
if(i==2)ans[2].PB(i-1);
else ans[2].PB(i+1);
ans[3].PB(j+1);
}
if(i==2&&s[{i,j}]>0&&s[{i+2,j}]>0){
join({i,j},{i+2,j});
ans[0].PB(num[{i,j}]);
ans[1].PB(num[{i+2,j}]);
ans[2].PB(i+1);
ans[3].PB(j-1);
}
j++;
}
i++;
}
pi t=parent({x[0],y[0]});
bool flag=1;
REP(i,0,n)if(parent({x[i],y[i]})!=t)flag=0;
if(flag){
build(ans[0],ans[1],ans[2],ans[3]);
return 1;
}
return 0;
}
if(mx==6){
REP(i,0,n)s[{x[i],y[i]}]=1;
REP(i,0,n)p[{x[i],y[i]}]={x[i],y[i]};
REP(i,0,n)num[{x[i],y[i]}]=i;
vii ans(4);
REP(i,2,7){
REP(j,2,200000){
if(s[{i,j}]>0&&s[{i,j+2}]>0){
join({i,j},{i,j+2});
ans[0].PB(num[{i,j}]);
ans[1].PB(num[{i,j+2}]);
if(i==2)ans[2].PB(i-1);
else if(i==6)ans[2].PB(i+1);
else if(i==4){
if((j/2)%2==0)ans[2].PB(i+1);
else ans[2].PB(i-1);
}
ans[3].PB(j+1);
used[{ans[2].back(),ans[3].back()}]=1;
}
j++;
}
i++;
}
REP(i,2,5){
REP(j,2,200001){
if(s[{i,j}]>0&&s[{i+2,j}]>0&&parent({i,j})!=parent({i+2,j})){
if(used[{i+1,j-1}]==1&&used[{i+1,j+1}])return 0;
join({i,j},{i+2,j});
ans[0].PB(num[{i,j}]);
ans[1].PB(num[{i+2,j}]);
if(used[{i+1,j-1}]==1){
ans[2].PB(i+1);
ans[3].PB(j+1);
}
else{
ans[2].PB(i+1);
ans[3].PB(j-1);
}
}
j++;
}
i++;
}
pi t=parent({x[0],y[0]});
bool flag=1;
REP(i,0,n)if(parent({x[i],y[i]})!=t)flag=0;
if(flag){
build(ans[0],ans[1],ans[2],ans[3]);
return 1;
}
return 0;
}
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
0 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 |
0 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 |
30 ms |
8296 KB |
Output is correct |
10 |
Correct |
3 ms |
1292 KB |
Output is correct |
11 |
Correct |
13 ms |
4512 KB |
Output is correct |
12 |
Correct |
4 ms |
1508 KB |
Output is correct |
13 |
Correct |
5 ms |
2004 KB |
Output is correct |
14 |
Correct |
0 ms |
348 KB |
Output is correct |
15 |
Correct |
0 ms |
348 KB |
Output is correct |
16 |
Correct |
30 ms |
8216 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
0 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 |
0 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 |
30 ms |
8296 KB |
Output is correct |
10 |
Correct |
3 ms |
1292 KB |
Output is correct |
11 |
Correct |
13 ms |
4512 KB |
Output is correct |
12 |
Correct |
4 ms |
1508 KB |
Output is correct |
13 |
Correct |
5 ms |
2004 KB |
Output is correct |
14 |
Correct |
0 ms |
348 KB |
Output is correct |
15 |
Correct |
0 ms |
348 KB |
Output is correct |
16 |
Correct |
30 ms |
8216 KB |
Output is correct |
17 |
Correct |
37 ms |
12904 KB |
Output is correct |
18 |
Correct |
35 ms |
12892 KB |
Output is correct |
19 |
Correct |
34 ms |
12736 KB |
Output is correct |
20 |
Correct |
37 ms |
12884 KB |
Output is correct |
21 |
Correct |
40 ms |
12884 KB |
Output is correct |
22 |
Correct |
35 ms |
12880 KB |
Output is correct |
23 |
Correct |
621 ms |
55200 KB |
Output is correct |
24 |
Correct |
47 ms |
12884 KB |
Output is correct |
25 |
Correct |
42 ms |
13136 KB |
Output is correct |
26 |
Correct |
41 ms |
13340 KB |
Output is correct |
27 |
Correct |
41 ms |
13396 KB |
Output is correct |
28 |
Correct |
224 ms |
29884 KB |
Output is correct |
29 |
Correct |
348 ms |
38316 KB |
Output is correct |
30 |
Correct |
498 ms |
46648 KB |
Output is correct |
31 |
Correct |
594 ms |
55324 KB |
Output is correct |
32 |
Correct |
36 ms |
12884 KB |
Output is correct |
33 |
Correct |
37 ms |
12892 KB |
Output is correct |
34 |
Correct |
39 ms |
12880 KB |
Output is correct |
35 |
Correct |
40 ms |
12880 KB |
Output is correct |
36 |
Correct |
35 ms |
12888 KB |
Output is correct |
37 |
Correct |
36 ms |
12720 KB |
Output is correct |
38 |
Correct |
34 ms |
12888 KB |
Output is correct |
39 |
Correct |
47 ms |
12884 KB |
Output is correct |
40 |
Correct |
36 ms |
12884 KB |
Output is correct |
41 |
Correct |
37 ms |
12756 KB |
Output is correct |
42 |
Correct |
36 ms |
12864 KB |
Output is correct |
43 |
Correct |
43 ms |
12996 KB |
Output is correct |
44 |
Correct |
41 ms |
13372 KB |
Output is correct |
45 |
Correct |
293 ms |
31668 KB |
Output is correct |
46 |
Correct |
425 ms |
40100 KB |
Output is correct |
47 |
Correct |
402 ms |
40104 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
0 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 |
0 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 |
30 ms |
8296 KB |
Output is correct |
10 |
Correct |
3 ms |
1292 KB |
Output is correct |
11 |
Correct |
13 ms |
4512 KB |
Output is correct |
12 |
Correct |
4 ms |
1508 KB |
Output is correct |
13 |
Correct |
5 ms |
2004 KB |
Output is correct |
14 |
Correct |
0 ms |
348 KB |
Output is correct |
15 |
Correct |
0 ms |
348 KB |
Output is correct |
16 |
Correct |
30 ms |
8216 KB |
Output is correct |
17 |
Correct |
37 ms |
12904 KB |
Output is correct |
18 |
Correct |
35 ms |
12892 KB |
Output is correct |
19 |
Correct |
34 ms |
12736 KB |
Output is correct |
20 |
Correct |
37 ms |
12884 KB |
Output is correct |
21 |
Correct |
40 ms |
12884 KB |
Output is correct |
22 |
Correct |
35 ms |
12880 KB |
Output is correct |
23 |
Correct |
621 ms |
55200 KB |
Output is correct |
24 |
Correct |
47 ms |
12884 KB |
Output is correct |
25 |
Correct |
42 ms |
13136 KB |
Output is correct |
26 |
Correct |
41 ms |
13340 KB |
Output is correct |
27 |
Correct |
41 ms |
13396 KB |
Output is correct |
28 |
Correct |
224 ms |
29884 KB |
Output is correct |
29 |
Correct |
348 ms |
38316 KB |
Output is correct |
30 |
Correct |
498 ms |
46648 KB |
Output is correct |
31 |
Correct |
594 ms |
55324 KB |
Output is correct |
32 |
Correct |
36 ms |
12884 KB |
Output is correct |
33 |
Correct |
37 ms |
12892 KB |
Output is correct |
34 |
Correct |
39 ms |
12880 KB |
Output is correct |
35 |
Correct |
40 ms |
12880 KB |
Output is correct |
36 |
Correct |
35 ms |
12888 KB |
Output is correct |
37 |
Correct |
36 ms |
12720 KB |
Output is correct |
38 |
Correct |
34 ms |
12888 KB |
Output is correct |
39 |
Correct |
47 ms |
12884 KB |
Output is correct |
40 |
Correct |
36 ms |
12884 KB |
Output is correct |
41 |
Correct |
37 ms |
12756 KB |
Output is correct |
42 |
Correct |
36 ms |
12864 KB |
Output is correct |
43 |
Correct |
43 ms |
12996 KB |
Output is correct |
44 |
Correct |
41 ms |
13372 KB |
Output is correct |
45 |
Correct |
293 ms |
31668 KB |
Output is correct |
46 |
Correct |
425 ms |
40100 KB |
Output is correct |
47 |
Correct |
402 ms |
40104 KB |
Output is correct |
48 |
Correct |
66 ms |
19024 KB |
Output is correct |
49 |
Correct |
57 ms |
19064 KB |
Output is correct |
50 |
Correct |
58 ms |
19028 KB |
Output is correct |
51 |
Correct |
66 ms |
19200 KB |
Output is correct |
52 |
Correct |
64 ms |
19040 KB |
Output is correct |
53 |
Correct |
61 ms |
19100 KB |
Output is correct |
54 |
Correct |
59 ms |
19052 KB |
Output is correct |
55 |
Correct |
731 ms |
70824 KB |
Output is correct |
56 |
Correct |
61 ms |
19028 KB |
Output is correct |
57 |
Correct |
65 ms |
19536 KB |
Output is correct |
58 |
Correct |
83 ms |
20816 KB |
Output is correct |
59 |
Correct |
77 ms |
21328 KB |
Output is correct |
60 |
Correct |
329 ms |
44980 KB |
Output is correct |
61 |
Correct |
448 ms |
53924 KB |
Output is correct |
62 |
Correct |
588 ms |
61968 KB |
Output is correct |
63 |
Correct |
700 ms |
70856 KB |
Output is correct |
64 |
Correct |
59 ms |
19024 KB |
Output is correct |
65 |
Correct |
62 ms |
19024 KB |
Output is correct |
66 |
Correct |
59 ms |
19024 KB |
Output is correct |
67 |
Correct |
606 ms |
70824 KB |
Output is correct |
68 |
Correct |
618 ms |
70880 KB |
Output is correct |
69 |
Correct |
612 ms |
70572 KB |
Output is correct |
70 |
Correct |
66 ms |
20052 KB |
Output is correct |
71 |
Correct |
73 ms |
20876 KB |
Output is correct |
72 |
Correct |
329 ms |
44980 KB |
Output is correct |
73 |
Correct |
528 ms |
58020 KB |
Output is correct |
74 |
Correct |
740 ms |
70960 KB |
Output is correct |
75 |
Correct |
641 ms |
70788 KB |
Output is correct |
76 |
Correct |
603 ms |
70820 KB |
Output is correct |
77 |
Correct |
78 ms |
20180 KB |
Output is correct |
78 |
Correct |
89 ms |
21216 KB |
Output is correct |
79 |
Correct |
333 ms |
44980 KB |
Output is correct |
80 |
Correct |
520 ms |
58004 KB |
Output is correct |
81 |
Correct |
694 ms |
70784 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
0 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 |
0 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 |
30 ms |
8296 KB |
Output is correct |
10 |
Correct |
3 ms |
1292 KB |
Output is correct |
11 |
Correct |
13 ms |
4512 KB |
Output is correct |
12 |
Correct |
4 ms |
1508 KB |
Output is correct |
13 |
Correct |
5 ms |
2004 KB |
Output is correct |
14 |
Correct |
0 ms |
348 KB |
Output is correct |
15 |
Correct |
0 ms |
348 KB |
Output is correct |
16 |
Correct |
30 ms |
8216 KB |
Output is correct |
17 |
Incorrect |
1 ms |
348 KB |
Solution announced impossible, but it is possible. |
18 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
0 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 |
0 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 |
30 ms |
8296 KB |
Output is correct |
10 |
Correct |
3 ms |
1292 KB |
Output is correct |
11 |
Correct |
13 ms |
4512 KB |
Output is correct |
12 |
Correct |
4 ms |
1508 KB |
Output is correct |
13 |
Correct |
5 ms |
2004 KB |
Output is correct |
14 |
Correct |
0 ms |
348 KB |
Output is correct |
15 |
Correct |
0 ms |
348 KB |
Output is correct |
16 |
Correct |
30 ms |
8216 KB |
Output is correct |
17 |
Incorrect |
19 ms |
3420 KB |
Solution announced impossible, but it is possible. |
18 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
0 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 |
0 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 |
30 ms |
8296 KB |
Output is correct |
10 |
Correct |
3 ms |
1292 KB |
Output is correct |
11 |
Correct |
13 ms |
4512 KB |
Output is correct |
12 |
Correct |
4 ms |
1508 KB |
Output is correct |
13 |
Correct |
5 ms |
2004 KB |
Output is correct |
14 |
Correct |
0 ms |
348 KB |
Output is correct |
15 |
Correct |
0 ms |
348 KB |
Output is correct |
16 |
Correct |
30 ms |
8216 KB |
Output is correct |
17 |
Correct |
37 ms |
12904 KB |
Output is correct |
18 |
Correct |
35 ms |
12892 KB |
Output is correct |
19 |
Correct |
34 ms |
12736 KB |
Output is correct |
20 |
Correct |
37 ms |
12884 KB |
Output is correct |
21 |
Correct |
40 ms |
12884 KB |
Output is correct |
22 |
Correct |
35 ms |
12880 KB |
Output is correct |
23 |
Correct |
621 ms |
55200 KB |
Output is correct |
24 |
Correct |
47 ms |
12884 KB |
Output is correct |
25 |
Correct |
42 ms |
13136 KB |
Output is correct |
26 |
Correct |
41 ms |
13340 KB |
Output is correct |
27 |
Correct |
41 ms |
13396 KB |
Output is correct |
28 |
Correct |
224 ms |
29884 KB |
Output is correct |
29 |
Correct |
348 ms |
38316 KB |
Output is correct |
30 |
Correct |
498 ms |
46648 KB |
Output is correct |
31 |
Correct |
594 ms |
55324 KB |
Output is correct |
32 |
Correct |
36 ms |
12884 KB |
Output is correct |
33 |
Correct |
37 ms |
12892 KB |
Output is correct |
34 |
Correct |
39 ms |
12880 KB |
Output is correct |
35 |
Correct |
40 ms |
12880 KB |
Output is correct |
36 |
Correct |
35 ms |
12888 KB |
Output is correct |
37 |
Correct |
36 ms |
12720 KB |
Output is correct |
38 |
Correct |
34 ms |
12888 KB |
Output is correct |
39 |
Correct |
47 ms |
12884 KB |
Output is correct |
40 |
Correct |
36 ms |
12884 KB |
Output is correct |
41 |
Correct |
37 ms |
12756 KB |
Output is correct |
42 |
Correct |
36 ms |
12864 KB |
Output is correct |
43 |
Correct |
43 ms |
12996 KB |
Output is correct |
44 |
Correct |
41 ms |
13372 KB |
Output is correct |
45 |
Correct |
293 ms |
31668 KB |
Output is correct |
46 |
Correct |
425 ms |
40100 KB |
Output is correct |
47 |
Correct |
402 ms |
40104 KB |
Output is correct |
48 |
Correct |
66 ms |
19024 KB |
Output is correct |
49 |
Correct |
57 ms |
19064 KB |
Output is correct |
50 |
Correct |
58 ms |
19028 KB |
Output is correct |
51 |
Correct |
66 ms |
19200 KB |
Output is correct |
52 |
Correct |
64 ms |
19040 KB |
Output is correct |
53 |
Correct |
61 ms |
19100 KB |
Output is correct |
54 |
Correct |
59 ms |
19052 KB |
Output is correct |
55 |
Correct |
731 ms |
70824 KB |
Output is correct |
56 |
Correct |
61 ms |
19028 KB |
Output is correct |
57 |
Correct |
65 ms |
19536 KB |
Output is correct |
58 |
Correct |
83 ms |
20816 KB |
Output is correct |
59 |
Correct |
77 ms |
21328 KB |
Output is correct |
60 |
Correct |
329 ms |
44980 KB |
Output is correct |
61 |
Correct |
448 ms |
53924 KB |
Output is correct |
62 |
Correct |
588 ms |
61968 KB |
Output is correct |
63 |
Correct |
700 ms |
70856 KB |
Output is correct |
64 |
Correct |
59 ms |
19024 KB |
Output is correct |
65 |
Correct |
62 ms |
19024 KB |
Output is correct |
66 |
Correct |
59 ms |
19024 KB |
Output is correct |
67 |
Correct |
606 ms |
70824 KB |
Output is correct |
68 |
Correct |
618 ms |
70880 KB |
Output is correct |
69 |
Correct |
612 ms |
70572 KB |
Output is correct |
70 |
Correct |
66 ms |
20052 KB |
Output is correct |
71 |
Correct |
73 ms |
20876 KB |
Output is correct |
72 |
Correct |
329 ms |
44980 KB |
Output is correct |
73 |
Correct |
528 ms |
58020 KB |
Output is correct |
74 |
Correct |
740 ms |
70960 KB |
Output is correct |
75 |
Correct |
641 ms |
70788 KB |
Output is correct |
76 |
Correct |
603 ms |
70820 KB |
Output is correct |
77 |
Correct |
78 ms |
20180 KB |
Output is correct |
78 |
Correct |
89 ms |
21216 KB |
Output is correct |
79 |
Correct |
333 ms |
44980 KB |
Output is correct |
80 |
Correct |
520 ms |
58004 KB |
Output is correct |
81 |
Correct |
694 ms |
70784 KB |
Output is correct |
82 |
Incorrect |
1 ms |
348 KB |
Solution announced impossible, but it is possible. |
83 |
Halted |
0 ms |
0 KB |
- |