#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] == 2)
{
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);
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
4948 KB |
Output is correct |
2 |
Correct |
3 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 |
189 ms |
23848 KB |
Output is correct |
10 |
Correct |
14 ms |
7124 KB |
Output is correct |
11 |
Correct |
82 ms |
15284 KB |
Output is correct |
12 |
Correct |
25 ms |
8052 KB |
Output is correct |
13 |
Correct |
62 ms |
11612 KB |
Output is correct |
14 |
Correct |
3 ms |
5076 KB |
Output is correct |
15 |
Correct |
4 ms |
5204 KB |
Output is correct |
16 |
Correct |
188 ms |
22572 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
4948 KB |
Output is correct |
2 |
Correct |
3 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 |
189 ms |
23848 KB |
Output is correct |
10 |
Correct |
14 ms |
7124 KB |
Output is correct |
11 |
Correct |
82 ms |
15284 KB |
Output is correct |
12 |
Correct |
25 ms |
8052 KB |
Output is correct |
13 |
Correct |
62 ms |
11612 KB |
Output is correct |
14 |
Correct |
3 ms |
5076 KB |
Output is correct |
15 |
Correct |
4 ms |
5204 KB |
Output is correct |
16 |
Correct |
188 ms |
22572 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 |
Correct |
2 ms |
4948 KB |
Output is correct |
21 |
Correct |
3 ms |
4948 KB |
Output is correct |
22 |
Correct |
2 ms |
4948 KB |
Output is correct |
23 |
Correct |
661 ms |
47248 KB |
Output is correct |
24 |
Correct |
3 ms |
4948 KB |
Output is correct |
25 |
Correct |
6 ms |
5244 KB |
Output is correct |
26 |
Correct |
9 ms |
5460 KB |
Output is correct |
27 |
Correct |
10 ms |
5540 KB |
Output is correct |
28 |
Correct |
220 ms |
22148 KB |
Output is correct |
29 |
Correct |
378 ms |
29960 KB |
Output is correct |
30 |
Correct |
589 ms |
38968 KB |
Output is correct |
31 |
Correct |
628 ms |
46776 KB |
Output is correct |
32 |
Correct |
3 ms |
4948 KB |
Output is correct |
33 |
Correct |
2 ms |
4948 KB |
Output is correct |
34 |
Correct |
2 ms |
4948 KB |
Output is correct |
35 |
Correct |
2 ms |
4948 KB |
Output is correct |
36 |
Correct |
3 ms |
4948 KB |
Output is correct |
37 |
Correct |
2 ms |
4948 KB |
Output is correct |
38 |
Correct |
2 ms |
4948 KB |
Output is correct |
39 |
Correct |
3 ms |
4948 KB |
Output is correct |
40 |
Correct |
3 ms |
4948 KB |
Output is correct |
41 |
Correct |
3 ms |
4948 KB |
Output is correct |
42 |
Correct |
2 ms |
4948 KB |
Output is correct |
43 |
Correct |
6 ms |
5204 KB |
Output is correct |
44 |
Correct |
6 ms |
5332 KB |
Output is correct |
45 |
Correct |
219 ms |
22900 KB |
Output is correct |
46 |
Correct |
378 ms |
31288 KB |
Output is correct |
47 |
Correct |
378 ms |
31068 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
4948 KB |
Output is correct |
2 |
Correct |
3 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 |
189 ms |
23848 KB |
Output is correct |
10 |
Correct |
14 ms |
7124 KB |
Output is correct |
11 |
Correct |
82 ms |
15284 KB |
Output is correct |
12 |
Correct |
25 ms |
8052 KB |
Output is correct |
13 |
Correct |
62 ms |
11612 KB |
Output is correct |
14 |
Correct |
3 ms |
5076 KB |
Output is correct |
15 |
Correct |
4 ms |
5204 KB |
Output is correct |
16 |
Correct |
188 ms |
22572 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 |
Correct |
2 ms |
4948 KB |
Output is correct |
21 |
Correct |
3 ms |
4948 KB |
Output is correct |
22 |
Correct |
2 ms |
4948 KB |
Output is correct |
23 |
Correct |
661 ms |
47248 KB |
Output is correct |
24 |
Correct |
3 ms |
4948 KB |
Output is correct |
25 |
Correct |
6 ms |
5244 KB |
Output is correct |
26 |
Correct |
9 ms |
5460 KB |
Output is correct |
27 |
Correct |
10 ms |
5540 KB |
Output is correct |
28 |
Correct |
220 ms |
22148 KB |
Output is correct |
29 |
Correct |
378 ms |
29960 KB |
Output is correct |
30 |
Correct |
589 ms |
38968 KB |
Output is correct |
31 |
Correct |
628 ms |
46776 KB |
Output is correct |
32 |
Correct |
3 ms |
4948 KB |
Output is correct |
33 |
Correct |
2 ms |
4948 KB |
Output is correct |
34 |
Correct |
2 ms |
4948 KB |
Output is correct |
35 |
Correct |
2 ms |
4948 KB |
Output is correct |
36 |
Correct |
3 ms |
4948 KB |
Output is correct |
37 |
Correct |
2 ms |
4948 KB |
Output is correct |
38 |
Correct |
2 ms |
4948 KB |
Output is correct |
39 |
Correct |
3 ms |
4948 KB |
Output is correct |
40 |
Correct |
3 ms |
4948 KB |
Output is correct |
41 |
Correct |
3 ms |
4948 KB |
Output is correct |
42 |
Correct |
2 ms |
4948 KB |
Output is correct |
43 |
Correct |
6 ms |
5204 KB |
Output is correct |
44 |
Correct |
6 ms |
5332 KB |
Output is correct |
45 |
Correct |
219 ms |
22900 KB |
Output is correct |
46 |
Correct |
378 ms |
31288 KB |
Output is correct |
47 |
Correct |
378 ms |
31068 KB |
Output is correct |
48 |
Incorrect |
3 ms |
4948 KB |
Tree @(5, 3) appears more than once: for edges on positions 2 and 3 |
49 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
4948 KB |
Output is correct |
2 |
Correct |
3 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 |
189 ms |
23848 KB |
Output is correct |
10 |
Correct |
14 ms |
7124 KB |
Output is correct |
11 |
Correct |
82 ms |
15284 KB |
Output is correct |
12 |
Correct |
25 ms |
8052 KB |
Output is correct |
13 |
Correct |
62 ms |
11612 KB |
Output is correct |
14 |
Correct |
3 ms |
5076 KB |
Output is correct |
15 |
Correct |
4 ms |
5204 KB |
Output is correct |
16 |
Correct |
188 ms |
22572 KB |
Output is correct |
17 |
Correct |
3 ms |
4948 KB |
Output is correct |
18 |
Correct |
2 ms |
4960 KB |
Output is correct |
19 |
Correct |
3 ms |
4948 KB |
Output is correct |
20 |
Correct |
546 ms |
43304 KB |
Output is correct |
21 |
Incorrect |
567 ms |
41944 KB |
Tree @(56859, 56863) appears more than once: for edges on positions 0 and 1 |
22 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
4948 KB |
Output is correct |
2 |
Correct |
3 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 |
189 ms |
23848 KB |
Output is correct |
10 |
Correct |
14 ms |
7124 KB |
Output is correct |
11 |
Correct |
82 ms |
15284 KB |
Output is correct |
12 |
Correct |
25 ms |
8052 KB |
Output is correct |
13 |
Correct |
62 ms |
11612 KB |
Output is correct |
14 |
Correct |
3 ms |
5076 KB |
Output is correct |
15 |
Correct |
4 ms |
5204 KB |
Output is correct |
16 |
Correct |
188 ms |
22572 KB |
Output is correct |
17 |
Correct |
503 ms |
43316 KB |
Output is correct |
18 |
Incorrect |
486 ms |
40864 KB |
Tree @(50003, 100001) appears more than once: for edges on positions 157198 and 161590 |
19 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
4948 KB |
Output is correct |
2 |
Correct |
3 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 |
189 ms |
23848 KB |
Output is correct |
10 |
Correct |
14 ms |
7124 KB |
Output is correct |
11 |
Correct |
82 ms |
15284 KB |
Output is correct |
12 |
Correct |
25 ms |
8052 KB |
Output is correct |
13 |
Correct |
62 ms |
11612 KB |
Output is correct |
14 |
Correct |
3 ms |
5076 KB |
Output is correct |
15 |
Correct |
4 ms |
5204 KB |
Output is correct |
16 |
Correct |
188 ms |
22572 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 |
Correct |
2 ms |
4948 KB |
Output is correct |
21 |
Correct |
3 ms |
4948 KB |
Output is correct |
22 |
Correct |
2 ms |
4948 KB |
Output is correct |
23 |
Correct |
661 ms |
47248 KB |
Output is correct |
24 |
Correct |
3 ms |
4948 KB |
Output is correct |
25 |
Correct |
6 ms |
5244 KB |
Output is correct |
26 |
Correct |
9 ms |
5460 KB |
Output is correct |
27 |
Correct |
10 ms |
5540 KB |
Output is correct |
28 |
Correct |
220 ms |
22148 KB |
Output is correct |
29 |
Correct |
378 ms |
29960 KB |
Output is correct |
30 |
Correct |
589 ms |
38968 KB |
Output is correct |
31 |
Correct |
628 ms |
46776 KB |
Output is correct |
32 |
Correct |
3 ms |
4948 KB |
Output is correct |
33 |
Correct |
2 ms |
4948 KB |
Output is correct |
34 |
Correct |
2 ms |
4948 KB |
Output is correct |
35 |
Correct |
2 ms |
4948 KB |
Output is correct |
36 |
Correct |
3 ms |
4948 KB |
Output is correct |
37 |
Correct |
2 ms |
4948 KB |
Output is correct |
38 |
Correct |
2 ms |
4948 KB |
Output is correct |
39 |
Correct |
3 ms |
4948 KB |
Output is correct |
40 |
Correct |
3 ms |
4948 KB |
Output is correct |
41 |
Correct |
3 ms |
4948 KB |
Output is correct |
42 |
Correct |
2 ms |
4948 KB |
Output is correct |
43 |
Correct |
6 ms |
5204 KB |
Output is correct |
44 |
Correct |
6 ms |
5332 KB |
Output is correct |
45 |
Correct |
219 ms |
22900 KB |
Output is correct |
46 |
Correct |
378 ms |
31288 KB |
Output is correct |
47 |
Correct |
378 ms |
31068 KB |
Output is correct |
48 |
Incorrect |
3 ms |
4948 KB |
Tree @(5, 3) appears more than once: for edges on positions 2 and 3 |
49 |
Halted |
0 ms |
0 KB |
- |