#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] = {0, 2, 0, -2}, yd[4] = {2, 0, -2, 0};
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){
c++;
vis.ins({x, y});
for(ll i=0;i<4;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);
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(c != n) return 0;
build(u, v, a, b);
return 1;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
344 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 |
412 KB |
Output is correct |
9 |
Correct |
150 ms |
43452 KB |
Output is correct |
10 |
Correct |
10 ms |
4956 KB |
Output is correct |
11 |
Correct |
80 ms |
23900 KB |
Output is correct |
12 |
Correct |
17 ms |
7256 KB |
Output is correct |
13 |
Correct |
45 ms |
13908 KB |
Output is correct |
14 |
Correct |
1 ms |
600 KB |
Output is correct |
15 |
Correct |
1 ms |
600 KB |
Output is correct |
16 |
Correct |
144 ms |
38304 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
344 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 |
412 KB |
Output is correct |
9 |
Correct |
150 ms |
43452 KB |
Output is correct |
10 |
Correct |
10 ms |
4956 KB |
Output is correct |
11 |
Correct |
80 ms |
23900 KB |
Output is correct |
12 |
Correct |
17 ms |
7256 KB |
Output is correct |
13 |
Correct |
45 ms |
13908 KB |
Output is correct |
14 |
Correct |
1 ms |
600 KB |
Output is correct |
15 |
Correct |
1 ms |
600 KB |
Output is correct |
16 |
Correct |
144 ms |
38304 KB |
Output is correct |
17 |
Correct |
0 ms |
344 KB |
Output is correct |
18 |
Incorrect |
0 ms |
348 KB |
Tree @(3, 5) appears more than once: for edges on positions 0 and 2 |
19 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
344 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 |
412 KB |
Output is correct |
9 |
Correct |
150 ms |
43452 KB |
Output is correct |
10 |
Correct |
10 ms |
4956 KB |
Output is correct |
11 |
Correct |
80 ms |
23900 KB |
Output is correct |
12 |
Correct |
17 ms |
7256 KB |
Output is correct |
13 |
Correct |
45 ms |
13908 KB |
Output is correct |
14 |
Correct |
1 ms |
600 KB |
Output is correct |
15 |
Correct |
1 ms |
600 KB |
Output is correct |
16 |
Correct |
144 ms |
38304 KB |
Output is correct |
17 |
Correct |
0 ms |
344 KB |
Output is correct |
18 |
Incorrect |
0 ms |
348 KB |
Tree @(3, 5) appears more than once: for edges on positions 0 and 2 |
19 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
344 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 |
412 KB |
Output is correct |
9 |
Correct |
150 ms |
43452 KB |
Output is correct |
10 |
Correct |
10 ms |
4956 KB |
Output is correct |
11 |
Correct |
80 ms |
23900 KB |
Output is correct |
12 |
Correct |
17 ms |
7256 KB |
Output is correct |
13 |
Correct |
45 ms |
13908 KB |
Output is correct |
14 |
Correct |
1 ms |
600 KB |
Output is correct |
15 |
Correct |
1 ms |
600 KB |
Output is correct |
16 |
Correct |
144 ms |
38304 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 |
298 ms |
76680 KB |
Output is correct |
21 |
Correct |
288 ms |
71212 KB |
Output is correct |
22 |
Correct |
283 ms |
68556 KB |
Output is correct |
23 |
Correct |
244 ms |
68016 KB |
Output is correct |
24 |
Correct |
79 ms |
19964 KB |
Output is correct |
25 |
Correct |
77 ms |
20004 KB |
Output is correct |
26 |
Correct |
77 ms |
19916 KB |
Output is correct |
27 |
Correct |
242 ms |
50996 KB |
Output is correct |
28 |
Correct |
246 ms |
51020 KB |
Output is correct |
29 |
Correct |
352 ms |
51028 KB |
Output is correct |
30 |
Correct |
343 ms |
50768 KB |
Output is correct |
31 |
Correct |
0 ms |
344 KB |
Output is correct |
32 |
Correct |
17 ms |
4956 KB |
Output is correct |
33 |
Correct |
36 ms |
10604 KB |
Output is correct |
34 |
Correct |
283 ms |
72432 KB |
Output is correct |
35 |
Correct |
6 ms |
1884 KB |
Output is correct |
36 |
Correct |
23 ms |
6528 KB |
Output is correct |
37 |
Correct |
43 ms |
11332 KB |
Output is correct |
38 |
Correct |
99 ms |
19752 KB |
Output is correct |
39 |
Correct |
149 ms |
26440 KB |
Output is correct |
40 |
Correct |
190 ms |
34372 KB |
Output is correct |
41 |
Correct |
240 ms |
41124 KB |
Output is correct |
42 |
Correct |
306 ms |
48148 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 |
600 KB |
Output is correct |
47 |
Correct |
1 ms |
348 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 |
1 ms |
344 KB |
Output is correct |
52 |
Correct |
0 ms |
436 KB |
Output is correct |
53 |
Correct |
0 ms |
348 KB |
Output is correct |
54 |
Correct |
2 ms |
856 KB |
Output is correct |
55 |
Correct |
2 ms |
860 KB |
Output is correct |
56 |
Correct |
140 ms |
35812 KB |
Output is correct |
57 |
Correct |
227 ms |
52656 KB |
Output is correct |
58 |
Correct |
220 ms |
51852 KB |
Output is correct |
59 |
Correct |
1 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 |
362 ms |
74948 KB |
Output is correct |
63 |
Correct |
314 ms |
75348 KB |
Output is correct |
64 |
Correct |
314 ms |
77636 KB |
Output is correct |
65 |
Correct |
2 ms |
1112 KB |
Output is correct |
66 |
Correct |
3 ms |
1368 KB |
Output is correct |
67 |
Correct |
135 ms |
30708 KB |
Output is correct |
68 |
Correct |
213 ms |
49220 KB |
Output is correct |
69 |
Correct |
310 ms |
61380 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
344 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 |
412 KB |
Output is correct |
9 |
Correct |
150 ms |
43452 KB |
Output is correct |
10 |
Correct |
10 ms |
4956 KB |
Output is correct |
11 |
Correct |
80 ms |
23900 KB |
Output is correct |
12 |
Correct |
17 ms |
7256 KB |
Output is correct |
13 |
Correct |
45 ms |
13908 KB |
Output is correct |
14 |
Correct |
1 ms |
600 KB |
Output is correct |
15 |
Correct |
1 ms |
600 KB |
Output is correct |
16 |
Correct |
144 ms |
38304 KB |
Output is correct |
17 |
Correct |
336 ms |
88816 KB |
Output is correct |
18 |
Correct |
288 ms |
78936 KB |
Output is correct |
19 |
Correct |
284 ms |
76816 KB |
Output is correct |
20 |
Correct |
247 ms |
57940 KB |
Output is correct |
21 |
Correct |
252 ms |
60536 KB |
Output is correct |
22 |
Correct |
0 ms |
348 KB |
Output is correct |
23 |
Correct |
36 ms |
10024 KB |
Output is correct |
24 |
Correct |
15 ms |
3776 KB |
Output is correct |
25 |
Correct |
33 ms |
9044 KB |
Output is correct |
26 |
Correct |
61 ms |
13868 KB |
Output is correct |
27 |
Correct |
129 ms |
30236 KB |
Output is correct |
28 |
Correct |
159 ms |
38088 KB |
Output is correct |
29 |
Correct |
212 ms |
45948 KB |
Output is correct |
30 |
Correct |
238 ms |
52556 KB |
Output is correct |
31 |
Correct |
283 ms |
60656 KB |
Output is correct |
32 |
Correct |
285 ms |
70696 KB |
Output is correct |
33 |
Correct |
331 ms |
82256 KB |
Output is correct |
34 |
Correct |
3 ms |
1368 KB |
Output is correct |
35 |
Correct |
5 ms |
1880 KB |
Output is correct |
36 |
Correct |
125 ms |
30836 KB |
Output is correct |
37 |
Correct |
201 ms |
47320 KB |
Output is correct |
38 |
Correct |
298 ms |
62544 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
344 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 |
412 KB |
Output is correct |
9 |
Correct |
150 ms |
43452 KB |
Output is correct |
10 |
Correct |
10 ms |
4956 KB |
Output is correct |
11 |
Correct |
80 ms |
23900 KB |
Output is correct |
12 |
Correct |
17 ms |
7256 KB |
Output is correct |
13 |
Correct |
45 ms |
13908 KB |
Output is correct |
14 |
Correct |
1 ms |
600 KB |
Output is correct |
15 |
Correct |
1 ms |
600 KB |
Output is correct |
16 |
Correct |
144 ms |
38304 KB |
Output is correct |
17 |
Correct |
0 ms |
344 KB |
Output is correct |
18 |
Incorrect |
0 ms |
348 KB |
Tree @(3, 5) appears more than once: for edges on positions 0 and 2 |
19 |
Halted |
0 ms |
0 KB |
- |