#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]);
}
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;
}
vector<int>x,y,U,V,A,B;
vector<pair<int,int>>Q;
int cnt,it;
void Union(int u,int v)
{
r[Find(u)]=Find(v);
cnt++;
U.pb(u-1);
V.pb(v-1);
int X=min(x[u-1],x[v-1]),Y=min(y[u-1],y[v-1]);
if(x[u-1]==x[v-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);
}
}
/*
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>xx,vector<int>yy)
{
x=xx;
y=yy;
int n=sz(x);
for(int i=0;i<n;i++)
{
id[x[i]][y[i]]=i+1;
r[i+1]=i+1;
}
it=n-1;
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))
{
Union(id[nx][ny],i+1);
}
}
}
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++)
{
if(Pair[i]==0) return 0;
A.pb(Q[Pair[i]-n].st);
B.pb(Q[Pair[i]-n].nd);
}
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 |
17 ms |
33748 KB |
Output is correct |
2 |
Correct |
17 ms |
33748 KB |
Output is correct |
3 |
Correct |
17 ms |
33108 KB |
Output is correct |
4 |
Correct |
16 ms |
33704 KB |
Output is correct |
5 |
Correct |
16 ms |
33672 KB |
Output is correct |
6 |
Correct |
16 ms |
33108 KB |
Output is correct |
7 |
Correct |
15 ms |
33152 KB |
Output is correct |
8 |
Correct |
16 ms |
33072 KB |
Output is correct |
9 |
Correct |
540 ms |
78604 KB |
Output is correct |
10 |
Correct |
38 ms |
38212 KB |
Output is correct |
11 |
Correct |
156 ms |
57752 KB |
Output is correct |
12 |
Correct |
50 ms |
40440 KB |
Output is correct |
13 |
Correct |
116 ms |
49924 KB |
Output is correct |
14 |
Correct |
20 ms |
33560 KB |
Output is correct |
15 |
Correct |
21 ms |
33868 KB |
Output is correct |
16 |
Correct |
529 ms |
78472 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
17 ms |
33748 KB |
Output is correct |
2 |
Correct |
17 ms |
33748 KB |
Output is correct |
3 |
Correct |
17 ms |
33108 KB |
Output is correct |
4 |
Correct |
16 ms |
33704 KB |
Output is correct |
5 |
Correct |
16 ms |
33672 KB |
Output is correct |
6 |
Correct |
16 ms |
33108 KB |
Output is correct |
7 |
Correct |
15 ms |
33152 KB |
Output is correct |
8 |
Correct |
16 ms |
33072 KB |
Output is correct |
9 |
Correct |
540 ms |
78604 KB |
Output is correct |
10 |
Correct |
38 ms |
38212 KB |
Output is correct |
11 |
Correct |
156 ms |
57752 KB |
Output is correct |
12 |
Correct |
50 ms |
40440 KB |
Output is correct |
13 |
Correct |
116 ms |
49924 KB |
Output is correct |
14 |
Correct |
20 ms |
33560 KB |
Output is correct |
15 |
Correct |
21 ms |
33868 KB |
Output is correct |
16 |
Correct |
529 ms |
78472 KB |
Output is correct |
17 |
Correct |
16 ms |
33748 KB |
Output is correct |
18 |
Correct |
17 ms |
33748 KB |
Output is correct |
19 |
Correct |
17 ms |
33676 KB |
Output is correct |
20 |
Correct |
17 ms |
33768 KB |
Output is correct |
21 |
Correct |
17 ms |
33112 KB |
Output is correct |
22 |
Correct |
17 ms |
33748 KB |
Output is correct |
23 |
Correct |
1292 ms |
98044 KB |
Output is correct |
24 |
Correct |
17 ms |
33732 KB |
Output is correct |
25 |
Correct |
19 ms |
34148 KB |
Output is correct |
26 |
Correct |
22 ms |
33952 KB |
Output is correct |
27 |
Correct |
26 ms |
34208 KB |
Output is correct |
28 |
Correct |
386 ms |
59400 KB |
Output is correct |
29 |
Correct |
629 ms |
72332 KB |
Output is correct |
30 |
Correct |
931 ms |
84860 KB |
Output is correct |
31 |
Correct |
1315 ms |
98136 KB |
Output is correct |
32 |
Correct |
17 ms |
33748 KB |
Output is correct |
33 |
Correct |
17 ms |
33744 KB |
Output is correct |
34 |
Correct |
17 ms |
33748 KB |
Output is correct |
35 |
Correct |
17 ms |
33108 KB |
Output is correct |
36 |
Correct |
16 ms |
33168 KB |
Output is correct |
37 |
Correct |
16 ms |
33696 KB |
Output is correct |
38 |
Correct |
17 ms |
33676 KB |
Output is correct |
39 |
Correct |
17 ms |
33748 KB |
Output is correct |
40 |
Correct |
17 ms |
33748 KB |
Output is correct |
41 |
Correct |
16 ms |
33108 KB |
Output is correct |
42 |
Correct |
19 ms |
33752 KB |
Output is correct |
43 |
Correct |
21 ms |
33728 KB |
Output is correct |
44 |
Correct |
23 ms |
34056 KB |
Output is correct |
45 |
Correct |
596 ms |
70060 KB |
Output is correct |
46 |
Correct |
973 ms |
85960 KB |
Output is correct |
47 |
Correct |
955 ms |
86052 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
17 ms |
33748 KB |
Output is correct |
2 |
Correct |
17 ms |
33748 KB |
Output is correct |
3 |
Correct |
17 ms |
33108 KB |
Output is correct |
4 |
Correct |
16 ms |
33704 KB |
Output is correct |
5 |
Correct |
16 ms |
33672 KB |
Output is correct |
6 |
Correct |
16 ms |
33108 KB |
Output is correct |
7 |
Correct |
15 ms |
33152 KB |
Output is correct |
8 |
Correct |
16 ms |
33072 KB |
Output is correct |
9 |
Correct |
540 ms |
78604 KB |
Output is correct |
10 |
Correct |
38 ms |
38212 KB |
Output is correct |
11 |
Correct |
156 ms |
57752 KB |
Output is correct |
12 |
Correct |
50 ms |
40440 KB |
Output is correct |
13 |
Correct |
116 ms |
49924 KB |
Output is correct |
14 |
Correct |
20 ms |
33560 KB |
Output is correct |
15 |
Correct |
21 ms |
33868 KB |
Output is correct |
16 |
Correct |
529 ms |
78472 KB |
Output is correct |
17 |
Correct |
16 ms |
33748 KB |
Output is correct |
18 |
Correct |
17 ms |
33748 KB |
Output is correct |
19 |
Correct |
17 ms |
33676 KB |
Output is correct |
20 |
Correct |
17 ms |
33768 KB |
Output is correct |
21 |
Correct |
17 ms |
33112 KB |
Output is correct |
22 |
Correct |
17 ms |
33748 KB |
Output is correct |
23 |
Correct |
1292 ms |
98044 KB |
Output is correct |
24 |
Correct |
17 ms |
33732 KB |
Output is correct |
25 |
Correct |
19 ms |
34148 KB |
Output is correct |
26 |
Correct |
22 ms |
33952 KB |
Output is correct |
27 |
Correct |
26 ms |
34208 KB |
Output is correct |
28 |
Correct |
386 ms |
59400 KB |
Output is correct |
29 |
Correct |
629 ms |
72332 KB |
Output is correct |
30 |
Correct |
931 ms |
84860 KB |
Output is correct |
31 |
Correct |
1315 ms |
98136 KB |
Output is correct |
32 |
Correct |
17 ms |
33748 KB |
Output is correct |
33 |
Correct |
17 ms |
33744 KB |
Output is correct |
34 |
Correct |
17 ms |
33748 KB |
Output is correct |
35 |
Correct |
17 ms |
33108 KB |
Output is correct |
36 |
Correct |
16 ms |
33168 KB |
Output is correct |
37 |
Correct |
16 ms |
33696 KB |
Output is correct |
38 |
Correct |
17 ms |
33676 KB |
Output is correct |
39 |
Correct |
17 ms |
33748 KB |
Output is correct |
40 |
Correct |
17 ms |
33748 KB |
Output is correct |
41 |
Correct |
16 ms |
33108 KB |
Output is correct |
42 |
Correct |
19 ms |
33752 KB |
Output is correct |
43 |
Correct |
21 ms |
33728 KB |
Output is correct |
44 |
Correct |
23 ms |
34056 KB |
Output is correct |
45 |
Correct |
596 ms |
70060 KB |
Output is correct |
46 |
Correct |
973 ms |
85960 KB |
Output is correct |
47 |
Correct |
955 ms |
86052 KB |
Output is correct |
48 |
Correct |
18 ms |
33748 KB |
Output is correct |
49 |
Correct |
18 ms |
33748 KB |
Output is correct |
50 |
Correct |
21 ms |
33660 KB |
Output is correct |
51 |
Correct |
18 ms |
33692 KB |
Output is correct |
52 |
Correct |
17 ms |
33756 KB |
Output is correct |
53 |
Correct |
18 ms |
33764 KB |
Output is correct |
54 |
Correct |
17 ms |
33748 KB |
Output is correct |
55 |
Incorrect |
1219 ms |
82392 KB |
Solution announced impossible, but it is possible. |
56 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
17 ms |
33748 KB |
Output is correct |
2 |
Correct |
17 ms |
33748 KB |
Output is correct |
3 |
Correct |
17 ms |
33108 KB |
Output is correct |
4 |
Correct |
16 ms |
33704 KB |
Output is correct |
5 |
Correct |
16 ms |
33672 KB |
Output is correct |
6 |
Correct |
16 ms |
33108 KB |
Output is correct |
7 |
Correct |
15 ms |
33152 KB |
Output is correct |
8 |
Correct |
16 ms |
33072 KB |
Output is correct |
9 |
Correct |
540 ms |
78604 KB |
Output is correct |
10 |
Correct |
38 ms |
38212 KB |
Output is correct |
11 |
Correct |
156 ms |
57752 KB |
Output is correct |
12 |
Correct |
50 ms |
40440 KB |
Output is correct |
13 |
Correct |
116 ms |
49924 KB |
Output is correct |
14 |
Correct |
20 ms |
33560 KB |
Output is correct |
15 |
Correct |
21 ms |
33868 KB |
Output is correct |
16 |
Correct |
529 ms |
78472 KB |
Output is correct |
17 |
Correct |
17 ms |
33748 KB |
Output is correct |
18 |
Correct |
17 ms |
33748 KB |
Output is correct |
19 |
Correct |
16 ms |
33180 KB |
Output is correct |
20 |
Correct |
754 ms |
112260 KB |
Output is correct |
21 |
Correct |
653 ms |
104260 KB |
Output is correct |
22 |
Correct |
838 ms |
104204 KB |
Output is correct |
23 |
Correct |
690 ms |
109596 KB |
Output is correct |
24 |
Correct |
455 ms |
66844 KB |
Output is correct |
25 |
Correct |
870 ms |
99676 KB |
Output is correct |
26 |
Correct |
891 ms |
99736 KB |
Output is correct |
27 |
Correct |
1070 ms |
113784 KB |
Output is correct |
28 |
Correct |
972 ms |
113848 KB |
Output is correct |
29 |
Correct |
1146 ms |
113640 KB |
Output is correct |
30 |
Correct |
930 ms |
113716 KB |
Output is correct |
31 |
Correct |
18 ms |
33748 KB |
Output is correct |
32 |
Correct |
49 ms |
38628 KB |
Output is correct |
33 |
Correct |
103 ms |
49996 KB |
Output is correct |
34 |
Correct |
561 ms |
112288 KB |
Output is correct |
35 |
Correct |
35 ms |
35660 KB |
Output is correct |
36 |
Correct |
153 ms |
45604 KB |
Output is correct |
37 |
Correct |
362 ms |
58232 KB |
Output is correct |
38 |
Correct |
373 ms |
59104 KB |
Output is correct |
39 |
Correct |
520 ms |
68520 KB |
Output is correct |
40 |
Correct |
739 ms |
78412 KB |
Output is correct |
41 |
Correct |
936 ms |
87044 KB |
Output is correct |
42 |
Correct |
1039 ms |
97024 KB |
Output is correct |
43 |
Correct |
16 ms |
33748 KB |
Output is correct |
44 |
Correct |
18 ms |
33776 KB |
Output is correct |
45 |
Correct |
19 ms |
33748 KB |
Output is correct |
46 |
Correct |
20 ms |
33116 KB |
Output is correct |
47 |
Correct |
17 ms |
33084 KB |
Output is correct |
48 |
Correct |
17 ms |
33748 KB |
Output is correct |
49 |
Correct |
18 ms |
33672 KB |
Output is correct |
50 |
Correct |
16 ms |
33740 KB |
Output is correct |
51 |
Correct |
19 ms |
33696 KB |
Output is correct |
52 |
Correct |
15 ms |
33108 KB |
Output is correct |
53 |
Correct |
19 ms |
33728 KB |
Output is correct |
54 |
Correct |
20 ms |
33720 KB |
Output is correct |
55 |
Correct |
23 ms |
34004 KB |
Output is correct |
56 |
Correct |
592 ms |
70052 KB |
Output is correct |
57 |
Correct |
842 ms |
86064 KB |
Output is correct |
58 |
Correct |
882 ms |
86064 KB |
Output is correct |
59 |
Correct |
16 ms |
33104 KB |
Output is correct |
60 |
Correct |
17 ms |
33776 KB |
Output is correct |
61 |
Correct |
16 ms |
33108 KB |
Output is correct |
62 |
Correct |
1246 ms |
118632 KB |
Output is correct |
63 |
Correct |
1186 ms |
118696 KB |
Output is correct |
64 |
Correct |
1243 ms |
118192 KB |
Output is correct |
65 |
Correct |
26 ms |
34388 KB |
Output is correct |
66 |
Correct |
42 ms |
35352 KB |
Output is correct |
67 |
Correct |
601 ms |
68444 KB |
Output is correct |
68 |
Correct |
922 ms |
85652 KB |
Output is correct |
69 |
Correct |
1336 ms |
103356 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
17 ms |
33748 KB |
Output is correct |
2 |
Correct |
17 ms |
33748 KB |
Output is correct |
3 |
Correct |
17 ms |
33108 KB |
Output is correct |
4 |
Correct |
16 ms |
33704 KB |
Output is correct |
5 |
Correct |
16 ms |
33672 KB |
Output is correct |
6 |
Correct |
16 ms |
33108 KB |
Output is correct |
7 |
Correct |
15 ms |
33152 KB |
Output is correct |
8 |
Correct |
16 ms |
33072 KB |
Output is correct |
9 |
Correct |
540 ms |
78604 KB |
Output is correct |
10 |
Correct |
38 ms |
38212 KB |
Output is correct |
11 |
Correct |
156 ms |
57752 KB |
Output is correct |
12 |
Correct |
50 ms |
40440 KB |
Output is correct |
13 |
Correct |
116 ms |
49924 KB |
Output is correct |
14 |
Correct |
20 ms |
33560 KB |
Output is correct |
15 |
Correct |
21 ms |
33868 KB |
Output is correct |
16 |
Correct |
529 ms |
78472 KB |
Output is correct |
17 |
Correct |
888 ms |
123796 KB |
Output is correct |
18 |
Correct |
897 ms |
123676 KB |
Output is correct |
19 |
Correct |
814 ms |
107484 KB |
Output is correct |
20 |
Correct |
956 ms |
92272 KB |
Output is correct |
21 |
Correct |
917 ms |
101168 KB |
Output is correct |
22 |
Correct |
17 ms |
33748 KB |
Output is correct |
23 |
Correct |
124 ms |
44288 KB |
Output is correct |
24 |
Correct |
53 ms |
38040 KB |
Output is correct |
25 |
Correct |
221 ms |
50240 KB |
Output is correct |
26 |
Correct |
432 ms |
62612 KB |
Output is correct |
27 |
Correct |
466 ms |
64976 KB |
Output is correct |
28 |
Correct |
602 ms |
72720 KB |
Output is correct |
29 |
Correct |
807 ms |
80300 KB |
Output is correct |
30 |
Correct |
946 ms |
88192 KB |
Output is correct |
31 |
Correct |
1098 ms |
96084 KB |
Output is correct |
32 |
Correct |
1289 ms |
103860 KB |
Output is correct |
33 |
Correct |
1280 ms |
118492 KB |
Output is correct |
34 |
Correct |
27 ms |
34516 KB |
Output is correct |
35 |
Correct |
39 ms |
35632 KB |
Output is correct |
36 |
Correct |
536 ms |
68260 KB |
Output is correct |
37 |
Correct |
908 ms |
85268 KB |
Output is correct |
38 |
Correct |
1370 ms |
102632 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
17 ms |
33748 KB |
Output is correct |
2 |
Correct |
17 ms |
33748 KB |
Output is correct |
3 |
Correct |
17 ms |
33108 KB |
Output is correct |
4 |
Correct |
16 ms |
33704 KB |
Output is correct |
5 |
Correct |
16 ms |
33672 KB |
Output is correct |
6 |
Correct |
16 ms |
33108 KB |
Output is correct |
7 |
Correct |
15 ms |
33152 KB |
Output is correct |
8 |
Correct |
16 ms |
33072 KB |
Output is correct |
9 |
Correct |
540 ms |
78604 KB |
Output is correct |
10 |
Correct |
38 ms |
38212 KB |
Output is correct |
11 |
Correct |
156 ms |
57752 KB |
Output is correct |
12 |
Correct |
50 ms |
40440 KB |
Output is correct |
13 |
Correct |
116 ms |
49924 KB |
Output is correct |
14 |
Correct |
20 ms |
33560 KB |
Output is correct |
15 |
Correct |
21 ms |
33868 KB |
Output is correct |
16 |
Correct |
529 ms |
78472 KB |
Output is correct |
17 |
Correct |
16 ms |
33748 KB |
Output is correct |
18 |
Correct |
17 ms |
33748 KB |
Output is correct |
19 |
Correct |
17 ms |
33676 KB |
Output is correct |
20 |
Correct |
17 ms |
33768 KB |
Output is correct |
21 |
Correct |
17 ms |
33112 KB |
Output is correct |
22 |
Correct |
17 ms |
33748 KB |
Output is correct |
23 |
Correct |
1292 ms |
98044 KB |
Output is correct |
24 |
Correct |
17 ms |
33732 KB |
Output is correct |
25 |
Correct |
19 ms |
34148 KB |
Output is correct |
26 |
Correct |
22 ms |
33952 KB |
Output is correct |
27 |
Correct |
26 ms |
34208 KB |
Output is correct |
28 |
Correct |
386 ms |
59400 KB |
Output is correct |
29 |
Correct |
629 ms |
72332 KB |
Output is correct |
30 |
Correct |
931 ms |
84860 KB |
Output is correct |
31 |
Correct |
1315 ms |
98136 KB |
Output is correct |
32 |
Correct |
17 ms |
33748 KB |
Output is correct |
33 |
Correct |
17 ms |
33744 KB |
Output is correct |
34 |
Correct |
17 ms |
33748 KB |
Output is correct |
35 |
Correct |
17 ms |
33108 KB |
Output is correct |
36 |
Correct |
16 ms |
33168 KB |
Output is correct |
37 |
Correct |
16 ms |
33696 KB |
Output is correct |
38 |
Correct |
17 ms |
33676 KB |
Output is correct |
39 |
Correct |
17 ms |
33748 KB |
Output is correct |
40 |
Correct |
17 ms |
33748 KB |
Output is correct |
41 |
Correct |
16 ms |
33108 KB |
Output is correct |
42 |
Correct |
19 ms |
33752 KB |
Output is correct |
43 |
Correct |
21 ms |
33728 KB |
Output is correct |
44 |
Correct |
23 ms |
34056 KB |
Output is correct |
45 |
Correct |
596 ms |
70060 KB |
Output is correct |
46 |
Correct |
973 ms |
85960 KB |
Output is correct |
47 |
Correct |
955 ms |
86052 KB |
Output is correct |
48 |
Correct |
18 ms |
33748 KB |
Output is correct |
49 |
Correct |
18 ms |
33748 KB |
Output is correct |
50 |
Correct |
21 ms |
33660 KB |
Output is correct |
51 |
Correct |
18 ms |
33692 KB |
Output is correct |
52 |
Correct |
17 ms |
33756 KB |
Output is correct |
53 |
Correct |
18 ms |
33764 KB |
Output is correct |
54 |
Correct |
17 ms |
33748 KB |
Output is correct |
55 |
Incorrect |
1219 ms |
82392 KB |
Solution announced impossible, but it is possible. |
56 |
Halted |
0 ms |
0 KB |
- |