#include "parks.h"
#include <bits/stdc++.h>
using namespace std;
#define ar array
const int dir[4][2] = {{2, 0}, {-2, 0}, {0, 2}, {0, -2}};
const int N = 3e5 + 20;
int X[N], Y[N];
map<ar<int, 2>, int > mp;
vector<int> U, V, A, B;
bool vis[N];
void dfs(int x){
vis[x] = 1;
for(int i = 0;i < 4;i++){
if(mp.count(ar<int, 2>{X[x] + dir[i][0], Y[x] + dir[i][1]})){
int u = mp[ar<int, 2>{X[x] + dir[i][0], Y[x] + dir[i][1]}];
if(vis[u])continue;
U.push_back(x);
V.push_back(u);
if(X[x] == X[u]){
B.push_back({Y[x] + (Y[x] < Y[u] ? 1 : -1)});
if((X[u] + Y[u]) % 4)A.push_back({X[x] + (Y[x] > Y[u] ? 1 : -1)});
else A.push_back({X[x] + (Y[x] < Y[u] ? 1 : -1)});
}else{
A.push_back({X[x] + (X[x] < X[u] ? 1 : -1)});
if((X[u] + Y[u]) % 4)B.push_back({Y[x] + (X[x] > X[u] ? 1 : -1)});
else B.push_back({Y[x] + (X[x] < X[u] ? 1 : -1)});
}
dfs(u);
}
}
}
int construct_roads(std::vector<int> x, std::vector<int> y) {
int n = x.size();
for(int i = 0;i < n;i++)X[i] = x[i], Y[i] = y[i];
for(int i = 0;i < n;i++)mp[{x[i], y[i]}] = i;
dfs(0);
for(int i = 0;i < n;i++){
if(!vis[i]){
return 0;
}
}
build(U, V, A, B);
return 1;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
2392 KB |
Output is correct |
2 |
Correct |
0 ms |
2396 KB |
Output is correct |
3 |
Correct |
0 ms |
2396 KB |
Output is correct |
4 |
Correct |
0 ms |
2396 KB |
Output is correct |
5 |
Correct |
0 ms |
2396 KB |
Output is correct |
6 |
Correct |
0 ms |
2396 KB |
Output is correct |
7 |
Correct |
0 ms |
2392 KB |
Output is correct |
8 |
Correct |
0 ms |
2396 KB |
Output is correct |
9 |
Correct |
78 ms |
25148 KB |
Output is correct |
10 |
Correct |
7 ms |
4956 KB |
Output is correct |
11 |
Correct |
43 ms |
15308 KB |
Output is correct |
12 |
Correct |
10 ms |
6232 KB |
Output is correct |
13 |
Correct |
22 ms |
10072 KB |
Output is correct |
14 |
Correct |
1 ms |
2396 KB |
Output is correct |
15 |
Correct |
1 ms |
2652 KB |
Output is correct |
16 |
Correct |
76 ms |
20836 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
2392 KB |
Output is correct |
2 |
Correct |
0 ms |
2396 KB |
Output is correct |
3 |
Correct |
0 ms |
2396 KB |
Output is correct |
4 |
Correct |
0 ms |
2396 KB |
Output is correct |
5 |
Correct |
0 ms |
2396 KB |
Output is correct |
6 |
Correct |
0 ms |
2396 KB |
Output is correct |
7 |
Correct |
0 ms |
2392 KB |
Output is correct |
8 |
Correct |
0 ms |
2396 KB |
Output is correct |
9 |
Correct |
78 ms |
25148 KB |
Output is correct |
10 |
Correct |
7 ms |
4956 KB |
Output is correct |
11 |
Correct |
43 ms |
15308 KB |
Output is correct |
12 |
Correct |
10 ms |
6232 KB |
Output is correct |
13 |
Correct |
22 ms |
10072 KB |
Output is correct |
14 |
Correct |
1 ms |
2396 KB |
Output is correct |
15 |
Correct |
1 ms |
2652 KB |
Output is correct |
16 |
Correct |
76 ms |
20836 KB |
Output is correct |
17 |
Correct |
0 ms |
2392 KB |
Output is correct |
18 |
Incorrect |
0 ms |
2396 KB |
Tree @(3, 5) appears more than once: for edges on positions 0 and 1 |
19 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
2392 KB |
Output is correct |
2 |
Correct |
0 ms |
2396 KB |
Output is correct |
3 |
Correct |
0 ms |
2396 KB |
Output is correct |
4 |
Correct |
0 ms |
2396 KB |
Output is correct |
5 |
Correct |
0 ms |
2396 KB |
Output is correct |
6 |
Correct |
0 ms |
2396 KB |
Output is correct |
7 |
Correct |
0 ms |
2392 KB |
Output is correct |
8 |
Correct |
0 ms |
2396 KB |
Output is correct |
9 |
Correct |
78 ms |
25148 KB |
Output is correct |
10 |
Correct |
7 ms |
4956 KB |
Output is correct |
11 |
Correct |
43 ms |
15308 KB |
Output is correct |
12 |
Correct |
10 ms |
6232 KB |
Output is correct |
13 |
Correct |
22 ms |
10072 KB |
Output is correct |
14 |
Correct |
1 ms |
2396 KB |
Output is correct |
15 |
Correct |
1 ms |
2652 KB |
Output is correct |
16 |
Correct |
76 ms |
20836 KB |
Output is correct |
17 |
Correct |
0 ms |
2392 KB |
Output is correct |
18 |
Incorrect |
0 ms |
2396 KB |
Tree @(3, 5) appears more than once: for edges on positions 0 and 1 |
19 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
2392 KB |
Output is correct |
2 |
Correct |
0 ms |
2396 KB |
Output is correct |
3 |
Correct |
0 ms |
2396 KB |
Output is correct |
4 |
Correct |
0 ms |
2396 KB |
Output is correct |
5 |
Correct |
0 ms |
2396 KB |
Output is correct |
6 |
Correct |
0 ms |
2396 KB |
Output is correct |
7 |
Correct |
0 ms |
2392 KB |
Output is correct |
8 |
Correct |
0 ms |
2396 KB |
Output is correct |
9 |
Correct |
78 ms |
25148 KB |
Output is correct |
10 |
Correct |
7 ms |
4956 KB |
Output is correct |
11 |
Correct |
43 ms |
15308 KB |
Output is correct |
12 |
Correct |
10 ms |
6232 KB |
Output is correct |
13 |
Correct |
22 ms |
10072 KB |
Output is correct |
14 |
Correct |
1 ms |
2396 KB |
Output is correct |
15 |
Correct |
1 ms |
2652 KB |
Output is correct |
16 |
Correct |
76 ms |
20836 KB |
Output is correct |
17 |
Correct |
1 ms |
2392 KB |
Output is correct |
18 |
Correct |
0 ms |
2396 KB |
Output is correct |
19 |
Correct |
0 ms |
2396 KB |
Output is correct |
20 |
Incorrect |
222 ms |
49700 KB |
Tree @(195231, 4773) appears more than once: for edges on positions 0 and 1 |
21 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
2392 KB |
Output is correct |
2 |
Correct |
0 ms |
2396 KB |
Output is correct |
3 |
Correct |
0 ms |
2396 KB |
Output is correct |
4 |
Correct |
0 ms |
2396 KB |
Output is correct |
5 |
Correct |
0 ms |
2396 KB |
Output is correct |
6 |
Correct |
0 ms |
2396 KB |
Output is correct |
7 |
Correct |
0 ms |
2392 KB |
Output is correct |
8 |
Correct |
0 ms |
2396 KB |
Output is correct |
9 |
Correct |
78 ms |
25148 KB |
Output is correct |
10 |
Correct |
7 ms |
4956 KB |
Output is correct |
11 |
Correct |
43 ms |
15308 KB |
Output is correct |
12 |
Correct |
10 ms |
6232 KB |
Output is correct |
13 |
Correct |
22 ms |
10072 KB |
Output is correct |
14 |
Correct |
1 ms |
2396 KB |
Output is correct |
15 |
Correct |
1 ms |
2652 KB |
Output is correct |
16 |
Correct |
76 ms |
20836 KB |
Output is correct |
17 |
Incorrect |
188 ms |
49968 KB |
Tree @(100001, 3) appears more than once: for edges on positions 58789 and 58790 |
18 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
2392 KB |
Output is correct |
2 |
Correct |
0 ms |
2396 KB |
Output is correct |
3 |
Correct |
0 ms |
2396 KB |
Output is correct |
4 |
Correct |
0 ms |
2396 KB |
Output is correct |
5 |
Correct |
0 ms |
2396 KB |
Output is correct |
6 |
Correct |
0 ms |
2396 KB |
Output is correct |
7 |
Correct |
0 ms |
2392 KB |
Output is correct |
8 |
Correct |
0 ms |
2396 KB |
Output is correct |
9 |
Correct |
78 ms |
25148 KB |
Output is correct |
10 |
Correct |
7 ms |
4956 KB |
Output is correct |
11 |
Correct |
43 ms |
15308 KB |
Output is correct |
12 |
Correct |
10 ms |
6232 KB |
Output is correct |
13 |
Correct |
22 ms |
10072 KB |
Output is correct |
14 |
Correct |
1 ms |
2396 KB |
Output is correct |
15 |
Correct |
1 ms |
2652 KB |
Output is correct |
16 |
Correct |
76 ms |
20836 KB |
Output is correct |
17 |
Correct |
0 ms |
2392 KB |
Output is correct |
18 |
Incorrect |
0 ms |
2396 KB |
Tree @(3, 5) appears more than once: for edges on positions 0 and 1 |
19 |
Halted |
0 ms |
0 KB |
- |