#include "parks.h"
#include <bits/stdc++.h>
#define pb push_back
#define ll int
#define ins insert
#define sz size()
#define vll vector<ll>
#define sc second
using namespace std;
const int N=2e5+5;
const int inf=1e9;
map<pair<ll,ll>, ll> f;
vll xx, yy;
ll xd[4] = {-2, 2, 0, 0}, yd[4] = {0, 0, -2, 2};
ll bx[2][4] = {{-1, 1, 1, -1}, {-1, 1, -1, 1}};
ll by[2][4] = {{-1, 1, -1, 1}, { 1, -1, -1, 1}};
set<pair<ll,ll>> vis;
vll v,u,a,b;
ll n,c;
bool ok(ll x,ll y){
bool free = (vis.find({x, y}) == vis.end());
if(x % 2) return free;
return free && f[{x,y}];
}
void dfs(ll x, ll y){
//~ vis.ins({x, y});
c++;
for(ll i=3;i>=0;i--){
ll nx = x + xd[i], ny = y + yd[i];
ll p = (x + y) / 2 % 2;
ll aa = x + bx[p][i], bb = y + by[p][i];
if(!ok(nx, ny) || !ok(aa, bb)) continue;
v.pb(f[{x,y}]-1);
u.pb(f[{nx,ny}]-1);
a.pb(aa);
b.pb(bb);
vis.ins({aa, bb});
dfs(nx, ny);
}
}
int construct_roads(vector<int> X, vector<int> Y) {
n=X.size();
for(int i=0;i<(int)X.size();i++){
f[{X[i], Y[i]}] = i + 1;
}
xx.pb(0);
yy.pb(0);
for(auto i : X) xx.pb(i);
for(auto i : Y) yy.pb(i);
dfs(xx[1], yy[1]);
if((ll)u.size() < n - 1) return 0;
build(u, v, a, b);
return 1;
}
# |
결과 |
실행 시간 |
메모리 |
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 |
158 ms |
42620 KB |
Output is correct |
10 |
Correct |
11 ms |
4956 KB |
Output is correct |
11 |
Correct |
78 ms |
23636 KB |
Output is correct |
12 |
Correct |
18 ms |
7004 KB |
Output is correct |
13 |
Correct |
42 ms |
13520 KB |
Output is correct |
14 |
Correct |
1 ms |
604 KB |
Output is correct |
15 |
Correct |
1 ms |
604 KB |
Output is correct |
16 |
Correct |
164 ms |
37500 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
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 |
158 ms |
42620 KB |
Output is correct |
10 |
Correct |
11 ms |
4956 KB |
Output is correct |
11 |
Correct |
78 ms |
23636 KB |
Output is correct |
12 |
Correct |
18 ms |
7004 KB |
Output is correct |
13 |
Correct |
42 ms |
13520 KB |
Output is correct |
14 |
Correct |
1 ms |
604 KB |
Output is correct |
15 |
Correct |
1 ms |
604 KB |
Output is correct |
16 |
Correct |
164 ms |
37500 KB |
Output is correct |
17 |
Correct |
0 ms |
348 KB |
Output is correct |
18 |
Correct |
0 ms |
348 KB |
Output is correct |
19 |
Correct |
0 ms |
348 KB |
Output is correct |
20 |
Correct |
0 ms |
348 KB |
Output is correct |
21 |
Correct |
0 ms |
348 KB |
Output is correct |
22 |
Correct |
0 ms |
348 KB |
Output is correct |
23 |
Correct |
356 ms |
60284 KB |
Output is correct |
24 |
Correct |
0 ms |
344 KB |
Output is correct |
25 |
Correct |
1 ms |
604 KB |
Output is correct |
26 |
Correct |
2 ms |
860 KB |
Output is correct |
27 |
Correct |
1 ms |
860 KB |
Output is correct |
28 |
Correct |
117 ms |
24920 KB |
Output is correct |
29 |
Correct |
180 ms |
35360 KB |
Output is correct |
30 |
Correct |
257 ms |
48720 KB |
Output is correct |
31 |
Correct |
395 ms |
59216 KB |
Output is correct |
32 |
Correct |
1 ms |
344 KB |
Output is correct |
33 |
Correct |
0 ms |
348 KB |
Output is correct |
34 |
Correct |
0 ms |
348 KB |
Output is correct |
35 |
Correct |
0 ms |
348 KB |
Output is correct |
36 |
Correct |
0 ms |
348 KB |
Output is correct |
37 |
Correct |
0 ms |
348 KB |
Output is correct |
38 |
Correct |
0 ms |
348 KB |
Output is correct |
39 |
Correct |
0 ms |
348 KB |
Output is correct |
40 |
Correct |
0 ms |
348 KB |
Output is correct |
41 |
Correct |
0 ms |
348 KB |
Output is correct |
42 |
Correct |
0 ms |
348 KB |
Output is correct |
43 |
Correct |
2 ms |
604 KB |
Output is correct |
44 |
Correct |
1 ms |
604 KB |
Output is correct |
45 |
Correct |
146 ms |
34940 KB |
Output is correct |
46 |
Correct |
220 ms |
51276 KB |
Output is correct |
47 |
Correct |
233 ms |
50504 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
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 |
158 ms |
42620 KB |
Output is correct |
10 |
Correct |
11 ms |
4956 KB |
Output is correct |
11 |
Correct |
78 ms |
23636 KB |
Output is correct |
12 |
Correct |
18 ms |
7004 KB |
Output is correct |
13 |
Correct |
42 ms |
13520 KB |
Output is correct |
14 |
Correct |
1 ms |
604 KB |
Output is correct |
15 |
Correct |
1 ms |
604 KB |
Output is correct |
16 |
Correct |
164 ms |
37500 KB |
Output is correct |
17 |
Correct |
0 ms |
348 KB |
Output is correct |
18 |
Correct |
0 ms |
348 KB |
Output is correct |
19 |
Correct |
0 ms |
348 KB |
Output is correct |
20 |
Correct |
0 ms |
348 KB |
Output is correct |
21 |
Correct |
0 ms |
348 KB |
Output is correct |
22 |
Correct |
0 ms |
348 KB |
Output is correct |
23 |
Correct |
356 ms |
60284 KB |
Output is correct |
24 |
Correct |
0 ms |
344 KB |
Output is correct |
25 |
Correct |
1 ms |
604 KB |
Output is correct |
26 |
Correct |
2 ms |
860 KB |
Output is correct |
27 |
Correct |
1 ms |
860 KB |
Output is correct |
28 |
Correct |
117 ms |
24920 KB |
Output is correct |
29 |
Correct |
180 ms |
35360 KB |
Output is correct |
30 |
Correct |
257 ms |
48720 KB |
Output is correct |
31 |
Correct |
395 ms |
59216 KB |
Output is correct |
32 |
Correct |
1 ms |
344 KB |
Output is correct |
33 |
Correct |
0 ms |
348 KB |
Output is correct |
34 |
Correct |
0 ms |
348 KB |
Output is correct |
35 |
Correct |
0 ms |
348 KB |
Output is correct |
36 |
Correct |
0 ms |
348 KB |
Output is correct |
37 |
Correct |
0 ms |
348 KB |
Output is correct |
38 |
Correct |
0 ms |
348 KB |
Output is correct |
39 |
Correct |
0 ms |
348 KB |
Output is correct |
40 |
Correct |
0 ms |
348 KB |
Output is correct |
41 |
Correct |
0 ms |
348 KB |
Output is correct |
42 |
Correct |
0 ms |
348 KB |
Output is correct |
43 |
Correct |
2 ms |
604 KB |
Output is correct |
44 |
Correct |
1 ms |
604 KB |
Output is correct |
45 |
Correct |
146 ms |
34940 KB |
Output is correct |
46 |
Correct |
220 ms |
51276 KB |
Output is correct |
47 |
Correct |
233 ms |
50504 KB |
Output is correct |
48 |
Correct |
0 ms |
348 KB |
Output is correct |
49 |
Correct |
0 ms |
348 KB |
Output is correct |
50 |
Correct |
0 ms |
348 KB |
Output is correct |
51 |
Correct |
0 ms |
348 KB |
Output is correct |
52 |
Correct |
0 ms |
348 KB |
Output is correct |
53 |
Correct |
0 ms |
348 KB |
Output is correct |
54 |
Correct |
0 ms |
348 KB |
Output is correct |
55 |
Incorrect |
334 ms |
61592 KB |
Given structure is not connected: There is no path between vertices 0 and 10 |
56 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
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 |
158 ms |
42620 KB |
Output is correct |
10 |
Correct |
11 ms |
4956 KB |
Output is correct |
11 |
Correct |
78 ms |
23636 KB |
Output is correct |
12 |
Correct |
18 ms |
7004 KB |
Output is correct |
13 |
Correct |
42 ms |
13520 KB |
Output is correct |
14 |
Correct |
1 ms |
604 KB |
Output is correct |
15 |
Correct |
1 ms |
604 KB |
Output is correct |
16 |
Correct |
164 ms |
37500 KB |
Output is correct |
17 |
Correct |
0 ms |
348 KB |
Output is correct |
18 |
Correct |
0 ms |
348 KB |
Output is correct |
19 |
Correct |
0 ms |
348 KB |
Output is correct |
20 |
Correct |
322 ms |
74104 KB |
Output is correct |
21 |
Correct |
303 ms |
69100 KB |
Output is correct |
22 |
Correct |
310 ms |
66284 KB |
Output is correct |
23 |
Correct |
272 ms |
66256 KB |
Output is correct |
24 |
Correct |
74 ms |
18384 KB |
Output is correct |
25 |
Correct |
78 ms |
18384 KB |
Output is correct |
26 |
Correct |
78 ms |
18384 KB |
Output is correct |
27 |
Correct |
262 ms |
49480 KB |
Output is correct |
28 |
Correct |
263 ms |
49236 KB |
Output is correct |
29 |
Correct |
366 ms |
49480 KB |
Output is correct |
30 |
Correct |
354 ms |
49232 KB |
Output is correct |
31 |
Correct |
0 ms |
348 KB |
Output is correct |
32 |
Correct |
18 ms |
4992 KB |
Output is correct |
33 |
Correct |
34 ms |
9160 KB |
Output is correct |
34 |
Correct |
288 ms |
70016 KB |
Output is correct |
35 |
Correct |
6 ms |
1884 KB |
Output is correct |
36 |
Correct |
23 ms |
5728 KB |
Output is correct |
37 |
Correct |
44 ms |
9972 KB |
Output is correct |
38 |
Correct |
114 ms |
18688 KB |
Output is correct |
39 |
Correct |
145 ms |
25172 KB |
Output is correct |
40 |
Correct |
193 ms |
32620 KB |
Output is correct |
41 |
Correct |
259 ms |
39072 KB |
Output is correct |
42 |
Correct |
286 ms |
45552 KB |
Output is correct |
43 |
Correct |
0 ms |
348 KB |
Output is correct |
44 |
Correct |
0 ms |
348 KB |
Output is correct |
45 |
Correct |
0 ms |
348 KB |
Output is correct |
46 |
Correct |
0 ms |
348 KB |
Output is correct |
47 |
Correct |
0 ms |
348 KB |
Output is correct |
48 |
Correct |
0 ms |
348 KB |
Output is correct |
49 |
Correct |
1 ms |
348 KB |
Output is correct |
50 |
Correct |
0 ms |
348 KB |
Output is correct |
51 |
Correct |
0 ms |
348 KB |
Output is correct |
52 |
Correct |
0 ms |
348 KB |
Output is correct |
53 |
Correct |
0 ms |
348 KB |
Output is correct |
54 |
Correct |
1 ms |
604 KB |
Output is correct |
55 |
Correct |
1 ms |
604 KB |
Output is correct |
56 |
Correct |
174 ms |
34752 KB |
Output is correct |
57 |
Correct |
229 ms |
51408 KB |
Output is correct |
58 |
Correct |
227 ms |
50560 KB |
Output is correct |
59 |
Correct |
0 ms |
348 KB |
Output is correct |
60 |
Correct |
0 ms |
348 KB |
Output is correct |
61 |
Correct |
0 ms |
348 KB |
Output is correct |
62 |
Correct |
352 ms |
73168 KB |
Output is correct |
63 |
Correct |
351 ms |
73688 KB |
Output is correct |
64 |
Correct |
349 ms |
76004 KB |
Output is correct |
65 |
Correct |
3 ms |
1116 KB |
Output is correct |
66 |
Correct |
3 ms |
1372 KB |
Output is correct |
67 |
Correct |
145 ms |
29764 KB |
Output is correct |
68 |
Correct |
239 ms |
47936 KB |
Output is correct |
69 |
Correct |
324 ms |
59728 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
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 |
158 ms |
42620 KB |
Output is correct |
10 |
Correct |
11 ms |
4956 KB |
Output is correct |
11 |
Correct |
78 ms |
23636 KB |
Output is correct |
12 |
Correct |
18 ms |
7004 KB |
Output is correct |
13 |
Correct |
42 ms |
13520 KB |
Output is correct |
14 |
Correct |
1 ms |
604 KB |
Output is correct |
15 |
Correct |
1 ms |
604 KB |
Output is correct |
16 |
Correct |
164 ms |
37500 KB |
Output is correct |
17 |
Correct |
360 ms |
86764 KB |
Output is correct |
18 |
Correct |
330 ms |
86768 KB |
Output is correct |
19 |
Correct |
326 ms |
74368 KB |
Output is correct |
20 |
Correct |
406 ms |
62548 KB |
Output is correct |
21 |
Correct |
342 ms |
61256 KB |
Output is correct |
22 |
Correct |
0 ms |
348 KB |
Output is correct |
23 |
Correct |
41 ms |
9128 KB |
Output is correct |
24 |
Correct |
15 ms |
3932 KB |
Output is correct |
25 |
Correct |
35 ms |
8144 KB |
Output is correct |
26 |
Correct |
57 ms |
12644 KB |
Output is correct |
27 |
Correct |
159 ms |
30128 KB |
Output is correct |
28 |
Correct |
225 ms |
37564 KB |
Output is correct |
29 |
Correct |
250 ms |
45228 KB |
Output is correct |
30 |
Correct |
312 ms |
52000 KB |
Output is correct |
31 |
Correct |
350 ms |
60040 KB |
Output is correct |
32 |
Correct |
388 ms |
72784 KB |
Output is correct |
33 |
Correct |
354 ms |
80404 KB |
Output is correct |
34 |
Correct |
3 ms |
1368 KB |
Output is correct |
35 |
Correct |
5 ms |
1884 KB |
Output is correct |
36 |
Correct |
149 ms |
30988 KB |
Output is correct |
37 |
Correct |
255 ms |
47256 KB |
Output is correct |
38 |
Correct |
335 ms |
62800 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
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 |
158 ms |
42620 KB |
Output is correct |
10 |
Correct |
11 ms |
4956 KB |
Output is correct |
11 |
Correct |
78 ms |
23636 KB |
Output is correct |
12 |
Correct |
18 ms |
7004 KB |
Output is correct |
13 |
Correct |
42 ms |
13520 KB |
Output is correct |
14 |
Correct |
1 ms |
604 KB |
Output is correct |
15 |
Correct |
1 ms |
604 KB |
Output is correct |
16 |
Correct |
164 ms |
37500 KB |
Output is correct |
17 |
Correct |
0 ms |
348 KB |
Output is correct |
18 |
Correct |
0 ms |
348 KB |
Output is correct |
19 |
Correct |
0 ms |
348 KB |
Output is correct |
20 |
Correct |
0 ms |
348 KB |
Output is correct |
21 |
Correct |
0 ms |
348 KB |
Output is correct |
22 |
Correct |
0 ms |
348 KB |
Output is correct |
23 |
Correct |
356 ms |
60284 KB |
Output is correct |
24 |
Correct |
0 ms |
344 KB |
Output is correct |
25 |
Correct |
1 ms |
604 KB |
Output is correct |
26 |
Correct |
2 ms |
860 KB |
Output is correct |
27 |
Correct |
1 ms |
860 KB |
Output is correct |
28 |
Correct |
117 ms |
24920 KB |
Output is correct |
29 |
Correct |
180 ms |
35360 KB |
Output is correct |
30 |
Correct |
257 ms |
48720 KB |
Output is correct |
31 |
Correct |
395 ms |
59216 KB |
Output is correct |
32 |
Correct |
1 ms |
344 KB |
Output is correct |
33 |
Correct |
0 ms |
348 KB |
Output is correct |
34 |
Correct |
0 ms |
348 KB |
Output is correct |
35 |
Correct |
0 ms |
348 KB |
Output is correct |
36 |
Correct |
0 ms |
348 KB |
Output is correct |
37 |
Correct |
0 ms |
348 KB |
Output is correct |
38 |
Correct |
0 ms |
348 KB |
Output is correct |
39 |
Correct |
0 ms |
348 KB |
Output is correct |
40 |
Correct |
0 ms |
348 KB |
Output is correct |
41 |
Correct |
0 ms |
348 KB |
Output is correct |
42 |
Correct |
0 ms |
348 KB |
Output is correct |
43 |
Correct |
2 ms |
604 KB |
Output is correct |
44 |
Correct |
1 ms |
604 KB |
Output is correct |
45 |
Correct |
146 ms |
34940 KB |
Output is correct |
46 |
Correct |
220 ms |
51276 KB |
Output is correct |
47 |
Correct |
233 ms |
50504 KB |
Output is correct |
48 |
Correct |
0 ms |
348 KB |
Output is correct |
49 |
Correct |
0 ms |
348 KB |
Output is correct |
50 |
Correct |
0 ms |
348 KB |
Output is correct |
51 |
Correct |
0 ms |
348 KB |
Output is correct |
52 |
Correct |
0 ms |
348 KB |
Output is correct |
53 |
Correct |
0 ms |
348 KB |
Output is correct |
54 |
Correct |
0 ms |
348 KB |
Output is correct |
55 |
Incorrect |
334 ms |
61592 KB |
Given structure is not connected: There is no path between vertices 0 and 10 |
56 |
Halted |
0 ms |
0 KB |
- |