#include "parks.h"
#include <bits/stdc++.h>
using namespace std;
struct dsu {
vector<int> e;
int cc=0;
dsu(int n) {
e=vector<int>(n, -1);
cc=n;
}
int get(int x) {
if(e[x]<0)return x;
return e[x]=get(e[x]);
}
bool unite(int x, int y) {
x=get(x),y=get(y);
if(x==y)return false;
if(-e[x] < -e[y]){
swap(x, y);
}
cc--;
e[x]+=e[y];
e[y] = x;
return true;
}
};
int construct_roads(vector<int> x, vector<int> y) {
vector<pair<int,int>> bc;
int n = x.size();
dsu d(n);
map<pair<int,int>, int> mp;
for(int i = 0;i<n;i++) {
mp[{x[i], y[i]}] = i;
bc.push_back({x[i]-1, y[i]-1});
bc.push_back({x[i]-1, y[i]+1});
bc.push_back({x[i]+1, y[i]-1});
bc.push_back({x[i]+1, y[i]+1});
}
vector<int> a, b, c, D;
for(auto [u,v]:bc) {
if((u+v)%4 == 2) {
if(mp.find(pair{u-1, v+1})!=mp.end() and mp.find(pair{u+1, v+1}) != mp.end() and d.unite(mp[{u-1, v+1}], mp[{u+1, v+1}])) {
a.push_back(mp[{u-1, v+1}]);
b.push_back(mp[{u+1, v+1}]);
c.push_back(u);
D.push_back(v);
}
else if(mp.find(pair{u-1, v-1})!=mp.end() and mp.find(pair{u+1, v-1}) != mp.end() and d.unite(mp[{u-1, v-1}], mp[{u+1, v-1}])) {
a.push_back(mp[{u-1, v-1}]);
b.push_back(mp[{u+1, v-1}]);
c.push_back(u);
D.push_back(v);
}
}
else {
if(mp.find(pair{u+1, v+1})!=mp.end() and mp.find(pair{u+1, v-1}) != mp.end() and d.unite(mp[{u+1, v+1}], mp[{u+1, v-1}])) {
a.push_back(mp[{u+1, v+1}]);
b.push_back(mp[{u+1, v-1}]);
c.push_back(u);
D.push_back(v);
}
else if(mp.find(pair{u-1, v-1})!=mp.end() and mp.find(pair{u-1, v+1}) != mp.end() and d.unite(mp[{u-1, v-1}], mp[{u-1, v+1}])) {
a.push_back(mp[{u-1, v-1}]);
b.push_back(mp[{u-1, v+1}]);
c.push_back(u);
D.push_back(v);
}
}
}
if(d.cc!=1)return false;
build(a, b, c, D);
return true;
}
# |
결과 |
실행 시간 |
메모리 |
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 |
432 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 |
166 ms |
18124 KB |
Output is correct |
10 |
Correct |
11 ms |
2000 KB |
Output is correct |
11 |
Correct |
70 ms |
9412 KB |
Output is correct |
12 |
Correct |
16 ms |
2768 KB |
Output is correct |
13 |
Correct |
51 ms |
7108 KB |
Output is correct |
14 |
Correct |
1 ms |
348 KB |
Output is correct |
15 |
Correct |
2 ms |
604 KB |
Output is correct |
16 |
Correct |
166 ms |
17488 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 |
432 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 |
166 ms |
18124 KB |
Output is correct |
10 |
Correct |
11 ms |
2000 KB |
Output is correct |
11 |
Correct |
70 ms |
9412 KB |
Output is correct |
12 |
Correct |
16 ms |
2768 KB |
Output is correct |
13 |
Correct |
51 ms |
7108 KB |
Output is correct |
14 |
Correct |
1 ms |
348 KB |
Output is correct |
15 |
Correct |
2 ms |
604 KB |
Output is correct |
16 |
Correct |
166 ms |
17488 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 1 and 2 |
19 |
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 |
432 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 |
166 ms |
18124 KB |
Output is correct |
10 |
Correct |
11 ms |
2000 KB |
Output is correct |
11 |
Correct |
70 ms |
9412 KB |
Output is correct |
12 |
Correct |
16 ms |
2768 KB |
Output is correct |
13 |
Correct |
51 ms |
7108 KB |
Output is correct |
14 |
Correct |
1 ms |
348 KB |
Output is correct |
15 |
Correct |
2 ms |
604 KB |
Output is correct |
16 |
Correct |
166 ms |
17488 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 1 and 2 |
19 |
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 |
432 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 |
166 ms |
18124 KB |
Output is correct |
10 |
Correct |
11 ms |
2000 KB |
Output is correct |
11 |
Correct |
70 ms |
9412 KB |
Output is correct |
12 |
Correct |
16 ms |
2768 KB |
Output is correct |
13 |
Correct |
51 ms |
7108 KB |
Output is correct |
14 |
Correct |
1 ms |
348 KB |
Output is correct |
15 |
Correct |
2 ms |
604 KB |
Output is correct |
16 |
Correct |
166 ms |
17488 KB |
Output is correct |
17 |
Correct |
0 ms |
344 KB |
Output is correct |
18 |
Correct |
0 ms |
348 KB |
Output is correct |
19 |
Correct |
0 ms |
348 KB |
Output is correct |
20 |
Correct |
473 ms |
37440 KB |
Output is correct |
21 |
Correct |
484 ms |
36392 KB |
Output is correct |
22 |
Correct |
486 ms |
35760 KB |
Output is correct |
23 |
Correct |
351 ms |
30644 KB |
Output is correct |
24 |
Correct |
266 ms |
25524 KB |
Output is correct |
25 |
Correct |
492 ms |
31800 KB |
Output is correct |
26 |
Correct |
444 ms |
31164 KB |
Output is correct |
27 |
Correct |
477 ms |
35488 KB |
Output is correct |
28 |
Correct |
492 ms |
36656 KB |
Output is correct |
29 |
Correct |
512 ms |
36016 KB |
Output is correct |
30 |
Correct |
527 ms |
35248 KB |
Output is correct |
31 |
Correct |
1 ms |
344 KB |
Output is correct |
32 |
Correct |
29 ms |
2768 KB |
Output is correct |
33 |
Correct |
112 ms |
13000 KB |
Output is correct |
34 |
Correct |
465 ms |
37364 KB |
Output is correct |
35 |
Correct |
18 ms |
2004 KB |
Output is correct |
36 |
Correct |
106 ms |
8016 KB |
Output is correct |
37 |
Correct |
229 ms |
15800 KB |
Output is correct |
38 |
Correct |
193 ms |
14784 KB |
Output is correct |
39 |
Correct |
276 ms |
19876 KB |
Output is correct |
40 |
Correct |
379 ms |
26800 KB |
Output is correct |
41 |
Correct |
462 ms |
31164 KB |
Output is correct |
42 |
Correct |
555 ms |
36016 KB |
Output is correct |
43 |
Correct |
1 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 |
344 KB |
Output is correct |
48 |
Correct |
0 ms |
436 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 |
3 ms |
600 KB |
Output is correct |
55 |
Correct |
5 ms |
860 KB |
Output is correct |
56 |
Correct |
227 ms |
17508 KB |
Output is correct |
57 |
Correct |
330 ms |
27564 KB |
Output is correct |
58 |
Correct |
323 ms |
26340 KB |
Output is correct |
59 |
Correct |
0 ms |
344 KB |
Output is correct |
60 |
Correct |
0 ms |
344 KB |
Output is correct |
61 |
Correct |
0 ms |
348 KB |
Output is correct |
62 |
Correct |
377 ms |
36016 KB |
Output is correct |
63 |
Correct |
374 ms |
36792 KB |
Output is correct |
64 |
Correct |
380 ms |
35744 KB |
Output is correct |
65 |
Correct |
6 ms |
1112 KB |
Output is correct |
66 |
Correct |
12 ms |
1496 KB |
Output is correct |
67 |
Correct |
216 ms |
17536 KB |
Output is correct |
68 |
Correct |
363 ms |
27060 KB |
Output is correct |
69 |
Correct |
493 ms |
36264 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 |
432 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 |
166 ms |
18124 KB |
Output is correct |
10 |
Correct |
11 ms |
2000 KB |
Output is correct |
11 |
Correct |
70 ms |
9412 KB |
Output is correct |
12 |
Correct |
16 ms |
2768 KB |
Output is correct |
13 |
Correct |
51 ms |
7108 KB |
Output is correct |
14 |
Correct |
1 ms |
348 KB |
Output is correct |
15 |
Correct |
2 ms |
604 KB |
Output is correct |
16 |
Correct |
166 ms |
17488 KB |
Output is correct |
17 |
Correct |
398 ms |
36160 KB |
Output is correct |
18 |
Correct |
411 ms |
37136 KB |
Output is correct |
19 |
Correct |
485 ms |
37308 KB |
Output is correct |
20 |
Correct |
633 ms |
35764 KB |
Output is correct |
21 |
Correct |
466 ms |
31924 KB |
Output is correct |
22 |
Correct |
0 ms |
348 KB |
Output is correct |
23 |
Correct |
69 ms |
5592 KB |
Output is correct |
24 |
Correct |
41 ms |
3536 KB |
Output is correct |
25 |
Correct |
163 ms |
12748 KB |
Output is correct |
26 |
Correct |
305 ms |
18368 KB |
Output is correct |
27 |
Correct |
261 ms |
18872 KB |
Output is correct |
28 |
Correct |
353 ms |
22200 KB |
Output is correct |
29 |
Correct |
469 ms |
28336 KB |
Output is correct |
30 |
Correct |
580 ms |
32432 KB |
Output is correct |
31 |
Correct |
590 ms |
37552 KB |
Output is correct |
32 |
Correct |
563 ms |
36100 KB |
Output is correct |
33 |
Correct |
403 ms |
35704 KB |
Output is correct |
34 |
Correct |
7 ms |
1148 KB |
Output is correct |
35 |
Correct |
14 ms |
1748 KB |
Output is correct |
36 |
Correct |
235 ms |
17596 KB |
Output is correct |
37 |
Correct |
401 ms |
27636 KB |
Output is correct |
38 |
Correct |
587 ms |
36288 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 |
432 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 |
166 ms |
18124 KB |
Output is correct |
10 |
Correct |
11 ms |
2000 KB |
Output is correct |
11 |
Correct |
70 ms |
9412 KB |
Output is correct |
12 |
Correct |
16 ms |
2768 KB |
Output is correct |
13 |
Correct |
51 ms |
7108 KB |
Output is correct |
14 |
Correct |
1 ms |
348 KB |
Output is correct |
15 |
Correct |
2 ms |
604 KB |
Output is correct |
16 |
Correct |
166 ms |
17488 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 1 and 2 |
19 |
Halted |
0 ms |
0 KB |
- |