#include "parks.h"
#include<bits/stdc++.h>
using namespace std;
vector<vector<int>> adj;
vector<bool> vis;
const int MAX_X = 200000;
void dfs(int i)
{
if(vis[i])
return;
vis[i] = 1;
for(auto j : adj[i])
{
dfs(j);
}
}
int mn , mx , cur_x;
void dfs_comp(int i , vector<int> &y)
{
if(vis[i])
return ;
vis[i] = 1;
mn = min(mn , y[i]);
mx = max(mx , y[i]);
for(auto j : adj[i])
{
dfs_comp(j , y);
}
}
void add_edge(int u , int v)
{
adj[u].push_back(v);
adj[v].push_back(u);
}
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;
for(int i = 0 ; i <n ; i++)
{
idx[{x[i] , y[i]}] = i;
}
for(int i = 0 ; i < n ;i++)
{
if(idx.count({x[i] , y[i] + 2}))
{
u.push_back(i);
v.push_back(idx[{x[i] , y[i] + 2}]);
add_edge(u.back() , v.back());
b.push_back(y[i] + 1);
a.push_back(x[i] - 1);
}
}
vector<vector<int>> comp(MAX_X + 1);
for(int i = 0 ; i < n ;i++)
{
if(vis[i])
continue;
cur_x = x[i];
mn = 1e9;
mx = -1e9;
dfs_comp(i , y);
comp[cur_x].push_back(mn);
comp[cur_x].push_back(mx);
}
for(int i = 2 ;i <= MAX_X ; i+=2)
{
sort(comp[i].begin() , comp[i].end());
}
for(int i = 4 ; i <= MAX_X ; i+=2)
{
for(int j = 0 ; j < (int)comp[i].size() ; j++)
{
if(j > 0 && comp[i][j] == comp[i][j - 1])
continue;
int val = comp[i][j];
if(idx.count({i - 2 ,val}))
{
u.push_back(idx[{i,val}]);
v.push_back(idx[{i - 2 , val}]);
add_edge(u.back() , v.back());
a.push_back(i - 1);
if(j % 2 == 0)
b.push_back(val - 1);
else
b.push_back(val + 1);
}
}
}
vis.assign(n , 0);
dfs(0);
for(int i = 0 ; i < n ; i++)
{
if(!vis[i])
{
return 0;
}
}
build(u , v , a , b);
return 1;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
4952 KB |
Output is correct |
2 |
Correct |
1 ms |
4956 KB |
Output is correct |
3 |
Correct |
1 ms |
4956 KB |
Output is correct |
4 |
Correct |
1 ms |
4956 KB |
Output is correct |
5 |
Correct |
1 ms |
4952 KB |
Output is correct |
6 |
Correct |
1 ms |
4956 KB |
Output is correct |
7 |
Correct |
2 ms |
4956 KB |
Output is correct |
8 |
Correct |
1 ms |
4956 KB |
Output is correct |
9 |
Correct |
104 ms |
26036 KB |
Output is correct |
10 |
Correct |
7 ms |
7260 KB |
Output is correct |
11 |
Correct |
31 ms |
16368 KB |
Output is correct |
12 |
Correct |
10 ms |
8284 KB |
Output is correct |
13 |
Correct |
25 ms |
12472 KB |
Output is correct |
14 |
Correct |
2 ms |
5212 KB |
Output is correct |
15 |
Correct |
2 ms |
5212 KB |
Output is correct |
16 |
Correct |
101 ms |
24704 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
4952 KB |
Output is correct |
2 |
Correct |
1 ms |
4956 KB |
Output is correct |
3 |
Correct |
1 ms |
4956 KB |
Output is correct |
4 |
Correct |
1 ms |
4956 KB |
Output is correct |
5 |
Correct |
1 ms |
4952 KB |
Output is correct |
6 |
Correct |
1 ms |
4956 KB |
Output is correct |
7 |
Correct |
2 ms |
4956 KB |
Output is correct |
8 |
Correct |
1 ms |
4956 KB |
Output is correct |
9 |
Correct |
104 ms |
26036 KB |
Output is correct |
10 |
Correct |
7 ms |
7260 KB |
Output is correct |
11 |
Correct |
31 ms |
16368 KB |
Output is correct |
12 |
Correct |
10 ms |
8284 KB |
Output is correct |
13 |
Correct |
25 ms |
12472 KB |
Output is correct |
14 |
Correct |
2 ms |
5212 KB |
Output is correct |
15 |
Correct |
2 ms |
5212 KB |
Output is correct |
16 |
Correct |
101 ms |
24704 KB |
Output is correct |
17 |
Correct |
1 ms |
4956 KB |
Output is correct |
18 |
Correct |
1 ms |
4956 KB |
Output is correct |
19 |
Correct |
1 ms |
4956 KB |
Output is correct |
20 |
Correct |
1 ms |
4956 KB |
Output is correct |
21 |
Correct |
2 ms |
4952 KB |
Output is correct |
22 |
Correct |
1 ms |
4956 KB |
Output is correct |
23 |
Correct |
252 ms |
47408 KB |
Output is correct |
24 |
Correct |
2 ms |
4952 KB |
Output is correct |
25 |
Correct |
2 ms |
5212 KB |
Output is correct |
26 |
Correct |
3 ms |
5468 KB |
Output is correct |
27 |
Correct |
3 ms |
5724 KB |
Output is correct |
28 |
Correct |
80 ms |
22004 KB |
Output is correct |
29 |
Correct |
124 ms |
30392 KB |
Output is correct |
30 |
Correct |
192 ms |
38892 KB |
Output is correct |
31 |
Correct |
270 ms |
47524 KB |
Output is correct |
32 |
Correct |
2 ms |
4956 KB |
Output is correct |
33 |
Correct |
1 ms |
4956 KB |
Output is correct |
34 |
Correct |
2 ms |
4952 KB |
Output is correct |
35 |
Correct |
3 ms |
4956 KB |
Output is correct |
36 |
Correct |
2 ms |
4956 KB |
Output is correct |
37 |
Correct |
2 ms |
4956 KB |
Output is correct |
38 |
Correct |
1 ms |
4956 KB |
Output is correct |
39 |
Correct |
1 ms |
4956 KB |
Output is correct |
40 |
Correct |
1 ms |
4956 KB |
Output is correct |
41 |
Correct |
2 ms |
4956 KB |
Output is correct |
42 |
Correct |
2 ms |
4956 KB |
Output is correct |
43 |
Correct |
3 ms |
5212 KB |
Output is correct |
44 |
Correct |
3 ms |
5468 KB |
Output is correct |
45 |
Incorrect |
95 ms |
21476 KB |
Solution announced impossible, but it is possible. |
46 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
4952 KB |
Output is correct |
2 |
Correct |
1 ms |
4956 KB |
Output is correct |
3 |
Correct |
1 ms |
4956 KB |
Output is correct |
4 |
Correct |
1 ms |
4956 KB |
Output is correct |
5 |
Correct |
1 ms |
4952 KB |
Output is correct |
6 |
Correct |
1 ms |
4956 KB |
Output is correct |
7 |
Correct |
2 ms |
4956 KB |
Output is correct |
8 |
Correct |
1 ms |
4956 KB |
Output is correct |
9 |
Correct |
104 ms |
26036 KB |
Output is correct |
10 |
Correct |
7 ms |
7260 KB |
Output is correct |
11 |
Correct |
31 ms |
16368 KB |
Output is correct |
12 |
Correct |
10 ms |
8284 KB |
Output is correct |
13 |
Correct |
25 ms |
12472 KB |
Output is correct |
14 |
Correct |
2 ms |
5212 KB |
Output is correct |
15 |
Correct |
2 ms |
5212 KB |
Output is correct |
16 |
Correct |
101 ms |
24704 KB |
Output is correct |
17 |
Correct |
1 ms |
4956 KB |
Output is correct |
18 |
Correct |
1 ms |
4956 KB |
Output is correct |
19 |
Correct |
1 ms |
4956 KB |
Output is correct |
20 |
Correct |
1 ms |
4956 KB |
Output is correct |
21 |
Correct |
2 ms |
4952 KB |
Output is correct |
22 |
Correct |
1 ms |
4956 KB |
Output is correct |
23 |
Correct |
252 ms |
47408 KB |
Output is correct |
24 |
Correct |
2 ms |
4952 KB |
Output is correct |
25 |
Correct |
2 ms |
5212 KB |
Output is correct |
26 |
Correct |
3 ms |
5468 KB |
Output is correct |
27 |
Correct |
3 ms |
5724 KB |
Output is correct |
28 |
Correct |
80 ms |
22004 KB |
Output is correct |
29 |
Correct |
124 ms |
30392 KB |
Output is correct |
30 |
Correct |
192 ms |
38892 KB |
Output is correct |
31 |
Correct |
270 ms |
47524 KB |
Output is correct |
32 |
Correct |
2 ms |
4956 KB |
Output is correct |
33 |
Correct |
1 ms |
4956 KB |
Output is correct |
34 |
Correct |
2 ms |
4952 KB |
Output is correct |
35 |
Correct |
3 ms |
4956 KB |
Output is correct |
36 |
Correct |
2 ms |
4956 KB |
Output is correct |
37 |
Correct |
2 ms |
4956 KB |
Output is correct |
38 |
Correct |
1 ms |
4956 KB |
Output is correct |
39 |
Correct |
1 ms |
4956 KB |
Output is correct |
40 |
Correct |
1 ms |
4956 KB |
Output is correct |
41 |
Correct |
2 ms |
4956 KB |
Output is correct |
42 |
Correct |
2 ms |
4956 KB |
Output is correct |
43 |
Correct |
3 ms |
5212 KB |
Output is correct |
44 |
Correct |
3 ms |
5468 KB |
Output is correct |
45 |
Incorrect |
95 ms |
21476 KB |
Solution announced impossible, but it is possible. |
46 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
4952 KB |
Output is correct |
2 |
Correct |
1 ms |
4956 KB |
Output is correct |
3 |
Correct |
1 ms |
4956 KB |
Output is correct |
4 |
Correct |
1 ms |
4956 KB |
Output is correct |
5 |
Correct |
1 ms |
4952 KB |
Output is correct |
6 |
Correct |
1 ms |
4956 KB |
Output is correct |
7 |
Correct |
2 ms |
4956 KB |
Output is correct |
8 |
Correct |
1 ms |
4956 KB |
Output is correct |
9 |
Correct |
104 ms |
26036 KB |
Output is correct |
10 |
Correct |
7 ms |
7260 KB |
Output is correct |
11 |
Correct |
31 ms |
16368 KB |
Output is correct |
12 |
Correct |
10 ms |
8284 KB |
Output is correct |
13 |
Correct |
25 ms |
12472 KB |
Output is correct |
14 |
Correct |
2 ms |
5212 KB |
Output is correct |
15 |
Correct |
2 ms |
5212 KB |
Output is correct |
16 |
Correct |
101 ms |
24704 KB |
Output is correct |
17 |
Correct |
2 ms |
4956 KB |
Output is correct |
18 |
Correct |
1 ms |
4932 KB |
Output is correct |
19 |
Correct |
1 ms |
4956 KB |
Output is correct |
20 |
Correct |
272 ms |
50344 KB |
Output is correct |
21 |
Correct |
287 ms |
47564 KB |
Output is correct |
22 |
Correct |
283 ms |
48248 KB |
Output is correct |
23 |
Correct |
213 ms |
42124 KB |
Output is correct |
24 |
Correct |
152 ms |
28272 KB |
Output is correct |
25 |
Correct |
220 ms |
37364 KB |
Output is correct |
26 |
Correct |
205 ms |
35704 KB |
Output is correct |
27 |
Correct |
242 ms |
42168 KB |
Output is correct |
28 |
Correct |
262 ms |
42152 KB |
Output is correct |
29 |
Correct |
240 ms |
44180 KB |
Output is correct |
30 |
Incorrect |
219 ms |
37884 KB |
Solution announced impossible, but it is possible. |
31 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
4952 KB |
Output is correct |
2 |
Correct |
1 ms |
4956 KB |
Output is correct |
3 |
Correct |
1 ms |
4956 KB |
Output is correct |
4 |
Correct |
1 ms |
4956 KB |
Output is correct |
5 |
Correct |
1 ms |
4952 KB |
Output is correct |
6 |
Correct |
1 ms |
4956 KB |
Output is correct |
7 |
Correct |
2 ms |
4956 KB |
Output is correct |
8 |
Correct |
1 ms |
4956 KB |
Output is correct |
9 |
Correct |
104 ms |
26036 KB |
Output is correct |
10 |
Correct |
7 ms |
7260 KB |
Output is correct |
11 |
Correct |
31 ms |
16368 KB |
Output is correct |
12 |
Correct |
10 ms |
8284 KB |
Output is correct |
13 |
Correct |
25 ms |
12472 KB |
Output is correct |
14 |
Correct |
2 ms |
5212 KB |
Output is correct |
15 |
Correct |
2 ms |
5212 KB |
Output is correct |
16 |
Correct |
101 ms |
24704 KB |
Output is correct |
17 |
Correct |
246 ms |
48928 KB |
Output is correct |
18 |
Correct |
245 ms |
48300 KB |
Output is correct |
19 |
Incorrect |
239 ms |
42524 KB |
Solution announced impossible, but it is possible. |
20 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
4952 KB |
Output is correct |
2 |
Correct |
1 ms |
4956 KB |
Output is correct |
3 |
Correct |
1 ms |
4956 KB |
Output is correct |
4 |
Correct |
1 ms |
4956 KB |
Output is correct |
5 |
Correct |
1 ms |
4952 KB |
Output is correct |
6 |
Correct |
1 ms |
4956 KB |
Output is correct |
7 |
Correct |
2 ms |
4956 KB |
Output is correct |
8 |
Correct |
1 ms |
4956 KB |
Output is correct |
9 |
Correct |
104 ms |
26036 KB |
Output is correct |
10 |
Correct |
7 ms |
7260 KB |
Output is correct |
11 |
Correct |
31 ms |
16368 KB |
Output is correct |
12 |
Correct |
10 ms |
8284 KB |
Output is correct |
13 |
Correct |
25 ms |
12472 KB |
Output is correct |
14 |
Correct |
2 ms |
5212 KB |
Output is correct |
15 |
Correct |
2 ms |
5212 KB |
Output is correct |
16 |
Correct |
101 ms |
24704 KB |
Output is correct |
17 |
Correct |
1 ms |
4956 KB |
Output is correct |
18 |
Correct |
1 ms |
4956 KB |
Output is correct |
19 |
Correct |
1 ms |
4956 KB |
Output is correct |
20 |
Correct |
1 ms |
4956 KB |
Output is correct |
21 |
Correct |
2 ms |
4952 KB |
Output is correct |
22 |
Correct |
1 ms |
4956 KB |
Output is correct |
23 |
Correct |
252 ms |
47408 KB |
Output is correct |
24 |
Correct |
2 ms |
4952 KB |
Output is correct |
25 |
Correct |
2 ms |
5212 KB |
Output is correct |
26 |
Correct |
3 ms |
5468 KB |
Output is correct |
27 |
Correct |
3 ms |
5724 KB |
Output is correct |
28 |
Correct |
80 ms |
22004 KB |
Output is correct |
29 |
Correct |
124 ms |
30392 KB |
Output is correct |
30 |
Correct |
192 ms |
38892 KB |
Output is correct |
31 |
Correct |
270 ms |
47524 KB |
Output is correct |
32 |
Correct |
2 ms |
4956 KB |
Output is correct |
33 |
Correct |
1 ms |
4956 KB |
Output is correct |
34 |
Correct |
2 ms |
4952 KB |
Output is correct |
35 |
Correct |
3 ms |
4956 KB |
Output is correct |
36 |
Correct |
2 ms |
4956 KB |
Output is correct |
37 |
Correct |
2 ms |
4956 KB |
Output is correct |
38 |
Correct |
1 ms |
4956 KB |
Output is correct |
39 |
Correct |
1 ms |
4956 KB |
Output is correct |
40 |
Correct |
1 ms |
4956 KB |
Output is correct |
41 |
Correct |
2 ms |
4956 KB |
Output is correct |
42 |
Correct |
2 ms |
4956 KB |
Output is correct |
43 |
Correct |
3 ms |
5212 KB |
Output is correct |
44 |
Correct |
3 ms |
5468 KB |
Output is correct |
45 |
Incorrect |
95 ms |
21476 KB |
Solution announced impossible, but it is possible. |
46 |
Halted |
0 ms |
0 KB |
- |