#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);
}
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;
}
for(int i = 0 ; i < n ;i++)
{
if(idx.count({x[i] + 2 , y[i]}))
{
u.push_back(i);
v.push_back(idx[{x[i] + 2 , y[i]}]);
a.push_back(x[i] + 1);
if(!taken.count({x[i] + 1 , y[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}))
{
b.push_back(y[i] + 1);
taken.insert({x[i] + 1 , y[i] + 1});
}
else
return 0;
}
if(idx.count({x[i] , y[i] + 2}))
{
u.push_back(i);
v.push_back(idx[{x[i] , y[i] + 2}]);
b.push_back(y[i] + 1);
if(!taken.count({x[i] - 1 , 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}))
{
a.push_back(x[i] + 1);
taken.insert({x[i] + 1 , y[i] +1});
}
else
return 0;
}
}
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])
{
return 0;
}
}
build(u , v , a , b);
return 1;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 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 |
0 ms |
348 KB |
Output is correct |
7 |
Correct |
0 ms |
348 KB |
Output is correct |
8 |
Correct |
0 ms |
436 KB |
Output is correct |
9 |
Correct |
138 ms |
26648 KB |
Output is correct |
10 |
Correct |
7 ms |
3160 KB |
Output is correct |
11 |
Correct |
43 ms |
14792 KB |
Output is correct |
12 |
Correct |
11 ms |
4700 KB |
Output is correct |
13 |
Correct |
31 ms |
10192 KB |
Output is correct |
14 |
Correct |
1 ms |
608 KB |
Output is correct |
15 |
Correct |
1 ms |
864 KB |
Output is correct |
16 |
Correct |
133 ms |
25496 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 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 |
0 ms |
348 KB |
Output is correct |
7 |
Correct |
0 ms |
348 KB |
Output is correct |
8 |
Correct |
0 ms |
436 KB |
Output is correct |
9 |
Correct |
138 ms |
26648 KB |
Output is correct |
10 |
Correct |
7 ms |
3160 KB |
Output is correct |
11 |
Correct |
43 ms |
14792 KB |
Output is correct |
12 |
Correct |
11 ms |
4700 KB |
Output is correct |
13 |
Correct |
31 ms |
10192 KB |
Output is correct |
14 |
Correct |
1 ms |
608 KB |
Output is correct |
15 |
Correct |
1 ms |
864 KB |
Output is correct |
16 |
Correct |
133 ms |
25496 KB |
Output is correct |
17 |
Correct |
1 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 |
Incorrect |
1 ms |
348 KB |
Solution announced impossible, but it is possible. |
21 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 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 |
0 ms |
348 KB |
Output is correct |
7 |
Correct |
0 ms |
348 KB |
Output is correct |
8 |
Correct |
0 ms |
436 KB |
Output is correct |
9 |
Correct |
138 ms |
26648 KB |
Output is correct |
10 |
Correct |
7 ms |
3160 KB |
Output is correct |
11 |
Correct |
43 ms |
14792 KB |
Output is correct |
12 |
Correct |
11 ms |
4700 KB |
Output is correct |
13 |
Correct |
31 ms |
10192 KB |
Output is correct |
14 |
Correct |
1 ms |
608 KB |
Output is correct |
15 |
Correct |
1 ms |
864 KB |
Output is correct |
16 |
Correct |
133 ms |
25496 KB |
Output is correct |
17 |
Correct |
1 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 |
Incorrect |
1 ms |
348 KB |
Solution announced impossible, but it is possible. |
21 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 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 |
0 ms |
348 KB |
Output is correct |
7 |
Correct |
0 ms |
348 KB |
Output is correct |
8 |
Correct |
0 ms |
436 KB |
Output is correct |
9 |
Correct |
138 ms |
26648 KB |
Output is correct |
10 |
Correct |
7 ms |
3160 KB |
Output is correct |
11 |
Correct |
43 ms |
14792 KB |
Output is correct |
12 |
Correct |
11 ms |
4700 KB |
Output is correct |
13 |
Correct |
31 ms |
10192 KB |
Output is correct |
14 |
Correct |
1 ms |
608 KB |
Output is correct |
15 |
Correct |
1 ms |
864 KB |
Output is correct |
16 |
Correct |
133 ms |
25496 KB |
Output is correct |
17 |
Correct |
0 ms |
348 KB |
Output is correct |
18 |
Correct |
0 ms |
436 KB |
Output is correct |
19 |
Correct |
0 ms |
348 KB |
Output is correct |
20 |
Incorrect |
87 ms |
23276 KB |
Solution announced impossible, but it is possible. |
21 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 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 |
0 ms |
348 KB |
Output is correct |
7 |
Correct |
0 ms |
348 KB |
Output is correct |
8 |
Correct |
0 ms |
436 KB |
Output is correct |
9 |
Correct |
138 ms |
26648 KB |
Output is correct |
10 |
Correct |
7 ms |
3160 KB |
Output is correct |
11 |
Correct |
43 ms |
14792 KB |
Output is correct |
12 |
Correct |
11 ms |
4700 KB |
Output is correct |
13 |
Correct |
31 ms |
10192 KB |
Output is correct |
14 |
Correct |
1 ms |
608 KB |
Output is correct |
15 |
Correct |
1 ms |
864 KB |
Output is correct |
16 |
Correct |
133 ms |
25496 KB |
Output is correct |
17 |
Correct |
334 ms |
54016 KB |
Output is correct |
18 |
Correct |
338 ms |
51724 KB |
Output is correct |
19 |
Incorrect |
86 ms |
23636 KB |
Solution announced impossible, but it is possible. |
20 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 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 |
0 ms |
348 KB |
Output is correct |
7 |
Correct |
0 ms |
348 KB |
Output is correct |
8 |
Correct |
0 ms |
436 KB |
Output is correct |
9 |
Correct |
138 ms |
26648 KB |
Output is correct |
10 |
Correct |
7 ms |
3160 KB |
Output is correct |
11 |
Correct |
43 ms |
14792 KB |
Output is correct |
12 |
Correct |
11 ms |
4700 KB |
Output is correct |
13 |
Correct |
31 ms |
10192 KB |
Output is correct |
14 |
Correct |
1 ms |
608 KB |
Output is correct |
15 |
Correct |
1 ms |
864 KB |
Output is correct |
16 |
Correct |
133 ms |
25496 KB |
Output is correct |
17 |
Correct |
1 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 |
Incorrect |
1 ms |
348 KB |
Solution announced impossible, but it is possible. |
21 |
Halted |
0 ms |
0 KB |
- |