#include "parks.h"
#include<bits/stdc++.h>
using namespace std;
mt19937 rng;
struct bpmatch{
vector<int>adj[200100];
int match1[200100],match2[400100],dep[200100];
void AE(int a,int b){
adj[a].push_back(b);
}
int bfs(int n){
queue<int>q;
for(int i=1;i<=n;i++)
if(!match1[i])
q.push(i),
dep[i]=1;
else dep[i]=0;
dep[0]=0;
while(q.size()){
int x=q.front();
q.pop();
if(dep[x]>=dep[0]&&dep[0])
continue;
for(auto i:adj[x])
if(!dep[match2[i]])
dep[match2[i]]=dep[x]+1,
q.push(match2[i]);
}
return dep[0];
}
int dfs(int n){
if(!n)return 1;
for(auto i:adj[n]){
if(dep[match2[i]]==dep[n]+1&&dfs(match2[i]))
return match2[match1[n]=i]=n,1;
}
dep[n]=1e9;
return 0;
}
int matching(int n){
int ans=0;
while(bfs(n))for(int i=1;i<=n;i++)
if(!match1[i]) ans+=dfs(i);
return ans;
}
} G;
map<int,int> pts[200100];
vector<pair<int,int>> tre_edges;
struct dsu{
int par[200100];
int abp(int n){
return par[n]?par[n]=abp(par[n]):n;
}
int merge(int a,int b){
a=abp(a),b=abp(b);
return a-b?par[a]=b:0;
}
} DT;
int Xpos[400100],Ypos[400100];
int construct_roads(std::vector<int> x, std::vector<int> y) {
int n=x.size();
for(int i=0;i<n;i++)
pts[x[i]][y[i]]=i+1;
vector<tuple<int,int,int>>E;
for(int i=0;i<n;i++) {
if(pts[x[i]+2][y[i]])
E.push_back({i+1,pts[x[i]+2][y[i]],0});
if(pts[x[i]][y[i]+2])
E.push_back({i+1,pts[x[i]][y[i]+2],1});
}
vector<int>u,v,A,B;
shuffle(E.begin(),E.end(),rng);
int CC=0;
for(auto [i,j,k]:E){
if(DT.merge(i,j)){
u.push_back(i-1);
v.push_back(j-1);
int x1=x[i-1]+1,y1=y[i-1]+1;
int x2=x1,y2=y1;
if(k)x2-=2;
else y2-=2;
if(!pts[x1][y1])
pts[x1][y1]=++CC,
Xpos[CC]=x1,
Ypos[CC]=y1;
if(!pts[x2][y2])
pts[x2][y2]=++CC,
Xpos[CC]=x2,
Ypos[CC]=y2;
G.AE(u.size(),pts[x1][y1]);
G.AE(u.size(),pts[x2][y2]);
}
}
if(u.size()-n+1)return 0;
if(G.matching(n-1)!=n-1)
return 0;
for(int i=1;i<n;i++)
A.push_back(Xpos[G.match1[i]]),
B.push_back(Ypos[G.match1[i]]);
build(u,v,A,B);
return 1;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
18776 KB |
Output is correct |
2 |
Correct |
2 ms |
20828 KB |
Output is correct |
3 |
Correct |
2 ms |
16732 KB |
Output is correct |
4 |
Correct |
2 ms |
20828 KB |
Output is correct |
5 |
Correct |
2 ms |
20828 KB |
Output is correct |
6 |
Correct |
2 ms |
18780 KB |
Output is correct |
7 |
Correct |
2 ms |
18780 KB |
Output is correct |
8 |
Correct |
2 ms |
18780 KB |
Output is correct |
9 |
Correct |
186 ms |
50960 KB |
Output is correct |
10 |
Correct |
15 ms |
24032 KB |
Output is correct |
11 |
Correct |
76 ms |
37096 KB |
Output is correct |
12 |
Correct |
19 ms |
25516 KB |
Output is correct |
13 |
Correct |
49 ms |
30220 KB |
Output is correct |
14 |
Correct |
3 ms |
19032 KB |
Output is correct |
15 |
Correct |
4 ms |
19292 KB |
Output is correct |
16 |
Correct |
187 ms |
50940 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
18776 KB |
Output is correct |
2 |
Correct |
2 ms |
20828 KB |
Output is correct |
3 |
Correct |
2 ms |
16732 KB |
Output is correct |
4 |
Correct |
2 ms |
20828 KB |
Output is correct |
5 |
Correct |
2 ms |
20828 KB |
Output is correct |
6 |
Correct |
2 ms |
18780 KB |
Output is correct |
7 |
Correct |
2 ms |
18780 KB |
Output is correct |
8 |
Correct |
2 ms |
18780 KB |
Output is correct |
9 |
Correct |
186 ms |
50960 KB |
Output is correct |
10 |
Correct |
15 ms |
24032 KB |
Output is correct |
11 |
Correct |
76 ms |
37096 KB |
Output is correct |
12 |
Correct |
19 ms |
25516 KB |
Output is correct |
13 |
Correct |
49 ms |
30220 KB |
Output is correct |
14 |
Correct |
3 ms |
19032 KB |
Output is correct |
15 |
Correct |
4 ms |
19292 KB |
Output is correct |
16 |
Correct |
187 ms |
50940 KB |
Output is correct |
17 |
Correct |
2 ms |
20828 KB |
Output is correct |
18 |
Correct |
2 ms |
20824 KB |
Output is correct |
19 |
Correct |
2 ms |
20828 KB |
Output is correct |
20 |
Correct |
2 ms |
20828 KB |
Output is correct |
21 |
Correct |
2 ms |
18776 KB |
Output is correct |
22 |
Correct |
2 ms |
20828 KB |
Output is correct |
23 |
Correct |
407 ms |
71084 KB |
Output is correct |
24 |
Correct |
2 ms |
20828 KB |
Output is correct |
25 |
Correct |
3 ms |
21084 KB |
Output is correct |
26 |
Correct |
5 ms |
19292 KB |
Output is correct |
27 |
Correct |
7 ms |
19656 KB |
Output is correct |
28 |
Correct |
156 ms |
40264 KB |
Output is correct |
29 |
Correct |
218 ms |
50180 KB |
Output is correct |
30 |
Correct |
312 ms |
59908 KB |
Output is correct |
31 |
Correct |
436 ms |
71248 KB |
Output is correct |
32 |
Correct |
2 ms |
20828 KB |
Output is correct |
33 |
Correct |
2 ms |
20824 KB |
Output is correct |
34 |
Correct |
2 ms |
20828 KB |
Output is correct |
35 |
Correct |
2 ms |
16732 KB |
Output is correct |
36 |
Correct |
2 ms |
16828 KB |
Output is correct |
37 |
Correct |
3 ms |
20932 KB |
Output is correct |
38 |
Correct |
2 ms |
20824 KB |
Output is correct |
39 |
Correct |
2 ms |
20912 KB |
Output is correct |
40 |
Correct |
2 ms |
20828 KB |
Output is correct |
41 |
Correct |
2 ms |
16732 KB |
Output is correct |
42 |
Correct |
2 ms |
20952 KB |
Output is correct |
43 |
Correct |
4 ms |
19312 KB |
Output is correct |
44 |
Correct |
4 ms |
19548 KB |
Output is correct |
45 |
Correct |
186 ms |
47432 KB |
Output is correct |
46 |
Correct |
291 ms |
59316 KB |
Output is correct |
47 |
Correct |
280 ms |
59360 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
18776 KB |
Output is correct |
2 |
Correct |
2 ms |
20828 KB |
Output is correct |
3 |
Correct |
2 ms |
16732 KB |
Output is correct |
4 |
Correct |
2 ms |
20828 KB |
Output is correct |
5 |
Correct |
2 ms |
20828 KB |
Output is correct |
6 |
Correct |
2 ms |
18780 KB |
Output is correct |
7 |
Correct |
2 ms |
18780 KB |
Output is correct |
8 |
Correct |
2 ms |
18780 KB |
Output is correct |
9 |
Correct |
186 ms |
50960 KB |
Output is correct |
10 |
Correct |
15 ms |
24032 KB |
Output is correct |
11 |
Correct |
76 ms |
37096 KB |
Output is correct |
12 |
Correct |
19 ms |
25516 KB |
Output is correct |
13 |
Correct |
49 ms |
30220 KB |
Output is correct |
14 |
Correct |
3 ms |
19032 KB |
Output is correct |
15 |
Correct |
4 ms |
19292 KB |
Output is correct |
16 |
Correct |
187 ms |
50940 KB |
Output is correct |
17 |
Correct |
2 ms |
20828 KB |
Output is correct |
18 |
Correct |
2 ms |
20824 KB |
Output is correct |
19 |
Correct |
2 ms |
20828 KB |
Output is correct |
20 |
Correct |
2 ms |
20828 KB |
Output is correct |
21 |
Correct |
2 ms |
18776 KB |
Output is correct |
22 |
Correct |
2 ms |
20828 KB |
Output is correct |
23 |
Correct |
407 ms |
71084 KB |
Output is correct |
24 |
Correct |
2 ms |
20828 KB |
Output is correct |
25 |
Correct |
3 ms |
21084 KB |
Output is correct |
26 |
Correct |
5 ms |
19292 KB |
Output is correct |
27 |
Correct |
7 ms |
19656 KB |
Output is correct |
28 |
Correct |
156 ms |
40264 KB |
Output is correct |
29 |
Correct |
218 ms |
50180 KB |
Output is correct |
30 |
Correct |
312 ms |
59908 KB |
Output is correct |
31 |
Correct |
436 ms |
71248 KB |
Output is correct |
32 |
Correct |
2 ms |
20828 KB |
Output is correct |
33 |
Correct |
2 ms |
20824 KB |
Output is correct |
34 |
Correct |
2 ms |
20828 KB |
Output is correct |
35 |
Correct |
2 ms |
16732 KB |
Output is correct |
36 |
Correct |
2 ms |
16828 KB |
Output is correct |
37 |
Correct |
3 ms |
20932 KB |
Output is correct |
38 |
Correct |
2 ms |
20824 KB |
Output is correct |
39 |
Correct |
2 ms |
20912 KB |
Output is correct |
40 |
Correct |
2 ms |
20828 KB |
Output is correct |
41 |
Correct |
2 ms |
16732 KB |
Output is correct |
42 |
Correct |
2 ms |
20952 KB |
Output is correct |
43 |
Correct |
4 ms |
19312 KB |
Output is correct |
44 |
Correct |
4 ms |
19548 KB |
Output is correct |
45 |
Correct |
186 ms |
47432 KB |
Output is correct |
46 |
Correct |
291 ms |
59316 KB |
Output is correct |
47 |
Correct |
280 ms |
59360 KB |
Output is correct |
48 |
Correct |
3 ms |
20828 KB |
Output is correct |
49 |
Correct |
2 ms |
20828 KB |
Output is correct |
50 |
Correct |
2 ms |
20828 KB |
Output is correct |
51 |
Correct |
2 ms |
20828 KB |
Output is correct |
52 |
Correct |
2 ms |
20928 KB |
Output is correct |
53 |
Correct |
2 ms |
20916 KB |
Output is correct |
54 |
Correct |
2 ms |
20828 KB |
Output is correct |
55 |
Incorrect |
395 ms |
60228 KB |
Solution announced impossible, but it is possible. |
56 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
18776 KB |
Output is correct |
2 |
Correct |
2 ms |
20828 KB |
Output is correct |
3 |
Correct |
2 ms |
16732 KB |
Output is correct |
4 |
Correct |
2 ms |
20828 KB |
Output is correct |
5 |
Correct |
2 ms |
20828 KB |
Output is correct |
6 |
Correct |
2 ms |
18780 KB |
Output is correct |
7 |
Correct |
2 ms |
18780 KB |
Output is correct |
8 |
Correct |
2 ms |
18780 KB |
Output is correct |
9 |
Correct |
186 ms |
50960 KB |
Output is correct |
10 |
Correct |
15 ms |
24032 KB |
Output is correct |
11 |
Correct |
76 ms |
37096 KB |
Output is correct |
12 |
Correct |
19 ms |
25516 KB |
Output is correct |
13 |
Correct |
49 ms |
30220 KB |
Output is correct |
14 |
Correct |
3 ms |
19032 KB |
Output is correct |
15 |
Correct |
4 ms |
19292 KB |
Output is correct |
16 |
Correct |
187 ms |
50940 KB |
Output is correct |
17 |
Correct |
3 ms |
20828 KB |
Output is correct |
18 |
Correct |
2 ms |
20828 KB |
Output is correct |
19 |
Correct |
2 ms |
18780 KB |
Output is correct |
20 |
Correct |
1507 ms |
69380 KB |
Output is correct |
21 |
Correct |
192 ms |
72344 KB |
Output is correct |
22 |
Correct |
1569 ms |
68360 KB |
Output is correct |
23 |
Correct |
223 ms |
71992 KB |
Output is correct |
24 |
Correct |
178 ms |
48088 KB |
Output is correct |
25 |
Correct |
305 ms |
70064 KB |
Output is correct |
26 |
Correct |
297 ms |
69888 KB |
Output is correct |
27 |
Correct |
354 ms |
81068 KB |
Output is correct |
28 |
Correct |
333 ms |
80964 KB |
Output is correct |
29 |
Correct |
344 ms |
81068 KB |
Output is correct |
30 |
Correct |
332 ms |
81172 KB |
Output is correct |
31 |
Correct |
2 ms |
20824 KB |
Output is correct |
32 |
Correct |
15 ms |
24756 KB |
Output is correct |
33 |
Correct |
31 ms |
32348 KB |
Output is correct |
34 |
Correct |
206 ms |
72696 KB |
Output is correct |
35 |
Correct |
9 ms |
20824 KB |
Output is correct |
36 |
Correct |
46 ms |
28908 KB |
Output is correct |
37 |
Correct |
106 ms |
38928 KB |
Output is correct |
38 |
Correct |
108 ms |
40676 KB |
Output is correct |
39 |
Correct |
161 ms |
48284 KB |
Output is correct |
40 |
Correct |
206 ms |
56580 KB |
Output is correct |
41 |
Correct |
270 ms |
62972 KB |
Output is correct |
42 |
Correct |
327 ms |
71472 KB |
Output is correct |
43 |
Correct |
3 ms |
20828 KB |
Output is correct |
44 |
Correct |
2 ms |
20828 KB |
Output is correct |
45 |
Correct |
2 ms |
20828 KB |
Output is correct |
46 |
Correct |
2 ms |
16732 KB |
Output is correct |
47 |
Correct |
2 ms |
16732 KB |
Output is correct |
48 |
Correct |
2 ms |
20828 KB |
Output is correct |
49 |
Correct |
2 ms |
20828 KB |
Output is correct |
50 |
Correct |
2 ms |
20828 KB |
Output is correct |
51 |
Correct |
2 ms |
20828 KB |
Output is correct |
52 |
Correct |
2 ms |
16732 KB |
Output is correct |
53 |
Correct |
2 ms |
20828 KB |
Output is correct |
54 |
Correct |
4 ms |
19292 KB |
Output is correct |
55 |
Correct |
5 ms |
19548 KB |
Output is correct |
56 |
Correct |
184 ms |
47412 KB |
Output is correct |
57 |
Correct |
299 ms |
59748 KB |
Output is correct |
58 |
Correct |
281 ms |
59360 KB |
Output is correct |
59 |
Correct |
2 ms |
16732 KB |
Output is correct |
60 |
Correct |
2 ms |
20828 KB |
Output is correct |
61 |
Correct |
2 ms |
16732 KB |
Output is correct |
62 |
Correct |
423 ms |
81412 KB |
Output is correct |
63 |
Correct |
427 ms |
81152 KB |
Output is correct |
64 |
Correct |
422 ms |
80900 KB |
Output is correct |
65 |
Correct |
6 ms |
19544 KB |
Output is correct |
66 |
Correct |
10 ms |
20476 KB |
Output is correct |
67 |
Correct |
184 ms |
46832 KB |
Output is correct |
68 |
Correct |
296 ms |
59908 KB |
Output is correct |
69 |
Correct |
418 ms |
72888 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
18776 KB |
Output is correct |
2 |
Correct |
2 ms |
20828 KB |
Output is correct |
3 |
Correct |
2 ms |
16732 KB |
Output is correct |
4 |
Correct |
2 ms |
20828 KB |
Output is correct |
5 |
Correct |
2 ms |
20828 KB |
Output is correct |
6 |
Correct |
2 ms |
18780 KB |
Output is correct |
7 |
Correct |
2 ms |
18780 KB |
Output is correct |
8 |
Correct |
2 ms |
18780 KB |
Output is correct |
9 |
Correct |
186 ms |
50960 KB |
Output is correct |
10 |
Correct |
15 ms |
24032 KB |
Output is correct |
11 |
Correct |
76 ms |
37096 KB |
Output is correct |
12 |
Correct |
19 ms |
25516 KB |
Output is correct |
13 |
Correct |
49 ms |
30220 KB |
Output is correct |
14 |
Correct |
3 ms |
19032 KB |
Output is correct |
15 |
Correct |
4 ms |
19292 KB |
Output is correct |
16 |
Correct |
187 ms |
50940 KB |
Output is correct |
17 |
Correct |
332 ms |
81664 KB |
Output is correct |
18 |
Correct |
332 ms |
81584 KB |
Output is correct |
19 |
Correct |
703 ms |
74724 KB |
Output is correct |
20 |
Correct |
308 ms |
67572 KB |
Output is correct |
21 |
Correct |
287 ms |
69092 KB |
Output is correct |
22 |
Correct |
2 ms |
20828 KB |
Output is correct |
23 |
Correct |
36 ms |
28952 KB |
Output is correct |
24 |
Correct |
22 ms |
22932 KB |
Output is correct |
25 |
Correct |
71 ms |
33032 KB |
Output is correct |
26 |
Correct |
130 ms |
42744 KB |
Output is correct |
27 |
Correct |
138 ms |
45448 KB |
Output is correct |
28 |
Correct |
198 ms |
52056 KB |
Output is correct |
29 |
Correct |
228 ms |
57908 KB |
Output is correct |
30 |
Correct |
277 ms |
64012 KB |
Output is correct |
31 |
Correct |
319 ms |
70368 KB |
Output is correct |
32 |
Correct |
423 ms |
72868 KB |
Output is correct |
33 |
Correct |
431 ms |
81060 KB |
Output is correct |
34 |
Correct |
7 ms |
19804 KB |
Output is correct |
35 |
Correct |
14 ms |
20880 KB |
Output is correct |
36 |
Correct |
177 ms |
46596 KB |
Output is correct |
37 |
Correct |
293 ms |
59944 KB |
Output is correct |
38 |
Correct |
416 ms |
72628 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
18776 KB |
Output is correct |
2 |
Correct |
2 ms |
20828 KB |
Output is correct |
3 |
Correct |
2 ms |
16732 KB |
Output is correct |
4 |
Correct |
2 ms |
20828 KB |
Output is correct |
5 |
Correct |
2 ms |
20828 KB |
Output is correct |
6 |
Correct |
2 ms |
18780 KB |
Output is correct |
7 |
Correct |
2 ms |
18780 KB |
Output is correct |
8 |
Correct |
2 ms |
18780 KB |
Output is correct |
9 |
Correct |
186 ms |
50960 KB |
Output is correct |
10 |
Correct |
15 ms |
24032 KB |
Output is correct |
11 |
Correct |
76 ms |
37096 KB |
Output is correct |
12 |
Correct |
19 ms |
25516 KB |
Output is correct |
13 |
Correct |
49 ms |
30220 KB |
Output is correct |
14 |
Correct |
3 ms |
19032 KB |
Output is correct |
15 |
Correct |
4 ms |
19292 KB |
Output is correct |
16 |
Correct |
187 ms |
50940 KB |
Output is correct |
17 |
Correct |
2 ms |
20828 KB |
Output is correct |
18 |
Correct |
2 ms |
20824 KB |
Output is correct |
19 |
Correct |
2 ms |
20828 KB |
Output is correct |
20 |
Correct |
2 ms |
20828 KB |
Output is correct |
21 |
Correct |
2 ms |
18776 KB |
Output is correct |
22 |
Correct |
2 ms |
20828 KB |
Output is correct |
23 |
Correct |
407 ms |
71084 KB |
Output is correct |
24 |
Correct |
2 ms |
20828 KB |
Output is correct |
25 |
Correct |
3 ms |
21084 KB |
Output is correct |
26 |
Correct |
5 ms |
19292 KB |
Output is correct |
27 |
Correct |
7 ms |
19656 KB |
Output is correct |
28 |
Correct |
156 ms |
40264 KB |
Output is correct |
29 |
Correct |
218 ms |
50180 KB |
Output is correct |
30 |
Correct |
312 ms |
59908 KB |
Output is correct |
31 |
Correct |
436 ms |
71248 KB |
Output is correct |
32 |
Correct |
2 ms |
20828 KB |
Output is correct |
33 |
Correct |
2 ms |
20824 KB |
Output is correct |
34 |
Correct |
2 ms |
20828 KB |
Output is correct |
35 |
Correct |
2 ms |
16732 KB |
Output is correct |
36 |
Correct |
2 ms |
16828 KB |
Output is correct |
37 |
Correct |
3 ms |
20932 KB |
Output is correct |
38 |
Correct |
2 ms |
20824 KB |
Output is correct |
39 |
Correct |
2 ms |
20912 KB |
Output is correct |
40 |
Correct |
2 ms |
20828 KB |
Output is correct |
41 |
Correct |
2 ms |
16732 KB |
Output is correct |
42 |
Correct |
2 ms |
20952 KB |
Output is correct |
43 |
Correct |
4 ms |
19312 KB |
Output is correct |
44 |
Correct |
4 ms |
19548 KB |
Output is correct |
45 |
Correct |
186 ms |
47432 KB |
Output is correct |
46 |
Correct |
291 ms |
59316 KB |
Output is correct |
47 |
Correct |
280 ms |
59360 KB |
Output is correct |
48 |
Correct |
3 ms |
20828 KB |
Output is correct |
49 |
Correct |
2 ms |
20828 KB |
Output is correct |
50 |
Correct |
2 ms |
20828 KB |
Output is correct |
51 |
Correct |
2 ms |
20828 KB |
Output is correct |
52 |
Correct |
2 ms |
20928 KB |
Output is correct |
53 |
Correct |
2 ms |
20916 KB |
Output is correct |
54 |
Correct |
2 ms |
20828 KB |
Output is correct |
55 |
Incorrect |
395 ms |
60228 KB |
Solution announced impossible, but it is possible. |
56 |
Halted |
0 ms |
0 KB |
- |