#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 = 2;
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)
{
continue;
sort(vv.begin() , vv.end() , [](pair<int ,int> a , pair<int ,int> b){return a.first + a.second < b.first + b.second;});
}
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 |
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 |
99 ms |
27340 KB |
Output is correct |
10 |
Correct |
8 ms |
3164 KB |
Output is correct |
11 |
Correct |
47 ms |
14976 KB |
Output is correct |
12 |
Correct |
13 ms |
4696 KB |
Output is correct |
13 |
Correct |
49 ms |
10380 KB |
Output is correct |
14 |
Correct |
1 ms |
600 KB |
Output is correct |
15 |
Correct |
2 ms |
604 KB |
Output is correct |
16 |
Correct |
100 ms |
26100 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 |
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 |
99 ms |
27340 KB |
Output is correct |
10 |
Correct |
8 ms |
3164 KB |
Output is correct |
11 |
Correct |
47 ms |
14976 KB |
Output is correct |
12 |
Correct |
13 ms |
4696 KB |
Output is correct |
13 |
Correct |
49 ms |
10380 KB |
Output is correct |
14 |
Correct |
1 ms |
600 KB |
Output is correct |
15 |
Correct |
2 ms |
604 KB |
Output is correct |
16 |
Correct |
100 ms |
26100 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 |
600 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 |
333 ms |
63180 KB |
Output is correct |
24 |
Correct |
0 ms |
348 KB |
Output is correct |
25 |
Correct |
1 ms |
604 KB |
Output is correct |
26 |
Correct |
3 ms |
1116 KB |
Output is correct |
27 |
Correct |
4 ms |
1424 KB |
Output is correct |
28 |
Correct |
109 ms |
26452 KB |
Output is correct |
29 |
Correct |
170 ms |
38332 KB |
Output is correct |
30 |
Correct |
244 ms |
53232 KB |
Output is correct |
31 |
Correct |
313 ms |
62668 KB |
Output is correct |
32 |
Correct |
0 ms |
344 KB |
Output is correct |
33 |
Correct |
0 ms |
344 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 |
1 ms |
348 KB |
Output is correct |
43 |
Correct |
2 ms |
860 KB |
Output is correct |
44 |
Correct |
3 ms |
860 KB |
Output is correct |
45 |
Correct |
114 ms |
26344 KB |
Output is correct |
46 |
Correct |
169 ms |
38616 KB |
Output is correct |
47 |
Correct |
162 ms |
38368 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 |
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 |
99 ms |
27340 KB |
Output is correct |
10 |
Correct |
8 ms |
3164 KB |
Output is correct |
11 |
Correct |
47 ms |
14976 KB |
Output is correct |
12 |
Correct |
13 ms |
4696 KB |
Output is correct |
13 |
Correct |
49 ms |
10380 KB |
Output is correct |
14 |
Correct |
1 ms |
600 KB |
Output is correct |
15 |
Correct |
2 ms |
604 KB |
Output is correct |
16 |
Correct |
100 ms |
26100 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 |
600 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 |
333 ms |
63180 KB |
Output is correct |
24 |
Correct |
0 ms |
348 KB |
Output is correct |
25 |
Correct |
1 ms |
604 KB |
Output is correct |
26 |
Correct |
3 ms |
1116 KB |
Output is correct |
27 |
Correct |
4 ms |
1424 KB |
Output is correct |
28 |
Correct |
109 ms |
26452 KB |
Output is correct |
29 |
Correct |
170 ms |
38332 KB |
Output is correct |
30 |
Correct |
244 ms |
53232 KB |
Output is correct |
31 |
Correct |
313 ms |
62668 KB |
Output is correct |
32 |
Correct |
0 ms |
344 KB |
Output is correct |
33 |
Correct |
0 ms |
344 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 |
1 ms |
348 KB |
Output is correct |
43 |
Correct |
2 ms |
860 KB |
Output is correct |
44 |
Correct |
3 ms |
860 KB |
Output is correct |
45 |
Correct |
114 ms |
26344 KB |
Output is correct |
46 |
Correct |
169 ms |
38616 KB |
Output is correct |
47 |
Correct |
162 ms |
38368 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 |
293 ms |
57480 KB |
Output is correct |
56 |
Correct |
0 ms |
600 KB |
Output is correct |
57 |
Correct |
2 ms |
856 KB |
Output is correct |
58 |
Correct |
6 ms |
2140 KB |
Output is correct |
59 |
Correct |
12 ms |
2640 KB |
Output is correct |
60 |
Correct |
127 ms |
30404 KB |
Output is correct |
61 |
Correct |
185 ms |
41084 KB |
Output is correct |
62 |
Correct |
232 ms |
49308 KB |
Output is correct |
63 |
Correct |
306 ms |
58824 KB |
Output is correct |
64 |
Correct |
1 ms |
344 KB |
Output is correct |
65 |
Correct |
0 ms |
348 KB |
Output is correct |
66 |
Correct |
0 ms |
348 KB |
Output is correct |
67 |
Correct |
234 ms |
53176 KB |
Output is correct |
68 |
Correct |
231 ms |
53384 KB |
Output is correct |
69 |
Correct |
236 ms |
53600 KB |
Output is correct |
70 |
Correct |
4 ms |
1116 KB |
Output is correct |
71 |
Correct |
8 ms |
1932 KB |
Output is correct |
72 |
Correct |
100 ms |
25456 KB |
Output is correct |
73 |
Correct |
165 ms |
39308 KB |
Output is correct |
74 |
Correct |
239 ms |
50828 KB |
Output is correct |
75 |
Correct |
280 ms |
58248 KB |
Output is correct |
76 |
Correct |
242 ms |
54924 KB |
Output is correct |
77 |
Correct |
6 ms |
1368 KB |
Output is correct |
78 |
Correct |
10 ms |
2396 KB |
Output is correct |
79 |
Correct |
113 ms |
26640 KB |
Output is correct |
80 |
Correct |
194 ms |
40592 KB |
Output is correct |
81 |
Correct |
254 ms |
54664 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 |
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 |
99 ms |
27340 KB |
Output is correct |
10 |
Correct |
8 ms |
3164 KB |
Output is correct |
11 |
Correct |
47 ms |
14976 KB |
Output is correct |
12 |
Correct |
13 ms |
4696 KB |
Output is correct |
13 |
Correct |
49 ms |
10380 KB |
Output is correct |
14 |
Correct |
1 ms |
600 KB |
Output is correct |
15 |
Correct |
2 ms |
604 KB |
Output is correct |
16 |
Correct |
100 ms |
26100 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 |
241 ms |
55692 KB |
Output is correct |
21 |
Correct |
266 ms |
54280 KB |
Output is correct |
22 |
Correct |
252 ms |
53640 KB |
Output is correct |
23 |
Correct |
195 ms |
45396 KB |
Output is correct |
24 |
Correct |
124 ms |
22988 KB |
Output is correct |
25 |
Correct |
301 ms |
41196 KB |
Output is correct |
26 |
Correct |
283 ms |
41396 KB |
Output is correct |
27 |
Correct |
246 ms |
48776 KB |
Output is correct |
28 |
Correct |
236 ms |
48688 KB |
Output is correct |
29 |
Correct |
254 ms |
48776 KB |
Output is correct |
30 |
Correct |
242 ms |
48776 KB |
Output is correct |
31 |
Correct |
0 ms |
348 KB |
Output is correct |
32 |
Incorrect |
16 ms |
3264 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 |
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 |
99 ms |
27340 KB |
Output is correct |
10 |
Correct |
8 ms |
3164 KB |
Output is correct |
11 |
Correct |
47 ms |
14976 KB |
Output is correct |
12 |
Correct |
13 ms |
4696 KB |
Output is correct |
13 |
Correct |
49 ms |
10380 KB |
Output is correct |
14 |
Correct |
1 ms |
600 KB |
Output is correct |
15 |
Correct |
2 ms |
604 KB |
Output is correct |
16 |
Correct |
100 ms |
26100 KB |
Output is correct |
17 |
Correct |
255 ms |
55432 KB |
Output is correct |
18 |
Correct |
248 ms |
54916 KB |
Output is correct |
19 |
Correct |
245 ms |
54036 KB |
Output is correct |
20 |
Correct |
262 ms |
59064 KB |
Output is correct |
21 |
Correct |
213 ms |
48112 KB |
Output is correct |
22 |
Correct |
0 ms |
348 KB |
Output is correct |
23 |
Incorrect |
41 ms |
7080 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 |
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 |
99 ms |
27340 KB |
Output is correct |
10 |
Correct |
8 ms |
3164 KB |
Output is correct |
11 |
Correct |
47 ms |
14976 KB |
Output is correct |
12 |
Correct |
13 ms |
4696 KB |
Output is correct |
13 |
Correct |
49 ms |
10380 KB |
Output is correct |
14 |
Correct |
1 ms |
600 KB |
Output is correct |
15 |
Correct |
2 ms |
604 KB |
Output is correct |
16 |
Correct |
100 ms |
26100 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 |
600 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 |
333 ms |
63180 KB |
Output is correct |
24 |
Correct |
0 ms |
348 KB |
Output is correct |
25 |
Correct |
1 ms |
604 KB |
Output is correct |
26 |
Correct |
3 ms |
1116 KB |
Output is correct |
27 |
Correct |
4 ms |
1424 KB |
Output is correct |
28 |
Correct |
109 ms |
26452 KB |
Output is correct |
29 |
Correct |
170 ms |
38332 KB |
Output is correct |
30 |
Correct |
244 ms |
53232 KB |
Output is correct |
31 |
Correct |
313 ms |
62668 KB |
Output is correct |
32 |
Correct |
0 ms |
344 KB |
Output is correct |
33 |
Correct |
0 ms |
344 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 |
1 ms |
348 KB |
Output is correct |
43 |
Correct |
2 ms |
860 KB |
Output is correct |
44 |
Correct |
3 ms |
860 KB |
Output is correct |
45 |
Correct |
114 ms |
26344 KB |
Output is correct |
46 |
Correct |
169 ms |
38616 KB |
Output is correct |
47 |
Correct |
162 ms |
38368 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 |
293 ms |
57480 KB |
Output is correct |
56 |
Correct |
0 ms |
600 KB |
Output is correct |
57 |
Correct |
2 ms |
856 KB |
Output is correct |
58 |
Correct |
6 ms |
2140 KB |
Output is correct |
59 |
Correct |
12 ms |
2640 KB |
Output is correct |
60 |
Correct |
127 ms |
30404 KB |
Output is correct |
61 |
Correct |
185 ms |
41084 KB |
Output is correct |
62 |
Correct |
232 ms |
49308 KB |
Output is correct |
63 |
Correct |
306 ms |
58824 KB |
Output is correct |
64 |
Correct |
1 ms |
344 KB |
Output is correct |
65 |
Correct |
0 ms |
348 KB |
Output is correct |
66 |
Correct |
0 ms |
348 KB |
Output is correct |
67 |
Correct |
234 ms |
53176 KB |
Output is correct |
68 |
Correct |
231 ms |
53384 KB |
Output is correct |
69 |
Correct |
236 ms |
53600 KB |
Output is correct |
70 |
Correct |
4 ms |
1116 KB |
Output is correct |
71 |
Correct |
8 ms |
1932 KB |
Output is correct |
72 |
Correct |
100 ms |
25456 KB |
Output is correct |
73 |
Correct |
165 ms |
39308 KB |
Output is correct |
74 |
Correct |
239 ms |
50828 KB |
Output is correct |
75 |
Correct |
280 ms |
58248 KB |
Output is correct |
76 |
Correct |
242 ms |
54924 KB |
Output is correct |
77 |
Correct |
6 ms |
1368 KB |
Output is correct |
78 |
Correct |
10 ms |
2396 KB |
Output is correct |
79 |
Correct |
113 ms |
26640 KB |
Output is correct |
80 |
Correct |
194 ms |
40592 KB |
Output is correct |
81 |
Correct |
254 ms |
54664 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 |
241 ms |
55692 KB |
Output is correct |
86 |
Correct |
266 ms |
54280 KB |
Output is correct |
87 |
Correct |
252 ms |
53640 KB |
Output is correct |
88 |
Correct |
195 ms |
45396 KB |
Output is correct |
89 |
Correct |
124 ms |
22988 KB |
Output is correct |
90 |
Correct |
301 ms |
41196 KB |
Output is correct |
91 |
Correct |
283 ms |
41396 KB |
Output is correct |
92 |
Correct |
246 ms |
48776 KB |
Output is correct |
93 |
Correct |
236 ms |
48688 KB |
Output is correct |
94 |
Correct |
254 ms |
48776 KB |
Output is correct |
95 |
Correct |
242 ms |
48776 KB |
Output is correct |
96 |
Correct |
0 ms |
348 KB |
Output is correct |
97 |
Incorrect |
16 ms |
3264 KB |
Solution announced impossible, but it is possible. |
98 |
Halted |
0 ms |
0 KB |
- |