#include "parks.h"
#include<bits/stdc++.h>
using namespace std;
typedef pair<int,int> ii;
typedef pair<ii,int> iii;
#define F first
#define S second
int xx[] = {0,0,1,-1};
int yy[] = {1,-1,0,0};
vector<vector<int>> g;
vector<bool> vis;
int c = 0;
void search(int i) {
vis[i] = 1; c++;
for(auto x: g[i]) if(!vis[x]) search(x);
}
int construct_roads(std::vector<int> x, std::vector<int> y) {
int n = x.size();
vis.resize(n,0);
g.resize(n);
vector<iii> p;
for(int i = 0; i < n; i++) p.push_back({{x[i],y[i]},i});
sort(p.begin(),p.end());
vector<ii> roads;
map<ii,int> rr;
for(int i = 0; i < n-1; i++) {
if(p[i].F.F == p[i+1].F.F && p[i+1].F.S-p[i].F.S == 2) {
ii a = {p[i].F.F, p[i].F.S+1};
rr[a] = roads.size();
roads.emplace_back(p[i].S, p[i+1].S);
g[p[i].S].push_back(p[i+1].S);
g[p[i+1].S].push_back(p[i].S);
}
}
for(int i = 0; i < n; i++) swap(p[i].F.F,p[i].F.S);
sort(p.begin(),p.end());
for(int i = 0; i < n; i++) swap(p[i].F.F,p[i].F.S);
for(int i = 0; i < n-1; i++) {
if(p[i].F.S == p[i+1].F.S && p[i+1].F.F-p[i].F.F == 2) {
ii a = {p[i].F.F+1,p[i].F.S};
rr[a] = roads.size();
roads.emplace_back(p[i].S, p[i+1].S);
g[p[i].S].push_back(p[i+1].S);
g[p[i+1].S].push_back(p[i].S);
}
}
int m = roads.size();
search(0);
if(c < n) return 0;
vector<ii> b;
vector<int> rb(m,-1);
for(auto x: rr) {
if(rb[x.S] == -1) {
rb[x.S] = b.size();
int f = x.S;
ii a;
if(x.F.F%2) a = {x.F.F, x.F.S+1};
else a = {x.F.F+1, x.F.S};
b.push_back(a);
//cout << a.F << " " << a.S << endl;
bool bb = true;
while(bb) {
bb = false;
for(int i = 0; i < 4; i++) {
ii po = {a.F+xx[i], a.S+yy[i]};
if(rr.count(po) && rr[po] != f) {
f = rr[po];
if(rb[f] >= 0) break;
bb = true;
a = {po.F+xx[i], po.S+yy[i]};
//cout << a.F << " " << a.S << endl;
rb[f] = b.size();
b.push_back(a);
break;
}
}
}
}
}
vector<int> u(m), v(m), ba(m), bb(m);
for(int i = 0; i < m; i++) {
u[i] = roads[i].F; v[i] = roads[i].S;
ba[i] = b[rb[i]].F; bb[i] = b[rb[i]].S;
}
build(u, v, ba, bb);
//for(auto x: rr) cout << x.F.F << " " << x.F.S << endl;
return 1;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
1 ms |
212 KB |
Output is correct |
3 |
Correct |
0 ms |
296 KB |
Output is correct |
4 |
Correct |
0 ms |
300 KB |
Output is correct |
5 |
Correct |
0 ms |
212 KB |
Output is correct |
6 |
Correct |
0 ms |
300 KB |
Output is correct |
7 |
Correct |
1 ms |
300 KB |
Output is correct |
8 |
Correct |
1 ms |
212 KB |
Output is correct |
9 |
Correct |
151 ms |
25104 KB |
Output is correct |
10 |
Correct |
11 ms |
2764 KB |
Output is correct |
11 |
Correct |
71 ms |
13748 KB |
Output is correct |
12 |
Correct |
18 ms |
4024 KB |
Output is correct |
13 |
Correct |
23 ms |
8260 KB |
Output is correct |
14 |
Correct |
1 ms |
340 KB |
Output is correct |
15 |
Correct |
2 ms |
596 KB |
Output is correct |
16 |
Correct |
152 ms |
23784 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
1 ms |
212 KB |
Output is correct |
3 |
Correct |
0 ms |
296 KB |
Output is correct |
4 |
Correct |
0 ms |
300 KB |
Output is correct |
5 |
Correct |
0 ms |
212 KB |
Output is correct |
6 |
Correct |
0 ms |
300 KB |
Output is correct |
7 |
Correct |
1 ms |
300 KB |
Output is correct |
8 |
Correct |
1 ms |
212 KB |
Output is correct |
9 |
Correct |
151 ms |
25104 KB |
Output is correct |
10 |
Correct |
11 ms |
2764 KB |
Output is correct |
11 |
Correct |
71 ms |
13748 KB |
Output is correct |
12 |
Correct |
18 ms |
4024 KB |
Output is correct |
13 |
Correct |
23 ms |
8260 KB |
Output is correct |
14 |
Correct |
1 ms |
340 KB |
Output is correct |
15 |
Correct |
2 ms |
596 KB |
Output is correct |
16 |
Correct |
152 ms |
23784 KB |
Output is correct |
17 |
Incorrect |
0 ms |
212 KB |
Tree @(3, 3) appears more than once: for edges on positions 0 and 2 |
18 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
1 ms |
212 KB |
Output is correct |
3 |
Correct |
0 ms |
296 KB |
Output is correct |
4 |
Correct |
0 ms |
300 KB |
Output is correct |
5 |
Correct |
0 ms |
212 KB |
Output is correct |
6 |
Correct |
0 ms |
300 KB |
Output is correct |
7 |
Correct |
1 ms |
300 KB |
Output is correct |
8 |
Correct |
1 ms |
212 KB |
Output is correct |
9 |
Correct |
151 ms |
25104 KB |
Output is correct |
10 |
Correct |
11 ms |
2764 KB |
Output is correct |
11 |
Correct |
71 ms |
13748 KB |
Output is correct |
12 |
Correct |
18 ms |
4024 KB |
Output is correct |
13 |
Correct |
23 ms |
8260 KB |
Output is correct |
14 |
Correct |
1 ms |
340 KB |
Output is correct |
15 |
Correct |
2 ms |
596 KB |
Output is correct |
16 |
Correct |
152 ms |
23784 KB |
Output is correct |
17 |
Incorrect |
0 ms |
212 KB |
Tree @(3, 3) appears more than once: for edges on positions 0 and 2 |
18 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
1 ms |
212 KB |
Output is correct |
3 |
Correct |
0 ms |
296 KB |
Output is correct |
4 |
Correct |
0 ms |
300 KB |
Output is correct |
5 |
Correct |
0 ms |
212 KB |
Output is correct |
6 |
Correct |
0 ms |
300 KB |
Output is correct |
7 |
Correct |
1 ms |
300 KB |
Output is correct |
8 |
Correct |
1 ms |
212 KB |
Output is correct |
9 |
Correct |
151 ms |
25104 KB |
Output is correct |
10 |
Correct |
11 ms |
2764 KB |
Output is correct |
11 |
Correct |
71 ms |
13748 KB |
Output is correct |
12 |
Correct |
18 ms |
4024 KB |
Output is correct |
13 |
Correct |
23 ms |
8260 KB |
Output is correct |
14 |
Correct |
1 ms |
340 KB |
Output is correct |
15 |
Correct |
2 ms |
596 KB |
Output is correct |
16 |
Correct |
152 ms |
23784 KB |
Output is correct |
17 |
Correct |
0 ms |
212 KB |
Output is correct |
18 |
Correct |
1 ms |
212 KB |
Output is correct |
19 |
Correct |
1 ms |
212 KB |
Output is correct |
20 |
Correct |
338 ms |
51176 KB |
Output is correct |
21 |
Correct |
336 ms |
49788 KB |
Output is correct |
22 |
Correct |
349 ms |
49040 KB |
Output is correct |
23 |
Correct |
252 ms |
41340 KB |
Output is correct |
24 |
Correct |
75 ms |
12996 KB |
Output is correct |
25 |
Correct |
171 ms |
32388 KB |
Output is correct |
26 |
Correct |
147 ms |
32332 KB |
Output is correct |
27 |
Correct |
280 ms |
44200 KB |
Output is correct |
28 |
Correct |
261 ms |
44292 KB |
Output is correct |
29 |
Correct |
301 ms |
44220 KB |
Output is correct |
30 |
Correct |
311 ms |
44128 KB |
Output is correct |
31 |
Correct |
1 ms |
212 KB |
Output is correct |
32 |
Correct |
24 ms |
3568 KB |
Output is correct |
33 |
Correct |
31 ms |
7112 KB |
Output is correct |
34 |
Correct |
316 ms |
50144 KB |
Output is correct |
35 |
Correct |
7 ms |
1940 KB |
Output is correct |
36 |
Correct |
37 ms |
8556 KB |
Output is correct |
37 |
Correct |
83 ms |
16808 KB |
Output is correct |
38 |
Correct |
132 ms |
18284 KB |
Output is correct |
39 |
Correct |
192 ms |
24896 KB |
Output is correct |
40 |
Correct |
259 ms |
32004 KB |
Output is correct |
41 |
Correct |
322 ms |
38412 KB |
Output is correct |
42 |
Correct |
377 ms |
45108 KB |
Output is correct |
43 |
Correct |
1 ms |
212 KB |
Output is correct |
44 |
Correct |
0 ms |
300 KB |
Output is correct |
45 |
Correct |
1 ms |
212 KB |
Output is correct |
46 |
Correct |
0 ms |
212 KB |
Output is correct |
47 |
Correct |
0 ms |
212 KB |
Output is correct |
48 |
Correct |
0 ms |
212 KB |
Output is correct |
49 |
Correct |
1 ms |
212 KB |
Output is correct |
50 |
Correct |
0 ms |
212 KB |
Output is correct |
51 |
Correct |
1 ms |
212 KB |
Output is correct |
52 |
Correct |
0 ms |
212 KB |
Output is correct |
53 |
Correct |
1 ms |
212 KB |
Output is correct |
54 |
Correct |
2 ms |
596 KB |
Output is correct |
55 |
Correct |
2 ms |
724 KB |
Output is correct |
56 |
Correct |
139 ms |
24144 KB |
Output is correct |
57 |
Correct |
215 ms |
35068 KB |
Output is correct |
58 |
Correct |
211 ms |
34892 KB |
Output is correct |
59 |
Correct |
1 ms |
212 KB |
Output is correct |
60 |
Correct |
1 ms |
300 KB |
Output is correct |
61 |
Correct |
1 ms |
212 KB |
Output is correct |
62 |
Correct |
337 ms |
48632 KB |
Output is correct |
63 |
Correct |
336 ms |
48816 KB |
Output is correct |
64 |
Correct |
327 ms |
49220 KB |
Output is correct |
65 |
Correct |
3 ms |
948 KB |
Output is correct |
66 |
Correct |
6 ms |
1608 KB |
Output is correct |
67 |
Correct |
145 ms |
23236 KB |
Output is correct |
68 |
Correct |
226 ms |
35632 KB |
Output is correct |
69 |
Correct |
320 ms |
46316 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
1 ms |
212 KB |
Output is correct |
3 |
Correct |
0 ms |
296 KB |
Output is correct |
4 |
Correct |
0 ms |
300 KB |
Output is correct |
5 |
Correct |
0 ms |
212 KB |
Output is correct |
6 |
Correct |
0 ms |
300 KB |
Output is correct |
7 |
Correct |
1 ms |
300 KB |
Output is correct |
8 |
Correct |
1 ms |
212 KB |
Output is correct |
9 |
Correct |
151 ms |
25104 KB |
Output is correct |
10 |
Correct |
11 ms |
2764 KB |
Output is correct |
11 |
Correct |
71 ms |
13748 KB |
Output is correct |
12 |
Correct |
18 ms |
4024 KB |
Output is correct |
13 |
Correct |
23 ms |
8260 KB |
Output is correct |
14 |
Correct |
1 ms |
340 KB |
Output is correct |
15 |
Correct |
2 ms |
596 KB |
Output is correct |
16 |
Correct |
152 ms |
23784 KB |
Output is correct |
17 |
Correct |
329 ms |
50876 KB |
Output is correct |
18 |
Correct |
298 ms |
50368 KB |
Output is correct |
19 |
Correct |
351 ms |
51168 KB |
Output is correct |
20 |
Correct |
399 ms |
54640 KB |
Output is correct |
21 |
Correct |
306 ms |
43580 KB |
Output is correct |
22 |
Correct |
0 ms |
212 KB |
Output is correct |
23 |
Correct |
55 ms |
7800 KB |
Output is correct |
24 |
Correct |
20 ms |
3988 KB |
Output is correct |
25 |
Correct |
63 ms |
12864 KB |
Output is correct |
26 |
Correct |
110 ms |
21816 KB |
Output is correct |
27 |
Correct |
200 ms |
26452 KB |
Output is correct |
28 |
Correct |
257 ms |
33300 KB |
Output is correct |
29 |
Correct |
327 ms |
39684 KB |
Output is correct |
30 |
Correct |
373 ms |
46200 KB |
Output is correct |
31 |
Correct |
429 ms |
52784 KB |
Output is correct |
32 |
Correct |
395 ms |
54348 KB |
Output is correct |
33 |
Correct |
340 ms |
50652 KB |
Output is correct |
34 |
Correct |
4 ms |
1108 KB |
Output is correct |
35 |
Correct |
6 ms |
1812 KB |
Output is correct |
36 |
Correct |
155 ms |
24812 KB |
Output is correct |
37 |
Correct |
244 ms |
37416 KB |
Output is correct |
38 |
Correct |
340 ms |
49716 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
1 ms |
212 KB |
Output is correct |
3 |
Correct |
0 ms |
296 KB |
Output is correct |
4 |
Correct |
0 ms |
300 KB |
Output is correct |
5 |
Correct |
0 ms |
212 KB |
Output is correct |
6 |
Correct |
0 ms |
300 KB |
Output is correct |
7 |
Correct |
1 ms |
300 KB |
Output is correct |
8 |
Correct |
1 ms |
212 KB |
Output is correct |
9 |
Correct |
151 ms |
25104 KB |
Output is correct |
10 |
Correct |
11 ms |
2764 KB |
Output is correct |
11 |
Correct |
71 ms |
13748 KB |
Output is correct |
12 |
Correct |
18 ms |
4024 KB |
Output is correct |
13 |
Correct |
23 ms |
8260 KB |
Output is correct |
14 |
Correct |
1 ms |
340 KB |
Output is correct |
15 |
Correct |
2 ms |
596 KB |
Output is correct |
16 |
Correct |
152 ms |
23784 KB |
Output is correct |
17 |
Incorrect |
0 ms |
212 KB |
Tree @(3, 3) appears more than once: for edges on positions 0 and 2 |
18 |
Halted |
0 ms |
0 KB |
- |