#include <bits/stdc++.h>
#include "parks.h"
using namespace std;
#define endl '\n'
#define st first
#define nd second
#define pb push_back
#define sz(x) (int)(x).size()
#define all(x) (x).begin(), (x).end()
#define ll long long
ll mod=1000000007;
int inf=1000000007;
ll infl=1000000000000000007;
const int N=200007;
map<int,int>id[N];
map<int,int>id1[N];
vector<int>G[3*N];
bool odw[3*N];
int Pair[3*N];
int r[N];
int Find(int v)
{
if(r[v]==v) return v;
return r[v]=Find(r[v]);
}
void Union(int u,int v)
{
r[u]=v;
}
int dx[4]={2,-2,0,0};
int dy[4]={0,0,2,-2};
void edge(int u,int v)
{
G[u].pb(v);
G[v].pb(u);
}
bool match(int v)
{
if(odw[v]) return 0;
odw[v]=1;
for(auto u:G[v])
{
if(!Pair[u]&&!odw[u])
{
Pair[u]=v;
Pair[v]=u;
return 1;
}
}
for(auto u:G[v])
{
if(!odw[u]&&match(Pair[u]))
{
Pair[u]=v;
Pair[v]=u;
return 1;
}
}
return 0;
}
/*
void build(vector<int>u,vector<int>v,vector<int>a,vector<int>b)
{
for(int i=0;i<sz(u);i++)
{
cout<<u[i]<<" "<<v[i]<<" "<<a[i]<<" "<<b[i]<<endl;
}
}
*/
int construct_roads(vector<int>x,vector<int>y)
{
int n=sz(x);
for(int i=0;i<n;i++)
{
id[x[i]][y[i]]=i+1;
r[i+1]=i+1;
}
int cnt=0,it=n-1;
vector<int>U,V,A,B;
vector<pair<int,int>>Q;
for(int i=0;i<n;i++)
{
for(int j=0;j<4;j++)
{
int nx=x[i]+dx[j],ny=y[i]+dy[j];
if(id[nx][ny]>0&&Find(id[nx][ny])!=Find(i+1))
{
cnt++;
U.pb(id[nx][ny]-1);
V.pb(i);
Union(Find(id[nx][ny]),Find(i+1));
int X=min(x[i],x[id[nx][ny]-1]),Y=min(y[i],y[id[nx][ny]-1]);
if(x[i]==x[id[nx][ny]-1])
{
if(id1[X+1][Y+1]==0)
{
id1[X+1][Y+1]=++it;
Q.pb({X+1,Y+1});
}
if(id1[X-1][Y+1]==0)
{
id1[X-1][Y+1]=++it;
Q.pb({X-1,Y+1});
}
edge(id1[X+1][Y+1],cnt);
edge(id1[X-1][Y+1],cnt);
}
else
{
if(id1[X+1][Y+1]==0)
{
id1[X+1][Y+1]=++it;
Q.pb({X+1,Y+1});
}
if(id1[X+1][Y-1]==0)
{
id1[X+1][Y-1]=++it;
Q.pb({X+1,Y-1});
}
edge(id1[X+1][Y+1],cnt);
edge(id1[X+1][Y-1],cnt);
}
}
}
}
if(cnt!=n-1) return 0;
while(true)
{
memset(odw,0,sizeof odw);
bool xd=0;
for(int i=1;i<=it;i++) if(!Pair[i]) xd|=match(i);
if(!xd) break;
}
for(int i=1;i<=n-1;i++)
{
A.pb(Q[Pair[i]-n].st);
B.pb(Q[Pair[i]-n].nd);
// if(Pair[i]==0) return 2137;
}
build(U,V,A,B);
return 1;
}
/*
int main()
{
construct_roads({2, 2, 4, 4}, {2, 4, 2, 4});
return 0;
}
*/
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
16 ms |
33740 KB |
Output is correct |
2 |
Correct |
16 ms |
33740 KB |
Output is correct |
3 |
Correct |
20 ms |
33160 KB |
Output is correct |
4 |
Correct |
18 ms |
33696 KB |
Output is correct |
5 |
Correct |
18 ms |
33784 KB |
Output is correct |
6 |
Correct |
16 ms |
33068 KB |
Output is correct |
7 |
Correct |
16 ms |
33080 KB |
Output is correct |
8 |
Correct |
17 ms |
33180 KB |
Output is correct |
9 |
Correct |
571 ms |
76648 KB |
Output is correct |
10 |
Correct |
39 ms |
38088 KB |
Output is correct |
11 |
Correct |
179 ms |
56776 KB |
Output is correct |
12 |
Correct |
54 ms |
40196 KB |
Output is correct |
13 |
Correct |
121 ms |
49688 KB |
Output is correct |
14 |
Correct |
20 ms |
33492 KB |
Output is correct |
15 |
Correct |
23 ms |
33908 KB |
Output is correct |
16 |
Correct |
553 ms |
76596 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
16 ms |
33740 KB |
Output is correct |
2 |
Correct |
16 ms |
33740 KB |
Output is correct |
3 |
Correct |
20 ms |
33160 KB |
Output is correct |
4 |
Correct |
18 ms |
33696 KB |
Output is correct |
5 |
Correct |
18 ms |
33784 KB |
Output is correct |
6 |
Correct |
16 ms |
33068 KB |
Output is correct |
7 |
Correct |
16 ms |
33080 KB |
Output is correct |
8 |
Correct |
17 ms |
33180 KB |
Output is correct |
9 |
Correct |
571 ms |
76648 KB |
Output is correct |
10 |
Correct |
39 ms |
38088 KB |
Output is correct |
11 |
Correct |
179 ms |
56776 KB |
Output is correct |
12 |
Correct |
54 ms |
40196 KB |
Output is correct |
13 |
Correct |
121 ms |
49688 KB |
Output is correct |
14 |
Correct |
20 ms |
33492 KB |
Output is correct |
15 |
Correct |
23 ms |
33908 KB |
Output is correct |
16 |
Correct |
553 ms |
76596 KB |
Output is correct |
17 |
Correct |
17 ms |
33748 KB |
Output is correct |
18 |
Correct |
17 ms |
33736 KB |
Output is correct |
19 |
Correct |
18 ms |
33680 KB |
Output is correct |
20 |
Correct |
17 ms |
33748 KB |
Output is correct |
21 |
Correct |
19 ms |
33104 KB |
Output is correct |
22 |
Correct |
17 ms |
33752 KB |
Output is correct |
23 |
Correct |
1315 ms |
94992 KB |
Output is correct |
24 |
Correct |
19 ms |
33748 KB |
Output is correct |
25 |
Correct |
22 ms |
34152 KB |
Output is correct |
26 |
Correct |
25 ms |
33876 KB |
Output is correct |
27 |
Correct |
28 ms |
34220 KB |
Output is correct |
28 |
Correct |
407 ms |
58332 KB |
Output is correct |
29 |
Correct |
769 ms |
70636 KB |
Output is correct |
30 |
Correct |
989 ms |
82376 KB |
Output is correct |
31 |
Correct |
1370 ms |
94948 KB |
Output is correct |
32 |
Correct |
19 ms |
33748 KB |
Output is correct |
33 |
Correct |
18 ms |
33748 KB |
Output is correct |
34 |
Correct |
16 ms |
33748 KB |
Output is correct |
35 |
Correct |
17 ms |
33160 KB |
Output is correct |
36 |
Correct |
17 ms |
33064 KB |
Output is correct |
37 |
Correct |
17 ms |
33696 KB |
Output is correct |
38 |
Correct |
17 ms |
33748 KB |
Output is correct |
39 |
Correct |
19 ms |
33664 KB |
Output is correct |
40 |
Correct |
18 ms |
33776 KB |
Output is correct |
41 |
Correct |
18 ms |
33172 KB |
Output is correct |
42 |
Correct |
18 ms |
33696 KB |
Output is correct |
43 |
Correct |
22 ms |
33704 KB |
Output is correct |
44 |
Correct |
26 ms |
34004 KB |
Output is correct |
45 |
Correct |
680 ms |
68328 KB |
Output is correct |
46 |
Correct |
943 ms |
83628 KB |
Output is correct |
47 |
Correct |
931 ms |
83464 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
16 ms |
33740 KB |
Output is correct |
2 |
Correct |
16 ms |
33740 KB |
Output is correct |
3 |
Correct |
20 ms |
33160 KB |
Output is correct |
4 |
Correct |
18 ms |
33696 KB |
Output is correct |
5 |
Correct |
18 ms |
33784 KB |
Output is correct |
6 |
Correct |
16 ms |
33068 KB |
Output is correct |
7 |
Correct |
16 ms |
33080 KB |
Output is correct |
8 |
Correct |
17 ms |
33180 KB |
Output is correct |
9 |
Correct |
571 ms |
76648 KB |
Output is correct |
10 |
Correct |
39 ms |
38088 KB |
Output is correct |
11 |
Correct |
179 ms |
56776 KB |
Output is correct |
12 |
Correct |
54 ms |
40196 KB |
Output is correct |
13 |
Correct |
121 ms |
49688 KB |
Output is correct |
14 |
Correct |
20 ms |
33492 KB |
Output is correct |
15 |
Correct |
23 ms |
33908 KB |
Output is correct |
16 |
Correct |
553 ms |
76596 KB |
Output is correct |
17 |
Correct |
17 ms |
33748 KB |
Output is correct |
18 |
Correct |
17 ms |
33736 KB |
Output is correct |
19 |
Correct |
18 ms |
33680 KB |
Output is correct |
20 |
Correct |
17 ms |
33748 KB |
Output is correct |
21 |
Correct |
19 ms |
33104 KB |
Output is correct |
22 |
Correct |
17 ms |
33752 KB |
Output is correct |
23 |
Correct |
1315 ms |
94992 KB |
Output is correct |
24 |
Correct |
19 ms |
33748 KB |
Output is correct |
25 |
Correct |
22 ms |
34152 KB |
Output is correct |
26 |
Correct |
25 ms |
33876 KB |
Output is correct |
27 |
Correct |
28 ms |
34220 KB |
Output is correct |
28 |
Correct |
407 ms |
58332 KB |
Output is correct |
29 |
Correct |
769 ms |
70636 KB |
Output is correct |
30 |
Correct |
989 ms |
82376 KB |
Output is correct |
31 |
Correct |
1370 ms |
94948 KB |
Output is correct |
32 |
Correct |
19 ms |
33748 KB |
Output is correct |
33 |
Correct |
18 ms |
33748 KB |
Output is correct |
34 |
Correct |
16 ms |
33748 KB |
Output is correct |
35 |
Correct |
17 ms |
33160 KB |
Output is correct |
36 |
Correct |
17 ms |
33064 KB |
Output is correct |
37 |
Correct |
17 ms |
33696 KB |
Output is correct |
38 |
Correct |
17 ms |
33748 KB |
Output is correct |
39 |
Correct |
19 ms |
33664 KB |
Output is correct |
40 |
Correct |
18 ms |
33776 KB |
Output is correct |
41 |
Correct |
18 ms |
33172 KB |
Output is correct |
42 |
Correct |
18 ms |
33696 KB |
Output is correct |
43 |
Correct |
22 ms |
33704 KB |
Output is correct |
44 |
Correct |
26 ms |
34004 KB |
Output is correct |
45 |
Correct |
680 ms |
68328 KB |
Output is correct |
46 |
Correct |
943 ms |
83628 KB |
Output is correct |
47 |
Correct |
931 ms |
83464 KB |
Output is correct |
48 |
Correct |
17 ms |
33748 KB |
Output is correct |
49 |
Correct |
17 ms |
33748 KB |
Output is correct |
50 |
Correct |
17 ms |
33676 KB |
Output is correct |
51 |
Correct |
18 ms |
33688 KB |
Output is correct |
52 |
Correct |
17 ms |
33640 KB |
Output is correct |
53 |
Correct |
17 ms |
33756 KB |
Output is correct |
54 |
Correct |
18 ms |
33700 KB |
Output is correct |
55 |
Runtime error |
1242 ms |
164072 KB |
Execution killed with signal 11 |
56 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
16 ms |
33740 KB |
Output is correct |
2 |
Correct |
16 ms |
33740 KB |
Output is correct |
3 |
Correct |
20 ms |
33160 KB |
Output is correct |
4 |
Correct |
18 ms |
33696 KB |
Output is correct |
5 |
Correct |
18 ms |
33784 KB |
Output is correct |
6 |
Correct |
16 ms |
33068 KB |
Output is correct |
7 |
Correct |
16 ms |
33080 KB |
Output is correct |
8 |
Correct |
17 ms |
33180 KB |
Output is correct |
9 |
Correct |
571 ms |
76648 KB |
Output is correct |
10 |
Correct |
39 ms |
38088 KB |
Output is correct |
11 |
Correct |
179 ms |
56776 KB |
Output is correct |
12 |
Correct |
54 ms |
40196 KB |
Output is correct |
13 |
Correct |
121 ms |
49688 KB |
Output is correct |
14 |
Correct |
20 ms |
33492 KB |
Output is correct |
15 |
Correct |
23 ms |
33908 KB |
Output is correct |
16 |
Correct |
553 ms |
76596 KB |
Output is correct |
17 |
Correct |
17 ms |
33748 KB |
Output is correct |
18 |
Correct |
17 ms |
33684 KB |
Output is correct |
19 |
Correct |
16 ms |
33124 KB |
Output is correct |
20 |
Correct |
744 ms |
109252 KB |
Output is correct |
21 |
Correct |
661 ms |
101668 KB |
Output is correct |
22 |
Correct |
783 ms |
101480 KB |
Output is correct |
23 |
Correct |
652 ms |
105920 KB |
Output is correct |
24 |
Correct |
482 ms |
65568 KB |
Output is correct |
25 |
Correct |
990 ms |
98308 KB |
Output is correct |
26 |
Correct |
886 ms |
98388 KB |
Output is correct |
27 |
Correct |
1016 ms |
109676 KB |
Output is correct |
28 |
Correct |
1025 ms |
109788 KB |
Output is correct |
29 |
Correct |
1095 ms |
109688 KB |
Output is correct |
30 |
Correct |
1014 ms |
109780 KB |
Output is correct |
31 |
Correct |
17 ms |
33748 KB |
Output is correct |
32 |
Correct |
57 ms |
38476 KB |
Output is correct |
33 |
Correct |
120 ms |
49432 KB |
Output is correct |
34 |
Correct |
596 ms |
109432 KB |
Output is correct |
35 |
Correct |
43 ms |
35784 KB |
Output is correct |
36 |
Correct |
153 ms |
45516 KB |
Output is correct |
37 |
Correct |
345 ms |
57528 KB |
Output is correct |
38 |
Correct |
355 ms |
57820 KB |
Output is correct |
39 |
Correct |
526 ms |
66920 KB |
Output is correct |
40 |
Correct |
688 ms |
76316 KB |
Output is correct |
41 |
Correct |
872 ms |
84472 KB |
Output is correct |
42 |
Correct |
1042 ms |
94008 KB |
Output is correct |
43 |
Correct |
18 ms |
33748 KB |
Output is correct |
44 |
Correct |
17 ms |
33784 KB |
Output is correct |
45 |
Correct |
17 ms |
33748 KB |
Output is correct |
46 |
Correct |
18 ms |
33228 KB |
Output is correct |
47 |
Correct |
17 ms |
33108 KB |
Output is correct |
48 |
Correct |
18 ms |
33740 KB |
Output is correct |
49 |
Correct |
17 ms |
33692 KB |
Output is correct |
50 |
Correct |
17 ms |
33692 KB |
Output is correct |
51 |
Correct |
16 ms |
33748 KB |
Output is correct |
52 |
Correct |
16 ms |
33188 KB |
Output is correct |
53 |
Correct |
17 ms |
33748 KB |
Output is correct |
54 |
Correct |
22 ms |
33712 KB |
Output is correct |
55 |
Correct |
24 ms |
34004 KB |
Output is correct |
56 |
Correct |
574 ms |
68432 KB |
Output is correct |
57 |
Correct |
949 ms |
83504 KB |
Output is correct |
58 |
Correct |
964 ms |
83616 KB |
Output is correct |
59 |
Correct |
17 ms |
33164 KB |
Output is correct |
60 |
Correct |
18 ms |
33696 KB |
Output is correct |
61 |
Correct |
17 ms |
33108 KB |
Output is correct |
62 |
Correct |
1265 ms |
114464 KB |
Output is correct |
63 |
Correct |
1229 ms |
114396 KB |
Output is correct |
64 |
Correct |
1257 ms |
114084 KB |
Output is correct |
65 |
Correct |
29 ms |
34300 KB |
Output is correct |
66 |
Correct |
40 ms |
35352 KB |
Output is correct |
67 |
Correct |
594 ms |
66860 KB |
Output is correct |
68 |
Correct |
945 ms |
83152 KB |
Output is correct |
69 |
Correct |
1345 ms |
99900 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
16 ms |
33740 KB |
Output is correct |
2 |
Correct |
16 ms |
33740 KB |
Output is correct |
3 |
Correct |
20 ms |
33160 KB |
Output is correct |
4 |
Correct |
18 ms |
33696 KB |
Output is correct |
5 |
Correct |
18 ms |
33784 KB |
Output is correct |
6 |
Correct |
16 ms |
33068 KB |
Output is correct |
7 |
Correct |
16 ms |
33080 KB |
Output is correct |
8 |
Correct |
17 ms |
33180 KB |
Output is correct |
9 |
Correct |
571 ms |
76648 KB |
Output is correct |
10 |
Correct |
39 ms |
38088 KB |
Output is correct |
11 |
Correct |
179 ms |
56776 KB |
Output is correct |
12 |
Correct |
54 ms |
40196 KB |
Output is correct |
13 |
Correct |
121 ms |
49688 KB |
Output is correct |
14 |
Correct |
20 ms |
33492 KB |
Output is correct |
15 |
Correct |
23 ms |
33908 KB |
Output is correct |
16 |
Correct |
553 ms |
76596 KB |
Output is correct |
17 |
Correct |
887 ms |
119024 KB |
Output is correct |
18 |
Correct |
909 ms |
119220 KB |
Output is correct |
19 |
Correct |
806 ms |
104612 KB |
Output is correct |
20 |
Correct |
1002 ms |
88948 KB |
Output is correct |
21 |
Correct |
1014 ms |
97656 KB |
Output is correct |
22 |
Correct |
18 ms |
33756 KB |
Output is correct |
23 |
Correct |
115 ms |
43880 KB |
Output is correct |
24 |
Correct |
59 ms |
38040 KB |
Output is correct |
25 |
Correct |
248 ms |
49932 KB |
Output is correct |
26 |
Correct |
443 ms |
61984 KB |
Output is correct |
27 |
Correct |
418 ms |
63460 KB |
Output is correct |
28 |
Correct |
617 ms |
70920 KB |
Output is correct |
29 |
Correct |
712 ms |
77992 KB |
Output is correct |
30 |
Correct |
900 ms |
85488 KB |
Output is correct |
31 |
Correct |
1107 ms |
92836 KB |
Output is correct |
32 |
Correct |
1303 ms |
100304 KB |
Output is correct |
33 |
Correct |
1275 ms |
114544 KB |
Output is correct |
34 |
Correct |
30 ms |
34532 KB |
Output is correct |
35 |
Correct |
41 ms |
35680 KB |
Output is correct |
36 |
Correct |
606 ms |
66676 KB |
Output is correct |
37 |
Correct |
961 ms |
82512 KB |
Output is correct |
38 |
Correct |
1340 ms |
99364 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
16 ms |
33740 KB |
Output is correct |
2 |
Correct |
16 ms |
33740 KB |
Output is correct |
3 |
Correct |
20 ms |
33160 KB |
Output is correct |
4 |
Correct |
18 ms |
33696 KB |
Output is correct |
5 |
Correct |
18 ms |
33784 KB |
Output is correct |
6 |
Correct |
16 ms |
33068 KB |
Output is correct |
7 |
Correct |
16 ms |
33080 KB |
Output is correct |
8 |
Correct |
17 ms |
33180 KB |
Output is correct |
9 |
Correct |
571 ms |
76648 KB |
Output is correct |
10 |
Correct |
39 ms |
38088 KB |
Output is correct |
11 |
Correct |
179 ms |
56776 KB |
Output is correct |
12 |
Correct |
54 ms |
40196 KB |
Output is correct |
13 |
Correct |
121 ms |
49688 KB |
Output is correct |
14 |
Correct |
20 ms |
33492 KB |
Output is correct |
15 |
Correct |
23 ms |
33908 KB |
Output is correct |
16 |
Correct |
553 ms |
76596 KB |
Output is correct |
17 |
Correct |
17 ms |
33748 KB |
Output is correct |
18 |
Correct |
17 ms |
33736 KB |
Output is correct |
19 |
Correct |
18 ms |
33680 KB |
Output is correct |
20 |
Correct |
17 ms |
33748 KB |
Output is correct |
21 |
Correct |
19 ms |
33104 KB |
Output is correct |
22 |
Correct |
17 ms |
33752 KB |
Output is correct |
23 |
Correct |
1315 ms |
94992 KB |
Output is correct |
24 |
Correct |
19 ms |
33748 KB |
Output is correct |
25 |
Correct |
22 ms |
34152 KB |
Output is correct |
26 |
Correct |
25 ms |
33876 KB |
Output is correct |
27 |
Correct |
28 ms |
34220 KB |
Output is correct |
28 |
Correct |
407 ms |
58332 KB |
Output is correct |
29 |
Correct |
769 ms |
70636 KB |
Output is correct |
30 |
Correct |
989 ms |
82376 KB |
Output is correct |
31 |
Correct |
1370 ms |
94948 KB |
Output is correct |
32 |
Correct |
19 ms |
33748 KB |
Output is correct |
33 |
Correct |
18 ms |
33748 KB |
Output is correct |
34 |
Correct |
16 ms |
33748 KB |
Output is correct |
35 |
Correct |
17 ms |
33160 KB |
Output is correct |
36 |
Correct |
17 ms |
33064 KB |
Output is correct |
37 |
Correct |
17 ms |
33696 KB |
Output is correct |
38 |
Correct |
17 ms |
33748 KB |
Output is correct |
39 |
Correct |
19 ms |
33664 KB |
Output is correct |
40 |
Correct |
18 ms |
33776 KB |
Output is correct |
41 |
Correct |
18 ms |
33172 KB |
Output is correct |
42 |
Correct |
18 ms |
33696 KB |
Output is correct |
43 |
Correct |
22 ms |
33704 KB |
Output is correct |
44 |
Correct |
26 ms |
34004 KB |
Output is correct |
45 |
Correct |
680 ms |
68328 KB |
Output is correct |
46 |
Correct |
943 ms |
83628 KB |
Output is correct |
47 |
Correct |
931 ms |
83464 KB |
Output is correct |
48 |
Correct |
17 ms |
33748 KB |
Output is correct |
49 |
Correct |
17 ms |
33748 KB |
Output is correct |
50 |
Correct |
17 ms |
33676 KB |
Output is correct |
51 |
Correct |
18 ms |
33688 KB |
Output is correct |
52 |
Correct |
17 ms |
33640 KB |
Output is correct |
53 |
Correct |
17 ms |
33756 KB |
Output is correct |
54 |
Correct |
18 ms |
33700 KB |
Output is correct |
55 |
Runtime error |
1242 ms |
164072 KB |
Execution killed with signal 11 |
56 |
Halted |
0 ms |
0 KB |
- |