#include "parks.h"
#include <bits/stdc++.h>
using namespace std;
const int MAXN = 2e5 + 10;
vector<int> adj[MAXN];
void dfs(int node, vector<int> &vis)
{
vis[node] = 1;
for(auto a:adj[node])
if(!vis[a])
dfs(a, vis);
}
int construct_roads(vector<int> x, vector<int> y)
{
int n = x.size();
map<pair<int, int>, int> ft;
for(int i=0;i<n;i++)
{
ft[{x[i], y[i]}] = i;
}
vector<pair<int, int>> dir{{2, 0}, {-2, 0}, {0, 2}, {0, -2}};
vector<int> u, v, a, b;
for(int i=0;i<n;i++)
{
for(auto d:dir)
{
int cx = x[i] + d.first, cy = y[i] + d.second;
if(!ft.count({cx, cy}))
continue;
ft[{cx, cy}];
adj[i].push_back(ft[{cx, cy}]);
if(ft[{cx, cy}] > i)
{
u.push_back(i);
v.push_back(ft[{cx, cy}]);
if(d.second == 0)
{
a.push_back(x[i] + cx >> 1);
b.push_back(cy - 1);
}
else
{
if(x[i] <= 4)
{
a.push_back(x[i] - 1);
b.push_back(y[i] + cy >> 1);
}
else
{
a.push_back(x[i] + 1);
b.push_back(y[i] + cy >> 1);
}
}
}
}
}
vector<int> vis(n, 0);
dfs(0, vis);
for(int i=0;i<n;i++)
if(!vis[i])
return 0;
build(u, v, a, b);
return 1;
}
Compilation message
parks.cpp: In function 'int construct_roads(std::vector<int>, std::vector<int>)':
parks.cpp:40:38: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
40 | a.push_back(x[i] + cx >> 1);
parks.cpp:48:42: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
48 | b.push_back(y[i] + cy >> 1);
parks.cpp:53:42: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
53 | b.push_back(y[i] + cy >> 1);
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
4948 KB |
Output is correct |
2 |
Correct |
2 ms |
4948 KB |
Output is correct |
3 |
Correct |
2 ms |
4948 KB |
Output is correct |
4 |
Correct |
2 ms |
4948 KB |
Output is correct |
5 |
Correct |
2 ms |
4948 KB |
Output is correct |
6 |
Correct |
2 ms |
4948 KB |
Output is correct |
7 |
Correct |
2 ms |
4948 KB |
Output is correct |
8 |
Correct |
2 ms |
4948 KB |
Output is correct |
9 |
Correct |
223 ms |
23924 KB |
Output is correct |
10 |
Correct |
14 ms |
7124 KB |
Output is correct |
11 |
Correct |
82 ms |
15256 KB |
Output is correct |
12 |
Correct |
20 ms |
8160 KB |
Output is correct |
13 |
Correct |
56 ms |
11584 KB |
Output is correct |
14 |
Correct |
3 ms |
5076 KB |
Output is correct |
15 |
Correct |
4 ms |
5204 KB |
Output is correct |
16 |
Correct |
192 ms |
22620 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
4948 KB |
Output is correct |
2 |
Correct |
2 ms |
4948 KB |
Output is correct |
3 |
Correct |
2 ms |
4948 KB |
Output is correct |
4 |
Correct |
2 ms |
4948 KB |
Output is correct |
5 |
Correct |
2 ms |
4948 KB |
Output is correct |
6 |
Correct |
2 ms |
4948 KB |
Output is correct |
7 |
Correct |
2 ms |
4948 KB |
Output is correct |
8 |
Correct |
2 ms |
4948 KB |
Output is correct |
9 |
Correct |
223 ms |
23924 KB |
Output is correct |
10 |
Correct |
14 ms |
7124 KB |
Output is correct |
11 |
Correct |
82 ms |
15256 KB |
Output is correct |
12 |
Correct |
20 ms |
8160 KB |
Output is correct |
13 |
Correct |
56 ms |
11584 KB |
Output is correct |
14 |
Correct |
3 ms |
5076 KB |
Output is correct |
15 |
Correct |
4 ms |
5204 KB |
Output is correct |
16 |
Correct |
192 ms |
22620 KB |
Output is correct |
17 |
Incorrect |
2 ms |
4948 KB |
Tree @(3, 3) appears more than once: for edges on positions 0 and 1 |
18 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
4948 KB |
Output is correct |
2 |
Correct |
2 ms |
4948 KB |
Output is correct |
3 |
Correct |
2 ms |
4948 KB |
Output is correct |
4 |
Correct |
2 ms |
4948 KB |
Output is correct |
5 |
Correct |
2 ms |
4948 KB |
Output is correct |
6 |
Correct |
2 ms |
4948 KB |
Output is correct |
7 |
Correct |
2 ms |
4948 KB |
Output is correct |
8 |
Correct |
2 ms |
4948 KB |
Output is correct |
9 |
Correct |
223 ms |
23924 KB |
Output is correct |
10 |
Correct |
14 ms |
7124 KB |
Output is correct |
11 |
Correct |
82 ms |
15256 KB |
Output is correct |
12 |
Correct |
20 ms |
8160 KB |
Output is correct |
13 |
Correct |
56 ms |
11584 KB |
Output is correct |
14 |
Correct |
3 ms |
5076 KB |
Output is correct |
15 |
Correct |
4 ms |
5204 KB |
Output is correct |
16 |
Correct |
192 ms |
22620 KB |
Output is correct |
17 |
Incorrect |
2 ms |
4948 KB |
Tree @(3, 3) appears more than once: for edges on positions 0 and 1 |
18 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
4948 KB |
Output is correct |
2 |
Correct |
2 ms |
4948 KB |
Output is correct |
3 |
Correct |
2 ms |
4948 KB |
Output is correct |
4 |
Correct |
2 ms |
4948 KB |
Output is correct |
5 |
Correct |
2 ms |
4948 KB |
Output is correct |
6 |
Correct |
2 ms |
4948 KB |
Output is correct |
7 |
Correct |
2 ms |
4948 KB |
Output is correct |
8 |
Correct |
2 ms |
4948 KB |
Output is correct |
9 |
Correct |
223 ms |
23924 KB |
Output is correct |
10 |
Correct |
14 ms |
7124 KB |
Output is correct |
11 |
Correct |
82 ms |
15256 KB |
Output is correct |
12 |
Correct |
20 ms |
8160 KB |
Output is correct |
13 |
Correct |
56 ms |
11584 KB |
Output is correct |
14 |
Correct |
3 ms |
5076 KB |
Output is correct |
15 |
Correct |
4 ms |
5204 KB |
Output is correct |
16 |
Correct |
192 ms |
22620 KB |
Output is correct |
17 |
Correct |
2 ms |
4948 KB |
Output is correct |
18 |
Correct |
2 ms |
4948 KB |
Output is correct |
19 |
Correct |
3 ms |
4948 KB |
Output is correct |
20 |
Incorrect |
534 ms |
43188 KB |
Tree @(3, 199999) appears more than once: for edges on positions 76167 and 76168 |
21 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
4948 KB |
Output is correct |
2 |
Correct |
2 ms |
4948 KB |
Output is correct |
3 |
Correct |
2 ms |
4948 KB |
Output is correct |
4 |
Correct |
2 ms |
4948 KB |
Output is correct |
5 |
Correct |
2 ms |
4948 KB |
Output is correct |
6 |
Correct |
2 ms |
4948 KB |
Output is correct |
7 |
Correct |
2 ms |
4948 KB |
Output is correct |
8 |
Correct |
2 ms |
4948 KB |
Output is correct |
9 |
Correct |
223 ms |
23924 KB |
Output is correct |
10 |
Correct |
14 ms |
7124 KB |
Output is correct |
11 |
Correct |
82 ms |
15256 KB |
Output is correct |
12 |
Correct |
20 ms |
8160 KB |
Output is correct |
13 |
Correct |
56 ms |
11584 KB |
Output is correct |
14 |
Correct |
3 ms |
5076 KB |
Output is correct |
15 |
Correct |
4 ms |
5204 KB |
Output is correct |
16 |
Correct |
192 ms |
22620 KB |
Output is correct |
17 |
Correct |
551 ms |
43500 KB |
Output is correct |
18 |
Incorrect |
527 ms |
40788 KB |
Tree @(50003, 100001) appears more than once: for edges on positions 157198 and 161590 |
19 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
4948 KB |
Output is correct |
2 |
Correct |
2 ms |
4948 KB |
Output is correct |
3 |
Correct |
2 ms |
4948 KB |
Output is correct |
4 |
Correct |
2 ms |
4948 KB |
Output is correct |
5 |
Correct |
2 ms |
4948 KB |
Output is correct |
6 |
Correct |
2 ms |
4948 KB |
Output is correct |
7 |
Correct |
2 ms |
4948 KB |
Output is correct |
8 |
Correct |
2 ms |
4948 KB |
Output is correct |
9 |
Correct |
223 ms |
23924 KB |
Output is correct |
10 |
Correct |
14 ms |
7124 KB |
Output is correct |
11 |
Correct |
82 ms |
15256 KB |
Output is correct |
12 |
Correct |
20 ms |
8160 KB |
Output is correct |
13 |
Correct |
56 ms |
11584 KB |
Output is correct |
14 |
Correct |
3 ms |
5076 KB |
Output is correct |
15 |
Correct |
4 ms |
5204 KB |
Output is correct |
16 |
Correct |
192 ms |
22620 KB |
Output is correct |
17 |
Incorrect |
2 ms |
4948 KB |
Tree @(3, 3) appears more than once: for edges on positions 0 and 1 |
18 |
Halted |
0 ms |
0 KB |
- |