#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;
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;
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;
}
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
348 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 |
8216 KB |
Output is correct |
10 |
Correct |
3 ms |
1292 KB |
Output is correct |
11 |
Correct |
13 ms |
4484 KB |
Output is correct |
12 |
Correct |
4 ms |
1508 KB |
Output is correct |
13 |
Correct |
5 ms |
2260 KB |
Output is correct |
14 |
Correct |
0 ms |
348 KB |
Output is correct |
15 |
Correct |
1 ms |
348 KB |
Output is correct |
16 |
Correct |
30 ms |
8176 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
348 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 |
8216 KB |
Output is correct |
10 |
Correct |
3 ms |
1292 KB |
Output is correct |
11 |
Correct |
13 ms |
4484 KB |
Output is correct |
12 |
Correct |
4 ms |
1508 KB |
Output is correct |
13 |
Correct |
5 ms |
2260 KB |
Output is correct |
14 |
Correct |
0 ms |
348 KB |
Output is correct |
15 |
Correct |
1 ms |
348 KB |
Output is correct |
16 |
Correct |
30 ms |
8176 KB |
Output is correct |
17 |
Correct |
36 ms |
12876 KB |
Output is correct |
18 |
Correct |
36 ms |
12880 KB |
Output is correct |
19 |
Correct |
35 ms |
12880 KB |
Output is correct |
20 |
Correct |
40 ms |
12864 KB |
Output is correct |
21 |
Correct |
47 ms |
12696 KB |
Output is correct |
22 |
Correct |
39 ms |
12880 KB |
Output is correct |
23 |
Correct |
564 ms |
55196 KB |
Output is correct |
24 |
Correct |
40 ms |
12884 KB |
Output is correct |
25 |
Correct |
41 ms |
13144 KB |
Output is correct |
26 |
Correct |
43 ms |
13392 KB |
Output is correct |
27 |
Correct |
41 ms |
13404 KB |
Output is correct |
28 |
Correct |
218 ms |
29860 KB |
Output is correct |
29 |
Correct |
327 ms |
38320 KB |
Output is correct |
30 |
Correct |
466 ms |
46628 KB |
Output is correct |
31 |
Correct |
579 ms |
55196 KB |
Output is correct |
32 |
Correct |
44 ms |
12884 KB |
Output is correct |
33 |
Correct |
35 ms |
12884 KB |
Output is correct |
34 |
Correct |
36 ms |
12884 KB |
Output is correct |
35 |
Correct |
35 ms |
12880 KB |
Output is correct |
36 |
Correct |
36 ms |
12880 KB |
Output is correct |
37 |
Correct |
35 ms |
12864 KB |
Output is correct |
38 |
Correct |
35 ms |
12888 KB |
Output is correct |
39 |
Correct |
36 ms |
12728 KB |
Output is correct |
40 |
Correct |
35 ms |
12880 KB |
Output is correct |
41 |
Correct |
36 ms |
12888 KB |
Output is correct |
42 |
Correct |
35 ms |
12736 KB |
Output is correct |
43 |
Correct |
45 ms |
13048 KB |
Output is correct |
44 |
Correct |
44 ms |
13348 KB |
Output is correct |
45 |
Correct |
248 ms |
31644 KB |
Output is correct |
46 |
Correct |
385 ms |
40132 KB |
Output is correct |
47 |
Correct |
392 ms |
40160 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
348 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 |
8216 KB |
Output is correct |
10 |
Correct |
3 ms |
1292 KB |
Output is correct |
11 |
Correct |
13 ms |
4484 KB |
Output is correct |
12 |
Correct |
4 ms |
1508 KB |
Output is correct |
13 |
Correct |
5 ms |
2260 KB |
Output is correct |
14 |
Correct |
0 ms |
348 KB |
Output is correct |
15 |
Correct |
1 ms |
348 KB |
Output is correct |
16 |
Correct |
30 ms |
8176 KB |
Output is correct |
17 |
Correct |
36 ms |
12876 KB |
Output is correct |
18 |
Correct |
36 ms |
12880 KB |
Output is correct |
19 |
Correct |
35 ms |
12880 KB |
Output is correct |
20 |
Correct |
40 ms |
12864 KB |
Output is correct |
21 |
Correct |
47 ms |
12696 KB |
Output is correct |
22 |
Correct |
39 ms |
12880 KB |
Output is correct |
23 |
Correct |
564 ms |
55196 KB |
Output is correct |
24 |
Correct |
40 ms |
12884 KB |
Output is correct |
25 |
Correct |
41 ms |
13144 KB |
Output is correct |
26 |
Correct |
43 ms |
13392 KB |
Output is correct |
27 |
Correct |
41 ms |
13404 KB |
Output is correct |
28 |
Correct |
218 ms |
29860 KB |
Output is correct |
29 |
Correct |
327 ms |
38320 KB |
Output is correct |
30 |
Correct |
466 ms |
46628 KB |
Output is correct |
31 |
Correct |
579 ms |
55196 KB |
Output is correct |
32 |
Correct |
44 ms |
12884 KB |
Output is correct |
33 |
Correct |
35 ms |
12884 KB |
Output is correct |
34 |
Correct |
36 ms |
12884 KB |
Output is correct |
35 |
Correct |
35 ms |
12880 KB |
Output is correct |
36 |
Correct |
36 ms |
12880 KB |
Output is correct |
37 |
Correct |
35 ms |
12864 KB |
Output is correct |
38 |
Correct |
35 ms |
12888 KB |
Output is correct |
39 |
Correct |
36 ms |
12728 KB |
Output is correct |
40 |
Correct |
35 ms |
12880 KB |
Output is correct |
41 |
Correct |
36 ms |
12888 KB |
Output is correct |
42 |
Correct |
35 ms |
12736 KB |
Output is correct |
43 |
Correct |
45 ms |
13048 KB |
Output is correct |
44 |
Correct |
44 ms |
13348 KB |
Output is correct |
45 |
Correct |
248 ms |
31644 KB |
Output is correct |
46 |
Correct |
385 ms |
40132 KB |
Output is correct |
47 |
Correct |
392 ms |
40160 KB |
Output is correct |
48 |
Incorrect |
0 ms |
348 KB |
Solution announced impossible, but it is possible. |
49 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
348 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 |
8216 KB |
Output is correct |
10 |
Correct |
3 ms |
1292 KB |
Output is correct |
11 |
Correct |
13 ms |
4484 KB |
Output is correct |
12 |
Correct |
4 ms |
1508 KB |
Output is correct |
13 |
Correct |
5 ms |
2260 KB |
Output is correct |
14 |
Correct |
0 ms |
348 KB |
Output is correct |
15 |
Correct |
1 ms |
348 KB |
Output is correct |
16 |
Correct |
30 ms |
8176 KB |
Output is correct |
17 |
Incorrect |
0 ms |
348 KB |
Solution announced impossible, but it is possible. |
18 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
348 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 |
8216 KB |
Output is correct |
10 |
Correct |
3 ms |
1292 KB |
Output is correct |
11 |
Correct |
13 ms |
4484 KB |
Output is correct |
12 |
Correct |
4 ms |
1508 KB |
Output is correct |
13 |
Correct |
5 ms |
2260 KB |
Output is correct |
14 |
Correct |
0 ms |
348 KB |
Output is correct |
15 |
Correct |
1 ms |
348 KB |
Output is correct |
16 |
Correct |
30 ms |
8176 KB |
Output is correct |
17 |
Incorrect |
19 ms |
3420 KB |
Solution announced impossible, but it is possible. |
18 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
348 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 |
8216 KB |
Output is correct |
10 |
Correct |
3 ms |
1292 KB |
Output is correct |
11 |
Correct |
13 ms |
4484 KB |
Output is correct |
12 |
Correct |
4 ms |
1508 KB |
Output is correct |
13 |
Correct |
5 ms |
2260 KB |
Output is correct |
14 |
Correct |
0 ms |
348 KB |
Output is correct |
15 |
Correct |
1 ms |
348 KB |
Output is correct |
16 |
Correct |
30 ms |
8176 KB |
Output is correct |
17 |
Correct |
36 ms |
12876 KB |
Output is correct |
18 |
Correct |
36 ms |
12880 KB |
Output is correct |
19 |
Correct |
35 ms |
12880 KB |
Output is correct |
20 |
Correct |
40 ms |
12864 KB |
Output is correct |
21 |
Correct |
47 ms |
12696 KB |
Output is correct |
22 |
Correct |
39 ms |
12880 KB |
Output is correct |
23 |
Correct |
564 ms |
55196 KB |
Output is correct |
24 |
Correct |
40 ms |
12884 KB |
Output is correct |
25 |
Correct |
41 ms |
13144 KB |
Output is correct |
26 |
Correct |
43 ms |
13392 KB |
Output is correct |
27 |
Correct |
41 ms |
13404 KB |
Output is correct |
28 |
Correct |
218 ms |
29860 KB |
Output is correct |
29 |
Correct |
327 ms |
38320 KB |
Output is correct |
30 |
Correct |
466 ms |
46628 KB |
Output is correct |
31 |
Correct |
579 ms |
55196 KB |
Output is correct |
32 |
Correct |
44 ms |
12884 KB |
Output is correct |
33 |
Correct |
35 ms |
12884 KB |
Output is correct |
34 |
Correct |
36 ms |
12884 KB |
Output is correct |
35 |
Correct |
35 ms |
12880 KB |
Output is correct |
36 |
Correct |
36 ms |
12880 KB |
Output is correct |
37 |
Correct |
35 ms |
12864 KB |
Output is correct |
38 |
Correct |
35 ms |
12888 KB |
Output is correct |
39 |
Correct |
36 ms |
12728 KB |
Output is correct |
40 |
Correct |
35 ms |
12880 KB |
Output is correct |
41 |
Correct |
36 ms |
12888 KB |
Output is correct |
42 |
Correct |
35 ms |
12736 KB |
Output is correct |
43 |
Correct |
45 ms |
13048 KB |
Output is correct |
44 |
Correct |
44 ms |
13348 KB |
Output is correct |
45 |
Correct |
248 ms |
31644 KB |
Output is correct |
46 |
Correct |
385 ms |
40132 KB |
Output is correct |
47 |
Correct |
392 ms |
40160 KB |
Output is correct |
48 |
Incorrect |
0 ms |
348 KB |
Solution announced impossible, but it is possible. |
49 |
Halted |
0 ms |
0 KB |
- |