#include "parks.h"
#include<bits/stdc++.h>
#pragma GCC optimize("unroll-loops" , "O3")
#pragma GCC target("avx2")
using namespace std;
vector<vector<int>> adj;
vector<bool> vis;
void dfs(int i)
{
if(vis[i])
return;
vis[i] = 1;
for(auto j : adj[i])
{
dfs(j);
}
}
void add_edge(int u , int v)
{
adj[u].push_back(v);
adj[v].push_back(u);
}
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
int construct_roads(std::vector<int> x, std::vector<int> y) {
int n= (int)x.size();
adj.assign(n , {});
vis.assign(n , 0);
vector<int> u , v , a , b;
map<pair<int, int> , int> idx;
set<pair<int ,int>> taken;
for(int i = 0 ; i <n ; i++)
{
idx[{x[i] , y[i]}] = i;
}
vector<pair<int ,int>> vv;
for(int i = 0 ; i < n ; i++)
vv.push_back({x[i] , y[i]});
sort(vv.begin() , vv.end());
int cnt = 10;
while(cnt--)
{
u.clear();
v.clear();
a.clear();
b.clear();
taken.clear();
adj.assign(n , {});
vis.assign(n ,0);
for(int i = 0 ; i < n ;i++)
{
x[i] = vv[i].first , y[i] = vv[i].second;
}
bool acc = 1;
for(int i = 0 ; i < n ;i++)
{
if(idx.count({x[i] + 2 , y[i]}))
{
if(!taken.count({x[i] + 1 , y[i] - 1}))
{
u.push_back(idx[{x[i] , y[i]}]);
v.push_back(idx[{x[i] + 2 , y[i]}]);
a.push_back(x[i] + 1);
b.push_back(y[i] - 1);
taken.insert({x[i] + 1 , y[i] - 1});
}
else if(!taken.count({x[i] + 1 , y[i] + 1}))
{
u.push_back(idx[{x[i] , y[i]}]);
v.push_back(idx[{x[i] + 2 , y[i]}]);
a.push_back(x[i] + 1);
b.push_back(y[i] + 1);
taken.insert({x[i] + 1 , y[i] + 1});
}
}
if(idx.count({x[i] , y[i] + 2}))
{
if(!taken.count({x[i] - 1 , y[i] + 1}))
{
u.push_back(idx[{x[i] , y[i]}]);
v.push_back(idx[{x[i] , y[i] + 2}]);
b.push_back(y[i] + 1);
a.push_back(x[i] - 1);
taken.insert({x[i] - 1 , y[i] +1});
}
else if(!taken.count({x[i] + 1 , y[i] + 1}))
{
u.push_back(idx[{x[i] , y[i]}]);
v.push_back(idx[{x[i] , y[i] + 2}]);
b.push_back(y[i] + 1);
a.push_back(x[i] + 1);
taken.insert({x[i] + 1 , y[i] +1});
}
}
}
for(int i = 0 ; i < (int)u.size() ; i++)
{
add_edge(u[i] , v[i]);
}
dfs(0);
for(int i = 0 ; i < n ; i++)
{
if(!vis[i])
{
acc = 0;
break;
}
}
if(!acc)
{
shuffle(vv.begin() , vv.end() , rng);
continue;
}
build(u , v , a , b);
return 1;
}
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 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 |
424 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 |
348 KB |
Output is correct |
9 |
Correct |
99 ms |
26200 KB |
Output is correct |
10 |
Correct |
11 ms |
3164 KB |
Output is correct |
11 |
Correct |
48 ms |
14272 KB |
Output is correct |
12 |
Correct |
12 ms |
4536 KB |
Output is correct |
13 |
Correct |
326 ms |
10100 KB |
Output is correct |
14 |
Correct |
4 ms |
604 KB |
Output is correct |
15 |
Correct |
8 ms |
604 KB |
Output is correct |
16 |
Correct |
103 ms |
25276 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 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 |
424 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 |
348 KB |
Output is correct |
9 |
Correct |
99 ms |
26200 KB |
Output is correct |
10 |
Correct |
11 ms |
3164 KB |
Output is correct |
11 |
Correct |
48 ms |
14272 KB |
Output is correct |
12 |
Correct |
12 ms |
4536 KB |
Output is correct |
13 |
Correct |
326 ms |
10100 KB |
Output is correct |
14 |
Correct |
4 ms |
604 KB |
Output is correct |
15 |
Correct |
8 ms |
604 KB |
Output is correct |
16 |
Correct |
103 ms |
25276 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 |
313 ms |
60940 KB |
Output is correct |
24 |
Correct |
0 ms |
356 KB |
Output is correct |
25 |
Correct |
1 ms |
700 KB |
Output is correct |
26 |
Correct |
18 ms |
1208 KB |
Output is correct |
27 |
Correct |
24 ms |
1372 KB |
Output is correct |
28 |
Correct |
105 ms |
25480 KB |
Output is correct |
29 |
Correct |
166 ms |
36808 KB |
Output is correct |
30 |
Correct |
246 ms |
51184 KB |
Output is correct |
31 |
Correct |
317 ms |
60616 KB |
Output is correct |
32 |
Correct |
0 ms |
348 KB |
Output is correct |
33 |
Correct |
0 ms |
348 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 |
348 KB |
Output is correct |
42 |
Correct |
0 ms |
348 KB |
Output is correct |
43 |
Correct |
8 ms |
860 KB |
Output is correct |
44 |
Correct |
13 ms |
860 KB |
Output is correct |
45 |
Correct |
105 ms |
25508 KB |
Output is correct |
46 |
Correct |
157 ms |
37400 KB |
Output is correct |
47 |
Correct |
157 ms |
37348 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 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 |
424 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 |
348 KB |
Output is correct |
9 |
Correct |
99 ms |
26200 KB |
Output is correct |
10 |
Correct |
11 ms |
3164 KB |
Output is correct |
11 |
Correct |
48 ms |
14272 KB |
Output is correct |
12 |
Correct |
12 ms |
4536 KB |
Output is correct |
13 |
Correct |
326 ms |
10100 KB |
Output is correct |
14 |
Correct |
4 ms |
604 KB |
Output is correct |
15 |
Correct |
8 ms |
604 KB |
Output is correct |
16 |
Correct |
103 ms |
25276 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 |
313 ms |
60940 KB |
Output is correct |
24 |
Correct |
0 ms |
356 KB |
Output is correct |
25 |
Correct |
1 ms |
700 KB |
Output is correct |
26 |
Correct |
18 ms |
1208 KB |
Output is correct |
27 |
Correct |
24 ms |
1372 KB |
Output is correct |
28 |
Correct |
105 ms |
25480 KB |
Output is correct |
29 |
Correct |
166 ms |
36808 KB |
Output is correct |
30 |
Correct |
246 ms |
51184 KB |
Output is correct |
31 |
Correct |
317 ms |
60616 KB |
Output is correct |
32 |
Correct |
0 ms |
348 KB |
Output is correct |
33 |
Correct |
0 ms |
348 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 |
348 KB |
Output is correct |
42 |
Correct |
0 ms |
348 KB |
Output is correct |
43 |
Correct |
8 ms |
860 KB |
Output is correct |
44 |
Correct |
13 ms |
860 KB |
Output is correct |
45 |
Correct |
105 ms |
25508 KB |
Output is correct |
46 |
Correct |
157 ms |
37400 KB |
Output is correct |
47 |
Correct |
157 ms |
37348 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 |
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 |
0 ms |
348 KB |
Output is correct |
55 |
Correct |
304 ms |
56416 KB |
Output is correct |
56 |
Correct |
1 ms |
344 KB |
Output is correct |
57 |
Correct |
2 ms |
860 KB |
Output is correct |
58 |
Correct |
7 ms |
2140 KB |
Output is correct |
59 |
Correct |
78 ms |
2648 KB |
Output is correct |
60 |
Correct |
136 ms |
29280 KB |
Output is correct |
61 |
Correct |
194 ms |
40056 KB |
Output is correct |
62 |
Correct |
241 ms |
48284 KB |
Output is correct |
63 |
Correct |
309 ms |
57300 KB |
Output is correct |
64 |
Correct |
0 ms |
344 KB |
Output is correct |
65 |
Correct |
0 ms |
344 KB |
Output is correct |
66 |
Correct |
0 ms |
348 KB |
Output is correct |
67 |
Correct |
235 ms |
51456 KB |
Output is correct |
68 |
Correct |
244 ms |
51588 KB |
Output is correct |
69 |
Correct |
237 ms |
51624 KB |
Output is correct |
70 |
Correct |
21 ms |
1112 KB |
Output is correct |
71 |
Correct |
43 ms |
1884 KB |
Output is correct |
72 |
Correct |
101 ms |
24992 KB |
Output is correct |
73 |
Correct |
183 ms |
38288 KB |
Output is correct |
74 |
Correct |
236 ms |
50056 KB |
Output is correct |
75 |
Correct |
260 ms |
56088 KB |
Output is correct |
76 |
Correct |
238 ms |
52616 KB |
Output is correct |
77 |
Correct |
27 ms |
1372 KB |
Output is correct |
78 |
Correct |
59 ms |
2392 KB |
Output is correct |
79 |
Correct |
116 ms |
26292 KB |
Output is correct |
80 |
Correct |
173 ms |
39824 KB |
Output is correct |
81 |
Correct |
253 ms |
53260 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 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 |
424 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 |
348 KB |
Output is correct |
9 |
Correct |
99 ms |
26200 KB |
Output is correct |
10 |
Correct |
11 ms |
3164 KB |
Output is correct |
11 |
Correct |
48 ms |
14272 KB |
Output is correct |
12 |
Correct |
12 ms |
4536 KB |
Output is correct |
13 |
Correct |
326 ms |
10100 KB |
Output is correct |
14 |
Correct |
4 ms |
604 KB |
Output is correct |
15 |
Correct |
8 ms |
604 KB |
Output is correct |
16 |
Correct |
103 ms |
25276 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 |
252 ms |
53264 KB |
Output is correct |
21 |
Correct |
239 ms |
52356 KB |
Output is correct |
22 |
Correct |
256 ms |
52120 KB |
Output is correct |
23 |
Correct |
198 ms |
44116 KB |
Output is correct |
24 |
Correct |
689 ms |
23136 KB |
Output is correct |
25 |
Correct |
2573 ms |
41164 KB |
Output is correct |
26 |
Correct |
2506 ms |
41196 KB |
Output is correct |
27 |
Correct |
229 ms |
48656 KB |
Output is correct |
28 |
Correct |
241 ms |
48572 KB |
Output is correct |
29 |
Correct |
261 ms |
48776 KB |
Output is correct |
30 |
Correct |
255 ms |
48776 KB |
Output is correct |
31 |
Correct |
0 ms |
348 KB |
Output is correct |
32 |
Incorrect |
98 ms |
3348 KB |
Solution announced impossible, but it is possible. |
33 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 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 |
424 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 |
348 KB |
Output is correct |
9 |
Correct |
99 ms |
26200 KB |
Output is correct |
10 |
Correct |
11 ms |
3164 KB |
Output is correct |
11 |
Correct |
48 ms |
14272 KB |
Output is correct |
12 |
Correct |
12 ms |
4536 KB |
Output is correct |
13 |
Correct |
326 ms |
10100 KB |
Output is correct |
14 |
Correct |
4 ms |
604 KB |
Output is correct |
15 |
Correct |
8 ms |
604 KB |
Output is correct |
16 |
Correct |
103 ms |
25276 KB |
Output is correct |
17 |
Correct |
244 ms |
52868 KB |
Output is correct |
18 |
Correct |
236 ms |
52752 KB |
Output is correct |
19 |
Correct |
253 ms |
52104 KB |
Output is correct |
20 |
Correct |
268 ms |
57444 KB |
Output is correct |
21 |
Correct |
222 ms |
46788 KB |
Output is correct |
22 |
Correct |
0 ms |
348 KB |
Output is correct |
23 |
Incorrect |
267 ms |
7160 KB |
Solution announced impossible, but it is possible. |
24 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 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 |
424 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 |
348 KB |
Output is correct |
9 |
Correct |
99 ms |
26200 KB |
Output is correct |
10 |
Correct |
11 ms |
3164 KB |
Output is correct |
11 |
Correct |
48 ms |
14272 KB |
Output is correct |
12 |
Correct |
12 ms |
4536 KB |
Output is correct |
13 |
Correct |
326 ms |
10100 KB |
Output is correct |
14 |
Correct |
4 ms |
604 KB |
Output is correct |
15 |
Correct |
8 ms |
604 KB |
Output is correct |
16 |
Correct |
103 ms |
25276 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 |
313 ms |
60940 KB |
Output is correct |
24 |
Correct |
0 ms |
356 KB |
Output is correct |
25 |
Correct |
1 ms |
700 KB |
Output is correct |
26 |
Correct |
18 ms |
1208 KB |
Output is correct |
27 |
Correct |
24 ms |
1372 KB |
Output is correct |
28 |
Correct |
105 ms |
25480 KB |
Output is correct |
29 |
Correct |
166 ms |
36808 KB |
Output is correct |
30 |
Correct |
246 ms |
51184 KB |
Output is correct |
31 |
Correct |
317 ms |
60616 KB |
Output is correct |
32 |
Correct |
0 ms |
348 KB |
Output is correct |
33 |
Correct |
0 ms |
348 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 |
348 KB |
Output is correct |
42 |
Correct |
0 ms |
348 KB |
Output is correct |
43 |
Correct |
8 ms |
860 KB |
Output is correct |
44 |
Correct |
13 ms |
860 KB |
Output is correct |
45 |
Correct |
105 ms |
25508 KB |
Output is correct |
46 |
Correct |
157 ms |
37400 KB |
Output is correct |
47 |
Correct |
157 ms |
37348 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 |
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 |
0 ms |
348 KB |
Output is correct |
55 |
Correct |
304 ms |
56416 KB |
Output is correct |
56 |
Correct |
1 ms |
344 KB |
Output is correct |
57 |
Correct |
2 ms |
860 KB |
Output is correct |
58 |
Correct |
7 ms |
2140 KB |
Output is correct |
59 |
Correct |
78 ms |
2648 KB |
Output is correct |
60 |
Correct |
136 ms |
29280 KB |
Output is correct |
61 |
Correct |
194 ms |
40056 KB |
Output is correct |
62 |
Correct |
241 ms |
48284 KB |
Output is correct |
63 |
Correct |
309 ms |
57300 KB |
Output is correct |
64 |
Correct |
0 ms |
344 KB |
Output is correct |
65 |
Correct |
0 ms |
344 KB |
Output is correct |
66 |
Correct |
0 ms |
348 KB |
Output is correct |
67 |
Correct |
235 ms |
51456 KB |
Output is correct |
68 |
Correct |
244 ms |
51588 KB |
Output is correct |
69 |
Correct |
237 ms |
51624 KB |
Output is correct |
70 |
Correct |
21 ms |
1112 KB |
Output is correct |
71 |
Correct |
43 ms |
1884 KB |
Output is correct |
72 |
Correct |
101 ms |
24992 KB |
Output is correct |
73 |
Correct |
183 ms |
38288 KB |
Output is correct |
74 |
Correct |
236 ms |
50056 KB |
Output is correct |
75 |
Correct |
260 ms |
56088 KB |
Output is correct |
76 |
Correct |
238 ms |
52616 KB |
Output is correct |
77 |
Correct |
27 ms |
1372 KB |
Output is correct |
78 |
Correct |
59 ms |
2392 KB |
Output is correct |
79 |
Correct |
116 ms |
26292 KB |
Output is correct |
80 |
Correct |
173 ms |
39824 KB |
Output is correct |
81 |
Correct |
253 ms |
53260 KB |
Output is correct |
82 |
Correct |
0 ms |
348 KB |
Output is correct |
83 |
Correct |
0 ms |
348 KB |
Output is correct |
84 |
Correct |
0 ms |
348 KB |
Output is correct |
85 |
Correct |
252 ms |
53264 KB |
Output is correct |
86 |
Correct |
239 ms |
52356 KB |
Output is correct |
87 |
Correct |
256 ms |
52120 KB |
Output is correct |
88 |
Correct |
198 ms |
44116 KB |
Output is correct |
89 |
Correct |
689 ms |
23136 KB |
Output is correct |
90 |
Correct |
2573 ms |
41164 KB |
Output is correct |
91 |
Correct |
2506 ms |
41196 KB |
Output is correct |
92 |
Correct |
229 ms |
48656 KB |
Output is correct |
93 |
Correct |
241 ms |
48572 KB |
Output is correct |
94 |
Correct |
261 ms |
48776 KB |
Output is correct |
95 |
Correct |
255 ms |
48776 KB |
Output is correct |
96 |
Correct |
0 ms |
348 KB |
Output is correct |
97 |
Incorrect |
98 ms |
3348 KB |
Solution announced impossible, but it is possible. |
98 |
Halted |
0 ms |
0 KB |
- |