#include "parks.h"
#include <bits/stdc++.h>
using namespace std;
map<pair<int, int>, int> M, M2;
vector<int> adj[200000];
bool counting[200000];
vector<pair<int, int>> E;
int cnt = 0;
void count_fountains(int x)
{
cnt++;
counting[x] = true;
for(int i : adj[x])
{
if(counting[i]) continue;
count_fountains(i);
E.push_back({x, i});
}
}
int construct_roads(vector<int> x, vector<int> y) {
if (x.size() == 1) {
build({}, {}, {}, {});
return 1;
}
int n = x.size();
vector<int> u, v, a, b;
for(int i=0;i<n;i++)
M[{x[i], y[i]}] = i+1;
for(int i=0;i<n;i++)
{
if(M[{x[i]+2, y[i]}]) adj[i].push_back(M[{x[i]+2, y[i]}]-1);
if(M[{x[i], y[i]+2}]) adj[i].push_back(M[{x[i], y[i]+2}]-1);
if(M[{x[i]-2, y[i]}]) adj[i].push_back(M[{x[i]-2, y[i]}]-1);
if(M[{x[i], y[i]-2}]) adj[i].push_back(M[{x[i], y[i]-2}]-1);
}
count_fountains(0);
if(cnt < n) return 0;
for(auto U : E)
{
int i = U.first, j = U.second;
if(y[i] == y[j]) continue;
if(y[i] > y[j]) swap(i, j);
u.push_back(i);
v.push_back(j);
b.push_back(y[i]+1);
if((x[i]+y[i])%4 == 0)
{
a.push_back(x[i]+1);
M2[{x[i]+1, y[i]+1}] = 1;
}
else
{
a.push_back(x[i]-1);
M2[{x[i]-1, y[i]+1}] = 1;
}
}
for(auto U : E)
{
int i = U.first, j = U.second;
if(y[i] != y[j]) continue;
if(x[i] > x[j]) swap(i, j);
u.push_back(i);
v.push_back(j);
a.push_back(x[i]+1);
if(M2[{x[i]+1, y[i]+1}]) b.push_back(y[i]-1);
else b.push_back(y[i]+1);
}
build(u, v, a, b);
return 1;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
3 ms |
4940 KB |
Output is correct |
2 |
Correct |
3 ms |
4940 KB |
Output is correct |
3 |
Correct |
3 ms |
4940 KB |
Output is correct |
4 |
Correct |
3 ms |
4940 KB |
Output is correct |
5 |
Correct |
3 ms |
4940 KB |
Output is correct |
6 |
Correct |
3 ms |
4940 KB |
Output is correct |
7 |
Correct |
3 ms |
4940 KB |
Output is correct |
8 |
Correct |
3 ms |
4940 KB |
Output is correct |
9 |
Correct |
413 ms |
48984 KB |
Output is correct |
10 |
Correct |
30 ms |
9480 KB |
Output is correct |
11 |
Correct |
129 ms |
28932 KB |
Output is correct |
12 |
Correct |
35 ms |
11640 KB |
Output is correct |
13 |
Correct |
78 ms |
18116 KB |
Output is correct |
14 |
Correct |
5 ms |
5196 KB |
Output is correct |
15 |
Correct |
6 ms |
5452 KB |
Output is correct |
16 |
Correct |
397 ms |
45752 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
3 ms |
4940 KB |
Output is correct |
2 |
Correct |
3 ms |
4940 KB |
Output is correct |
3 |
Correct |
3 ms |
4940 KB |
Output is correct |
4 |
Correct |
3 ms |
4940 KB |
Output is correct |
5 |
Correct |
3 ms |
4940 KB |
Output is correct |
6 |
Correct |
3 ms |
4940 KB |
Output is correct |
7 |
Correct |
3 ms |
4940 KB |
Output is correct |
8 |
Correct |
3 ms |
4940 KB |
Output is correct |
9 |
Correct |
413 ms |
48984 KB |
Output is correct |
10 |
Correct |
30 ms |
9480 KB |
Output is correct |
11 |
Correct |
129 ms |
28932 KB |
Output is correct |
12 |
Correct |
35 ms |
11640 KB |
Output is correct |
13 |
Correct |
78 ms |
18116 KB |
Output is correct |
14 |
Correct |
5 ms |
5196 KB |
Output is correct |
15 |
Correct |
6 ms |
5452 KB |
Output is correct |
16 |
Correct |
397 ms |
45752 KB |
Output is correct |
17 |
Correct |
3 ms |
4940 KB |
Output is correct |
18 |
Correct |
3 ms |
4940 KB |
Output is correct |
19 |
Correct |
3 ms |
4940 KB |
Output is correct |
20 |
Incorrect |
3 ms |
4940 KB |
Tree @(3, 7) appears more than once: for edges on positions 2 and 3 |
21 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
3 ms |
4940 KB |
Output is correct |
2 |
Correct |
3 ms |
4940 KB |
Output is correct |
3 |
Correct |
3 ms |
4940 KB |
Output is correct |
4 |
Correct |
3 ms |
4940 KB |
Output is correct |
5 |
Correct |
3 ms |
4940 KB |
Output is correct |
6 |
Correct |
3 ms |
4940 KB |
Output is correct |
7 |
Correct |
3 ms |
4940 KB |
Output is correct |
8 |
Correct |
3 ms |
4940 KB |
Output is correct |
9 |
Correct |
413 ms |
48984 KB |
Output is correct |
10 |
Correct |
30 ms |
9480 KB |
Output is correct |
11 |
Correct |
129 ms |
28932 KB |
Output is correct |
12 |
Correct |
35 ms |
11640 KB |
Output is correct |
13 |
Correct |
78 ms |
18116 KB |
Output is correct |
14 |
Correct |
5 ms |
5196 KB |
Output is correct |
15 |
Correct |
6 ms |
5452 KB |
Output is correct |
16 |
Correct |
397 ms |
45752 KB |
Output is correct |
17 |
Correct |
3 ms |
4940 KB |
Output is correct |
18 |
Correct |
3 ms |
4940 KB |
Output is correct |
19 |
Correct |
3 ms |
4940 KB |
Output is correct |
20 |
Incorrect |
3 ms |
4940 KB |
Tree @(3, 7) appears more than once: for edges on positions 2 and 3 |
21 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
3 ms |
4940 KB |
Output is correct |
2 |
Correct |
3 ms |
4940 KB |
Output is correct |
3 |
Correct |
3 ms |
4940 KB |
Output is correct |
4 |
Correct |
3 ms |
4940 KB |
Output is correct |
5 |
Correct |
3 ms |
4940 KB |
Output is correct |
6 |
Correct |
3 ms |
4940 KB |
Output is correct |
7 |
Correct |
3 ms |
4940 KB |
Output is correct |
8 |
Correct |
3 ms |
4940 KB |
Output is correct |
9 |
Correct |
413 ms |
48984 KB |
Output is correct |
10 |
Correct |
30 ms |
9480 KB |
Output is correct |
11 |
Correct |
129 ms |
28932 KB |
Output is correct |
12 |
Correct |
35 ms |
11640 KB |
Output is correct |
13 |
Correct |
78 ms |
18116 KB |
Output is correct |
14 |
Correct |
5 ms |
5196 KB |
Output is correct |
15 |
Correct |
6 ms |
5452 KB |
Output is correct |
16 |
Correct |
397 ms |
45752 KB |
Output is correct |
17 |
Correct |
3 ms |
4940 KB |
Output is correct |
18 |
Correct |
3 ms |
4940 KB |
Output is correct |
19 |
Correct |
3 ms |
4940 KB |
Output is correct |
20 |
Correct |
864 ms |
82228 KB |
Output is correct |
21 |
Correct |
853 ms |
75988 KB |
Output is correct |
22 |
Correct |
897 ms |
74288 KB |
Output is correct |
23 |
Correct |
759 ms |
76524 KB |
Output is correct |
24 |
Correct |
816 ms |
45676 KB |
Output is correct |
25 |
Correct |
770 ms |
39728 KB |
Output is correct |
26 |
Correct |
782 ms |
39696 KB |
Output is correct |
27 |
Correct |
950 ms |
66152 KB |
Output is correct |
28 |
Correct |
960 ms |
66160 KB |
Output is correct |
29 |
Correct |
959 ms |
66272 KB |
Output is correct |
30 |
Correct |
925 ms |
66124 KB |
Output is correct |
31 |
Correct |
3 ms |
4940 KB |
Output is correct |
32 |
Correct |
41 ms |
9744 KB |
Output is correct |
33 |
Correct |
215 ms |
25220 KB |
Output is correct |
34 |
Correct |
819 ms |
74416 KB |
Output is correct |
35 |
Correct |
21 ms |
6524 KB |
Output is correct |
36 |
Correct |
124 ms |
12940 KB |
Output is correct |
37 |
Correct |
306 ms |
20672 KB |
Output is correct |
38 |
Correct |
317 ms |
27200 KB |
Output is correct |
39 |
Correct |
462 ms |
35360 KB |
Output is correct |
40 |
Correct |
624 ms |
44848 KB |
Output is correct |
41 |
Correct |
819 ms |
52268 KB |
Output is correct |
42 |
Correct |
982 ms |
60476 KB |
Output is correct |
43 |
Correct |
3 ms |
4940 KB |
Output is correct |
44 |
Correct |
3 ms |
4940 KB |
Output is correct |
45 |
Correct |
3 ms |
4940 KB |
Output is correct |
46 |
Correct |
3 ms |
4940 KB |
Output is correct |
47 |
Correct |
3 ms |
4940 KB |
Output is correct |
48 |
Correct |
3 ms |
4940 KB |
Output is correct |
49 |
Correct |
3 ms |
4940 KB |
Output is correct |
50 |
Correct |
3 ms |
4940 KB |
Output is correct |
51 |
Correct |
3 ms |
4940 KB |
Output is correct |
52 |
Correct |
3 ms |
4940 KB |
Output is correct |
53 |
Correct |
3 ms |
4940 KB |
Output is correct |
54 |
Correct |
6 ms |
5452 KB |
Output is correct |
55 |
Correct |
9 ms |
5584 KB |
Output is correct |
56 |
Correct |
423 ms |
41612 KB |
Output is correct |
57 |
Correct |
719 ms |
59684 KB |
Output is correct |
58 |
Correct |
732 ms |
59220 KB |
Output is correct |
59 |
Correct |
3 ms |
4940 KB |
Output is correct |
60 |
Correct |
3 ms |
4940 KB |
Output is correct |
61 |
Correct |
3 ms |
4940 KB |
Output is correct |
62 |
Correct |
1016 ms |
83556 KB |
Output is correct |
63 |
Correct |
1041 ms |
83816 KB |
Output is correct |
64 |
Correct |
997 ms |
85216 KB |
Output is correct |
65 |
Correct |
10 ms |
5836 KB |
Output is correct |
66 |
Correct |
17 ms |
6520 KB |
Output is correct |
67 |
Correct |
409 ms |
37996 KB |
Output is correct |
68 |
Correct |
719 ms |
57324 KB |
Output is correct |
69 |
Correct |
1029 ms |
71552 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
3 ms |
4940 KB |
Output is correct |
2 |
Correct |
3 ms |
4940 KB |
Output is correct |
3 |
Correct |
3 ms |
4940 KB |
Output is correct |
4 |
Correct |
3 ms |
4940 KB |
Output is correct |
5 |
Correct |
3 ms |
4940 KB |
Output is correct |
6 |
Correct |
3 ms |
4940 KB |
Output is correct |
7 |
Correct |
3 ms |
4940 KB |
Output is correct |
8 |
Correct |
3 ms |
4940 KB |
Output is correct |
9 |
Correct |
413 ms |
48984 KB |
Output is correct |
10 |
Correct |
30 ms |
9480 KB |
Output is correct |
11 |
Correct |
129 ms |
28932 KB |
Output is correct |
12 |
Correct |
35 ms |
11640 KB |
Output is correct |
13 |
Correct |
78 ms |
18116 KB |
Output is correct |
14 |
Correct |
5 ms |
5196 KB |
Output is correct |
15 |
Correct |
6 ms |
5452 KB |
Output is correct |
16 |
Correct |
397 ms |
45752 KB |
Output is correct |
17 |
Correct |
954 ms |
94620 KB |
Output is correct |
18 |
Correct |
938 ms |
88712 KB |
Output is correct |
19 |
Correct |
878 ms |
79164 KB |
Output is correct |
20 |
Correct |
875 ms |
62904 KB |
Output is correct |
21 |
Correct |
914 ms |
68748 KB |
Output is correct |
22 |
Correct |
3 ms |
4940 KB |
Output is correct |
23 |
Correct |
91 ms |
14276 KB |
Output is correct |
24 |
Correct |
43 ms |
8388 KB |
Output is correct |
25 |
Correct |
181 ms |
15660 KB |
Output is correct |
26 |
Correct |
384 ms |
22980 KB |
Output is correct |
27 |
Correct |
376 ms |
35968 KB |
Output is correct |
28 |
Correct |
517 ms |
43732 KB |
Output is correct |
29 |
Correct |
669 ms |
52276 KB |
Output is correct |
30 |
Correct |
798 ms |
59488 KB |
Output is correct |
31 |
Correct |
958 ms |
67076 KB |
Output is correct |
32 |
Correct |
1012 ms |
75732 KB |
Output is correct |
33 |
Correct |
1035 ms |
88104 KB |
Output is correct |
34 |
Correct |
11 ms |
5964 KB |
Output is correct |
35 |
Correct |
19 ms |
6848 KB |
Output is correct |
36 |
Correct |
414 ms |
38736 KB |
Output is correct |
37 |
Correct |
787 ms |
57064 KB |
Output is correct |
38 |
Correct |
1079 ms |
72004 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
3 ms |
4940 KB |
Output is correct |
2 |
Correct |
3 ms |
4940 KB |
Output is correct |
3 |
Correct |
3 ms |
4940 KB |
Output is correct |
4 |
Correct |
3 ms |
4940 KB |
Output is correct |
5 |
Correct |
3 ms |
4940 KB |
Output is correct |
6 |
Correct |
3 ms |
4940 KB |
Output is correct |
7 |
Correct |
3 ms |
4940 KB |
Output is correct |
8 |
Correct |
3 ms |
4940 KB |
Output is correct |
9 |
Correct |
413 ms |
48984 KB |
Output is correct |
10 |
Correct |
30 ms |
9480 KB |
Output is correct |
11 |
Correct |
129 ms |
28932 KB |
Output is correct |
12 |
Correct |
35 ms |
11640 KB |
Output is correct |
13 |
Correct |
78 ms |
18116 KB |
Output is correct |
14 |
Correct |
5 ms |
5196 KB |
Output is correct |
15 |
Correct |
6 ms |
5452 KB |
Output is correct |
16 |
Correct |
397 ms |
45752 KB |
Output is correct |
17 |
Correct |
3 ms |
4940 KB |
Output is correct |
18 |
Correct |
3 ms |
4940 KB |
Output is correct |
19 |
Correct |
3 ms |
4940 KB |
Output is correct |
20 |
Incorrect |
3 ms |
4940 KB |
Tree @(3, 7) appears more than once: for edges on positions 2 and 3 |
21 |
Halted |
0 ms |
0 KB |
- |