#include "parks.h"
#include<bits/stdc++.h>
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 = 20;
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(v.begin() , v.end() , rng);
continue;
}
build(u , v , a , b);
return 1;
}
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
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 |
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 |
106 ms |
27260 KB |
Output is correct |
10 |
Correct |
7 ms |
3160 KB |
Output is correct |
11 |
Correct |
60 ms |
14972 KB |
Output is correct |
12 |
Correct |
11 ms |
4700 KB |
Output is correct |
13 |
Correct |
347 ms |
10456 KB |
Output is correct |
14 |
Correct |
5 ms |
600 KB |
Output is correct |
15 |
Correct |
10 ms |
860 KB |
Output is correct |
16 |
Correct |
121 ms |
26024 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 |
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 |
106 ms |
27260 KB |
Output is correct |
10 |
Correct |
7 ms |
3160 KB |
Output is correct |
11 |
Correct |
60 ms |
14972 KB |
Output is correct |
12 |
Correct |
11 ms |
4700 KB |
Output is correct |
13 |
Correct |
347 ms |
10456 KB |
Output is correct |
14 |
Correct |
5 ms |
600 KB |
Output is correct |
15 |
Correct |
10 ms |
860 KB |
Output is correct |
16 |
Correct |
121 ms |
26024 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 |
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 |
322 ms |
63064 KB |
Output is correct |
24 |
Correct |
1 ms |
348 KB |
Output is correct |
25 |
Correct |
2 ms |
600 KB |
Output is correct |
26 |
Correct |
35 ms |
1220 KB |
Output is correct |
27 |
Correct |
30 ms |
1372 KB |
Output is correct |
28 |
Correct |
121 ms |
26436 KB |
Output is correct |
29 |
Correct |
183 ms |
38348 KB |
Output is correct |
30 |
Correct |
237 ms |
53136 KB |
Output is correct |
31 |
Correct |
310 ms |
62612 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 |
12 ms |
868 KB |
Output is correct |
44 |
Correct |
17 ms |
1088 KB |
Output is correct |
45 |
Correct |
108 ms |
26272 KB |
Output is correct |
46 |
Correct |
172 ms |
39012 KB |
Output is correct |
47 |
Correct |
169 ms |
38564 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 |
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 |
106 ms |
27260 KB |
Output is correct |
10 |
Correct |
7 ms |
3160 KB |
Output is correct |
11 |
Correct |
60 ms |
14972 KB |
Output is correct |
12 |
Correct |
11 ms |
4700 KB |
Output is correct |
13 |
Correct |
347 ms |
10456 KB |
Output is correct |
14 |
Correct |
5 ms |
600 KB |
Output is correct |
15 |
Correct |
10 ms |
860 KB |
Output is correct |
16 |
Correct |
121 ms |
26024 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 |
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 |
322 ms |
63064 KB |
Output is correct |
24 |
Correct |
1 ms |
348 KB |
Output is correct |
25 |
Correct |
2 ms |
600 KB |
Output is correct |
26 |
Correct |
35 ms |
1220 KB |
Output is correct |
27 |
Correct |
30 ms |
1372 KB |
Output is correct |
28 |
Correct |
121 ms |
26436 KB |
Output is correct |
29 |
Correct |
183 ms |
38348 KB |
Output is correct |
30 |
Correct |
237 ms |
53136 KB |
Output is correct |
31 |
Correct |
310 ms |
62612 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 |
12 ms |
868 KB |
Output is correct |
44 |
Correct |
17 ms |
1088 KB |
Output is correct |
45 |
Correct |
108 ms |
26272 KB |
Output is correct |
46 |
Correct |
172 ms |
39012 KB |
Output is correct |
47 |
Correct |
169 ms |
38564 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 |
300 ms |
57548 KB |
Output is correct |
56 |
Correct |
0 ms |
344 KB |
Output is correct |
57 |
Correct |
2 ms |
860 KB |
Output is correct |
58 |
Correct |
7 ms |
2112 KB |
Output is correct |
59 |
Correct |
98 ms |
2592 KB |
Output is correct |
60 |
Correct |
157 ms |
30312 KB |
Output is correct |
61 |
Correct |
201 ms |
41220 KB |
Output is correct |
62 |
Correct |
236 ms |
49308 KB |
Output is correct |
63 |
Correct |
358 ms |
58952 KB |
Output is correct |
64 |
Correct |
0 ms |
348 KB |
Output is correct |
65 |
Correct |
0 ms |
348 KB |
Output is correct |
66 |
Correct |
0 ms |
348 KB |
Output is correct |
67 |
Correct |
243 ms |
53168 KB |
Output is correct |
68 |
Correct |
269 ms |
53156 KB |
Output is correct |
69 |
Correct |
272 ms |
53772 KB |
Output is correct |
70 |
Correct |
34 ms |
1248 KB |
Output is correct |
71 |
Correct |
61 ms |
1884 KB |
Output is correct |
72 |
Correct |
129 ms |
25512 KB |
Output is correct |
73 |
Correct |
203 ms |
39180 KB |
Output is correct |
74 |
Correct |
259 ms |
50824 KB |
Output is correct |
75 |
Correct |
310 ms |
58132 KB |
Output is correct |
76 |
Correct |
292 ms |
54916 KB |
Output is correct |
77 |
Correct |
37 ms |
1372 KB |
Output is correct |
78 |
Correct |
66 ms |
2420 KB |
Output is correct |
79 |
Correct |
114 ms |
26848 KB |
Output is correct |
80 |
Correct |
189 ms |
40788 KB |
Output is correct |
81 |
Correct |
263 ms |
54660 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 |
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 |
106 ms |
27260 KB |
Output is correct |
10 |
Correct |
7 ms |
3160 KB |
Output is correct |
11 |
Correct |
60 ms |
14972 KB |
Output is correct |
12 |
Correct |
11 ms |
4700 KB |
Output is correct |
13 |
Correct |
347 ms |
10456 KB |
Output is correct |
14 |
Correct |
5 ms |
600 KB |
Output is correct |
15 |
Correct |
10 ms |
860 KB |
Output is correct |
16 |
Correct |
121 ms |
26024 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 |
264 ms |
55820 KB |
Output is correct |
21 |
Correct |
284 ms |
54516 KB |
Output is correct |
22 |
Correct |
265 ms |
53680 KB |
Output is correct |
23 |
Correct |
220 ms |
45380 KB |
Output is correct |
24 |
Correct |
488 ms |
22988 KB |
Output is correct |
25 |
Correct |
2107 ms |
41296 KB |
Output is correct |
26 |
Correct |
1871 ms |
41380 KB |
Output is correct |
27 |
Correct |
280 ms |
48596 KB |
Output is correct |
28 |
Correct |
257 ms |
48776 KB |
Output is correct |
29 |
Correct |
255 ms |
48776 KB |
Output is correct |
30 |
Correct |
257 ms |
48776 KB |
Output is correct |
31 |
Correct |
1 ms |
348 KB |
Output is correct |
32 |
Incorrect |
107 ms |
3348 KB |
Solution announced impossible, but it is possible. |
33 |
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 |
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 |
106 ms |
27260 KB |
Output is correct |
10 |
Correct |
7 ms |
3160 KB |
Output is correct |
11 |
Correct |
60 ms |
14972 KB |
Output is correct |
12 |
Correct |
11 ms |
4700 KB |
Output is correct |
13 |
Correct |
347 ms |
10456 KB |
Output is correct |
14 |
Correct |
5 ms |
600 KB |
Output is correct |
15 |
Correct |
10 ms |
860 KB |
Output is correct |
16 |
Correct |
121 ms |
26024 KB |
Output is correct |
17 |
Correct |
248 ms |
55308 KB |
Output is correct |
18 |
Correct |
279 ms |
54796 KB |
Output is correct |
19 |
Correct |
293 ms |
54036 KB |
Output is correct |
20 |
Correct |
279 ms |
59064 KB |
Output is correct |
21 |
Correct |
228 ms |
48068 KB |
Output is correct |
22 |
Correct |
0 ms |
348 KB |
Output is correct |
23 |
Incorrect |
265 ms |
7224 KB |
Solution announced impossible, but it is possible. |
24 |
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 |
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 |
106 ms |
27260 KB |
Output is correct |
10 |
Correct |
7 ms |
3160 KB |
Output is correct |
11 |
Correct |
60 ms |
14972 KB |
Output is correct |
12 |
Correct |
11 ms |
4700 KB |
Output is correct |
13 |
Correct |
347 ms |
10456 KB |
Output is correct |
14 |
Correct |
5 ms |
600 KB |
Output is correct |
15 |
Correct |
10 ms |
860 KB |
Output is correct |
16 |
Correct |
121 ms |
26024 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 |
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 |
322 ms |
63064 KB |
Output is correct |
24 |
Correct |
1 ms |
348 KB |
Output is correct |
25 |
Correct |
2 ms |
600 KB |
Output is correct |
26 |
Correct |
35 ms |
1220 KB |
Output is correct |
27 |
Correct |
30 ms |
1372 KB |
Output is correct |
28 |
Correct |
121 ms |
26436 KB |
Output is correct |
29 |
Correct |
183 ms |
38348 KB |
Output is correct |
30 |
Correct |
237 ms |
53136 KB |
Output is correct |
31 |
Correct |
310 ms |
62612 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 |
12 ms |
868 KB |
Output is correct |
44 |
Correct |
17 ms |
1088 KB |
Output is correct |
45 |
Correct |
108 ms |
26272 KB |
Output is correct |
46 |
Correct |
172 ms |
39012 KB |
Output is correct |
47 |
Correct |
169 ms |
38564 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 |
300 ms |
57548 KB |
Output is correct |
56 |
Correct |
0 ms |
344 KB |
Output is correct |
57 |
Correct |
2 ms |
860 KB |
Output is correct |
58 |
Correct |
7 ms |
2112 KB |
Output is correct |
59 |
Correct |
98 ms |
2592 KB |
Output is correct |
60 |
Correct |
157 ms |
30312 KB |
Output is correct |
61 |
Correct |
201 ms |
41220 KB |
Output is correct |
62 |
Correct |
236 ms |
49308 KB |
Output is correct |
63 |
Correct |
358 ms |
58952 KB |
Output is correct |
64 |
Correct |
0 ms |
348 KB |
Output is correct |
65 |
Correct |
0 ms |
348 KB |
Output is correct |
66 |
Correct |
0 ms |
348 KB |
Output is correct |
67 |
Correct |
243 ms |
53168 KB |
Output is correct |
68 |
Correct |
269 ms |
53156 KB |
Output is correct |
69 |
Correct |
272 ms |
53772 KB |
Output is correct |
70 |
Correct |
34 ms |
1248 KB |
Output is correct |
71 |
Correct |
61 ms |
1884 KB |
Output is correct |
72 |
Correct |
129 ms |
25512 KB |
Output is correct |
73 |
Correct |
203 ms |
39180 KB |
Output is correct |
74 |
Correct |
259 ms |
50824 KB |
Output is correct |
75 |
Correct |
310 ms |
58132 KB |
Output is correct |
76 |
Correct |
292 ms |
54916 KB |
Output is correct |
77 |
Correct |
37 ms |
1372 KB |
Output is correct |
78 |
Correct |
66 ms |
2420 KB |
Output is correct |
79 |
Correct |
114 ms |
26848 KB |
Output is correct |
80 |
Correct |
189 ms |
40788 KB |
Output is correct |
81 |
Correct |
263 ms |
54660 KB |
Output is correct |
82 |
Correct |
0 ms |
344 KB |
Output is correct |
83 |
Correct |
0 ms |
348 KB |
Output is correct |
84 |
Correct |
0 ms |
348 KB |
Output is correct |
85 |
Correct |
264 ms |
55820 KB |
Output is correct |
86 |
Correct |
284 ms |
54516 KB |
Output is correct |
87 |
Correct |
265 ms |
53680 KB |
Output is correct |
88 |
Correct |
220 ms |
45380 KB |
Output is correct |
89 |
Correct |
488 ms |
22988 KB |
Output is correct |
90 |
Correct |
2107 ms |
41296 KB |
Output is correct |
91 |
Correct |
1871 ms |
41380 KB |
Output is correct |
92 |
Correct |
280 ms |
48596 KB |
Output is correct |
93 |
Correct |
257 ms |
48776 KB |
Output is correct |
94 |
Correct |
255 ms |
48776 KB |
Output is correct |
95 |
Correct |
257 ms |
48776 KB |
Output is correct |
96 |
Correct |
1 ms |
348 KB |
Output is correct |
97 |
Incorrect |
107 ms |
3348 KB |
Solution announced impossible, but it is possible. |
98 |
Halted |
0 ms |
0 KB |
- |