#include "parks.h"
#include <bits/stdc++.h>
using namespace std;
int construct_roads(vector<int> x,vector<int> y){
int n = x.size();
map<pair<int,int>,int> lookup;
for(int i=0;i<n;i++)lookup[{x[i],y[i]}]=i;
vector<int> u,v,a,b;
vector<vector<int>> adj(n);
for(int i=0;i<n;i++){
if(lookup[{x[i]+2,y[i]}]>i){
u.emplace_back(i);
v.emplace_back(lookup[{x[i]+2,y[i]}]);
adj[i].emplace_back(lookup[{x[i]+2,y[i]}]);
adj[lookup[{x[i]+2,y[i]}]].emplace_back(i);
a.emplace_back(x[i]+1);
b.emplace_back(y[i]-1);
}
if(lookup[{x[i]-2,y[i]}]>i){
u.emplace_back(i);
v.emplace_back(lookup[{x[i]-2,y[i]}]);
adj[i].emplace_back(lookup[{x[i]-2,y[i]}]);
adj[lookup[{x[i]-2,y[i]}]].emplace_back(i);
a.emplace_back(x[i]-1);
b.emplace_back(y[i]-1);
}
if(lookup[{x[i],y[i]+2}]>i){
u.emplace_back(i);
v.emplace_back(lookup[{x[i],y[i]+2}]);
adj[i].emplace_back(lookup[{x[i],y[i]+2}]);
adj[lookup[{x[i],y[i]+2}]].emplace_back(i);
if(x[i]==2)a.emplace_back(x[i]-1);
else a.emplace_back(x[i]+1);
b.emplace_back(y[i]+1);
}
if(lookup[{x[i],y[i]-2}]>i){
u.emplace_back(i);
v.emplace_back(lookup[{x[i],y[i]-2}]);
adj[i].emplace_back(lookup[{x[i],y[i]-2}]);
adj[lookup[{x[i],y[i]-2}]].emplace_back(i);
if(x[i]==2)a.emplace_back(x[i]-1);
else a.emplace_back(x[i]+1);
b.emplace_back(y[i]-1);
}
}
vector<bool> visited(n);
int vis = 0;
function<void(int)> dfs = [&](int x){
if(visited[x])return;
visited[x]=true;
vis++;
for(int&i:adj[x])dfs(i);
};
dfs(0);
if(vis!=n)return 0;
build(u,v,a,b);
return 1;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
344 KB |
Output is correct |
2 |
Correct |
1 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 |
1 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 |
197 ms |
37540 KB |
Output is correct |
10 |
Correct |
9 ms |
4188 KB |
Output is correct |
11 |
Correct |
62 ms |
20680 KB |
Output is correct |
12 |
Correct |
15 ms |
5976 KB |
Output is correct |
13 |
Correct |
46 ms |
14788 KB |
Output is correct |
14 |
Correct |
1 ms |
604 KB |
Output is correct |
15 |
Correct |
2 ms |
860 KB |
Output is correct |
16 |
Correct |
210 ms |
34808 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
344 KB |
Output is correct |
2 |
Correct |
1 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 |
1 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 |
197 ms |
37540 KB |
Output is correct |
10 |
Correct |
9 ms |
4188 KB |
Output is correct |
11 |
Correct |
62 ms |
20680 KB |
Output is correct |
12 |
Correct |
15 ms |
5976 KB |
Output is correct |
13 |
Correct |
46 ms |
14788 KB |
Output is correct |
14 |
Correct |
1 ms |
604 KB |
Output is correct |
15 |
Correct |
2 ms |
860 KB |
Output is correct |
16 |
Correct |
210 ms |
34808 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 |
562 ms |
64532 KB |
Output is correct |
24 |
Correct |
0 ms |
344 KB |
Output is correct |
25 |
Correct |
2 ms |
604 KB |
Output is correct |
26 |
Correct |
3 ms |
1116 KB |
Output is correct |
27 |
Correct |
5 ms |
1372 KB |
Output is correct |
28 |
Correct |
164 ms |
26292 KB |
Output is correct |
29 |
Correct |
262 ms |
38056 KB |
Output is correct |
30 |
Correct |
428 ms |
51968 KB |
Output is correct |
31 |
Correct |
584 ms |
63640 KB |
Output is correct |
32 |
Correct |
0 ms |
344 KB |
Output is correct |
33 |
Correct |
0 ms |
432 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 |
344 KB |
Output is correct |
42 |
Correct |
0 ms |
348 KB |
Output is correct |
43 |
Correct |
2 ms |
860 KB |
Output is correct |
44 |
Correct |
3 ms |
1116 KB |
Output is correct |
45 |
Correct |
199 ms |
31636 KB |
Output is correct |
46 |
Correct |
325 ms |
46248 KB |
Output is correct |
47 |
Correct |
369 ms |
45736 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
344 KB |
Output is correct |
2 |
Correct |
1 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 |
1 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 |
197 ms |
37540 KB |
Output is correct |
10 |
Correct |
9 ms |
4188 KB |
Output is correct |
11 |
Correct |
62 ms |
20680 KB |
Output is correct |
12 |
Correct |
15 ms |
5976 KB |
Output is correct |
13 |
Correct |
46 ms |
14788 KB |
Output is correct |
14 |
Correct |
1 ms |
604 KB |
Output is correct |
15 |
Correct |
2 ms |
860 KB |
Output is correct |
16 |
Correct |
210 ms |
34808 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 |
562 ms |
64532 KB |
Output is correct |
24 |
Correct |
0 ms |
344 KB |
Output is correct |
25 |
Correct |
2 ms |
604 KB |
Output is correct |
26 |
Correct |
3 ms |
1116 KB |
Output is correct |
27 |
Correct |
5 ms |
1372 KB |
Output is correct |
28 |
Correct |
164 ms |
26292 KB |
Output is correct |
29 |
Correct |
262 ms |
38056 KB |
Output is correct |
30 |
Correct |
428 ms |
51968 KB |
Output is correct |
31 |
Correct |
584 ms |
63640 KB |
Output is correct |
32 |
Correct |
0 ms |
344 KB |
Output is correct |
33 |
Correct |
0 ms |
432 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 |
344 KB |
Output is correct |
42 |
Correct |
0 ms |
348 KB |
Output is correct |
43 |
Correct |
2 ms |
860 KB |
Output is correct |
44 |
Correct |
3 ms |
1116 KB |
Output is correct |
45 |
Correct |
199 ms |
31636 KB |
Output is correct |
46 |
Correct |
325 ms |
46248 KB |
Output is correct |
47 |
Correct |
369 ms |
45736 KB |
Output is correct |
48 |
Incorrect |
0 ms |
348 KB |
Tree @(5, 3) appears more than once: for edges on positions 2 and 3 |
49 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
344 KB |
Output is correct |
2 |
Correct |
1 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 |
1 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 |
197 ms |
37540 KB |
Output is correct |
10 |
Correct |
9 ms |
4188 KB |
Output is correct |
11 |
Correct |
62 ms |
20680 KB |
Output is correct |
12 |
Correct |
15 ms |
5976 KB |
Output is correct |
13 |
Correct |
46 ms |
14788 KB |
Output is correct |
14 |
Correct |
1 ms |
604 KB |
Output is correct |
15 |
Correct |
2 ms |
860 KB |
Output is correct |
16 |
Correct |
210 ms |
34808 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 |
462 ms |
63572 KB |
Output is correct |
21 |
Incorrect |
506 ms |
61092 KB |
Tree @(56859, 56863) appears more than once: for edges on positions 0 and 1 |
22 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
344 KB |
Output is correct |
2 |
Correct |
1 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 |
1 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 |
197 ms |
37540 KB |
Output is correct |
10 |
Correct |
9 ms |
4188 KB |
Output is correct |
11 |
Correct |
62 ms |
20680 KB |
Output is correct |
12 |
Correct |
15 ms |
5976 KB |
Output is correct |
13 |
Correct |
46 ms |
14788 KB |
Output is correct |
14 |
Correct |
1 ms |
604 KB |
Output is correct |
15 |
Correct |
2 ms |
860 KB |
Output is correct |
16 |
Correct |
210 ms |
34808 KB |
Output is correct |
17 |
Correct |
529 ms |
75940 KB |
Output is correct |
18 |
Incorrect |
543 ms |
71076 KB |
Tree @(50003, 100001) appears more than once: for edges on positions 157198 and 161590 |
19 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
344 KB |
Output is correct |
2 |
Correct |
1 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 |
1 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 |
197 ms |
37540 KB |
Output is correct |
10 |
Correct |
9 ms |
4188 KB |
Output is correct |
11 |
Correct |
62 ms |
20680 KB |
Output is correct |
12 |
Correct |
15 ms |
5976 KB |
Output is correct |
13 |
Correct |
46 ms |
14788 KB |
Output is correct |
14 |
Correct |
1 ms |
604 KB |
Output is correct |
15 |
Correct |
2 ms |
860 KB |
Output is correct |
16 |
Correct |
210 ms |
34808 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 |
562 ms |
64532 KB |
Output is correct |
24 |
Correct |
0 ms |
344 KB |
Output is correct |
25 |
Correct |
2 ms |
604 KB |
Output is correct |
26 |
Correct |
3 ms |
1116 KB |
Output is correct |
27 |
Correct |
5 ms |
1372 KB |
Output is correct |
28 |
Correct |
164 ms |
26292 KB |
Output is correct |
29 |
Correct |
262 ms |
38056 KB |
Output is correct |
30 |
Correct |
428 ms |
51968 KB |
Output is correct |
31 |
Correct |
584 ms |
63640 KB |
Output is correct |
32 |
Correct |
0 ms |
344 KB |
Output is correct |
33 |
Correct |
0 ms |
432 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 |
344 KB |
Output is correct |
42 |
Correct |
0 ms |
348 KB |
Output is correct |
43 |
Correct |
2 ms |
860 KB |
Output is correct |
44 |
Correct |
3 ms |
1116 KB |
Output is correct |
45 |
Correct |
199 ms |
31636 KB |
Output is correct |
46 |
Correct |
325 ms |
46248 KB |
Output is correct |
47 |
Correct |
369 ms |
45736 KB |
Output is correct |
48 |
Incorrect |
0 ms |
348 KB |
Tree @(5, 3) appears more than once: for edges on positions 2 and 3 |
49 |
Halted |
0 ms |
0 KB |
- |