#include "parks.h"
#include <vector>
using namespace std;
int coord[3][100005];
bool bench[4][100005];
struct UnionFind
{
vector<int> par;
UnionFind(int N)
{
par.resize(N+1);
for (int i = 0; i <= N; i++) par[i] = i;
}
int fin(int v)
{
return v == par[v] ? v : (par[v] = fin(par[v]));
}
void uni(int u, int v)
{
par[fin(u)] = fin(v);
}
bool isuni(int u, int v)
{
return fin(u) == fin(v);
}
};
int construct_roads(std::vector<int> x, std::vector<int> y) {
int N = x.size();
fill(&coord[0][0], &coord[2][100005], -1);
for (int i = 0; i < N; i++) {
coord[(x[i]-2)/2][y[i]/2] = i;
}
UnionFind uf(N);
vector<int> u, v, a, b;
for (int i = 1; i < 100000; i++) {
if (coord[0][i] != -1 && coord[0][i+1] != -1) {
uf.uni(coord[0][i], coord[0][i+1]);
u.push_back(coord[0][i]);
v.push_back(coord[0][i+1]);
a.push_back(1);
b.push_back(2*i+1);
}
if (coord[2][i] != -1 && coord[2][i+1] != -1) {
uf.uni(coord[2][i], coord[2][i+1]);
u.push_back(coord[2][i]);
v.push_back(coord[2][i+1]);
a.push_back(7);
b.push_back(2*i+1);
}
}
vector<pair<int, int>> edge;
for (int i = 1; i <= 100000; i++) {
if (coord[0][i] != -1 && coord[1][i] != -1) {
uf.uni(coord[0][i], coord[1][i]);
edge.push_back(make_pair(coord[0][i], coord[1][i]));
}
if (coord[1][i] != -1 && coord[2][i] != -1) {
uf.uni(coord[1][i], coord[2][i]);
edge.push_back(make_pair(coord[1][i], coord[2][i]));
}
}
bool flag = false;
for (int i = 1; i < 100000; i++) {
if (coord[1][i] != -1 && coord[1][i+1] != -1) {
if (uf.isuni(coord[1][i], coord[1][i+1])) continue;
uf.uni(coord[1][i], coord[1][i+1]);
u.push_back(coord[1][i]);
v.push_back(coord[1][i+1]);
b.push_back(2*i+1);
if (!flag) a.push_back(3);
else a.push_back(5);
bench[a.back()/2][b.back()/2] = true;
flag = !flag;
}
}
for (pair<int, int> p:edge) {
u.push_back(p.first);
v.push_back(p.second);
int xc = x[p.first] + x[p.second] >> 1;
int yc = y[p.first];
a.push_back(xc);
if (!bench[xc/2][yc/2-1]) b.push_back(yc-1);
else b.push_back(yc+1);
bench[a.back()/2][b.back()/2] = true;
}
for (int i = 0; i < N; i++) {
if (!uf.isuni(0, 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:80:29: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
80 | int xc = x[p.first] + x[p.second] >> 1;
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
1364 KB |
Output is correct |
2 |
Correct |
1 ms |
1364 KB |
Output is correct |
3 |
Correct |
1 ms |
1364 KB |
Output is correct |
4 |
Correct |
1 ms |
1364 KB |
Output is correct |
5 |
Correct |
1 ms |
1364 KB |
Output is correct |
6 |
Correct |
1 ms |
1364 KB |
Output is correct |
7 |
Correct |
1 ms |
1428 KB |
Output is correct |
8 |
Correct |
1 ms |
1364 KB |
Output is correct |
9 |
Correct |
39 ms |
9284 KB |
Output is correct |
10 |
Correct |
4 ms |
2388 KB |
Output is correct |
11 |
Correct |
19 ms |
5812 KB |
Output is correct |
12 |
Correct |
7 ms |
2900 KB |
Output is correct |
13 |
Correct |
9 ms |
3532 KB |
Output is correct |
14 |
Correct |
1 ms |
1492 KB |
Output is correct |
15 |
Correct |
1 ms |
1492 KB |
Output is correct |
16 |
Correct |
38 ms |
8764 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
1364 KB |
Output is correct |
2 |
Correct |
1 ms |
1364 KB |
Output is correct |
3 |
Correct |
1 ms |
1364 KB |
Output is correct |
4 |
Correct |
1 ms |
1364 KB |
Output is correct |
5 |
Correct |
1 ms |
1364 KB |
Output is correct |
6 |
Correct |
1 ms |
1364 KB |
Output is correct |
7 |
Correct |
1 ms |
1428 KB |
Output is correct |
8 |
Correct |
1 ms |
1364 KB |
Output is correct |
9 |
Correct |
39 ms |
9284 KB |
Output is correct |
10 |
Correct |
4 ms |
2388 KB |
Output is correct |
11 |
Correct |
19 ms |
5812 KB |
Output is correct |
12 |
Correct |
7 ms |
2900 KB |
Output is correct |
13 |
Correct |
9 ms |
3532 KB |
Output is correct |
14 |
Correct |
1 ms |
1492 KB |
Output is correct |
15 |
Correct |
1 ms |
1492 KB |
Output is correct |
16 |
Correct |
38 ms |
8764 KB |
Output is correct |
17 |
Correct |
1 ms |
1364 KB |
Output is correct |
18 |
Correct |
1 ms |
1364 KB |
Output is correct |
19 |
Correct |
1 ms |
1364 KB |
Output is correct |
20 |
Correct |
1 ms |
1364 KB |
Output is correct |
21 |
Correct |
1 ms |
1364 KB |
Output is correct |
22 |
Correct |
1 ms |
1364 KB |
Output is correct |
23 |
Correct |
82 ms |
16928 KB |
Output is correct |
24 |
Correct |
1 ms |
1364 KB |
Output is correct |
25 |
Correct |
2 ms |
1492 KB |
Output is correct |
26 |
Correct |
2 ms |
1620 KB |
Output is correct |
27 |
Correct |
2 ms |
1748 KB |
Output is correct |
28 |
Correct |
32 ms |
8328 KB |
Output is correct |
29 |
Correct |
49 ms |
11824 KB |
Output is correct |
30 |
Correct |
66 ms |
15268 KB |
Output is correct |
31 |
Correct |
82 ms |
18628 KB |
Output is correct |
32 |
Correct |
1 ms |
1364 KB |
Output is correct |
33 |
Correct |
1 ms |
1364 KB |
Output is correct |
34 |
Correct |
1 ms |
1364 KB |
Output is correct |
35 |
Correct |
1 ms |
1364 KB |
Output is correct |
36 |
Correct |
1 ms |
1364 KB |
Output is correct |
37 |
Correct |
1 ms |
1364 KB |
Output is correct |
38 |
Correct |
1 ms |
1452 KB |
Output is correct |
39 |
Correct |
1 ms |
1364 KB |
Output is correct |
40 |
Correct |
1 ms |
1452 KB |
Output is correct |
41 |
Correct |
1 ms |
1364 KB |
Output is correct |
42 |
Correct |
1 ms |
1364 KB |
Output is correct |
43 |
Correct |
1 ms |
1596 KB |
Output is correct |
44 |
Correct |
2 ms |
1596 KB |
Output is correct |
45 |
Correct |
40 ms |
9716 KB |
Output is correct |
46 |
Correct |
60 ms |
13344 KB |
Output is correct |
47 |
Correct |
57 ms |
13088 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
1364 KB |
Output is correct |
2 |
Correct |
1 ms |
1364 KB |
Output is correct |
3 |
Correct |
1 ms |
1364 KB |
Output is correct |
4 |
Correct |
1 ms |
1364 KB |
Output is correct |
5 |
Correct |
1 ms |
1364 KB |
Output is correct |
6 |
Correct |
1 ms |
1364 KB |
Output is correct |
7 |
Correct |
1 ms |
1428 KB |
Output is correct |
8 |
Correct |
1 ms |
1364 KB |
Output is correct |
9 |
Correct |
39 ms |
9284 KB |
Output is correct |
10 |
Correct |
4 ms |
2388 KB |
Output is correct |
11 |
Correct |
19 ms |
5812 KB |
Output is correct |
12 |
Correct |
7 ms |
2900 KB |
Output is correct |
13 |
Correct |
9 ms |
3532 KB |
Output is correct |
14 |
Correct |
1 ms |
1492 KB |
Output is correct |
15 |
Correct |
1 ms |
1492 KB |
Output is correct |
16 |
Correct |
38 ms |
8764 KB |
Output is correct |
17 |
Correct |
1 ms |
1364 KB |
Output is correct |
18 |
Correct |
1 ms |
1364 KB |
Output is correct |
19 |
Correct |
1 ms |
1364 KB |
Output is correct |
20 |
Correct |
1 ms |
1364 KB |
Output is correct |
21 |
Correct |
1 ms |
1364 KB |
Output is correct |
22 |
Correct |
1 ms |
1364 KB |
Output is correct |
23 |
Correct |
82 ms |
16928 KB |
Output is correct |
24 |
Correct |
1 ms |
1364 KB |
Output is correct |
25 |
Correct |
2 ms |
1492 KB |
Output is correct |
26 |
Correct |
2 ms |
1620 KB |
Output is correct |
27 |
Correct |
2 ms |
1748 KB |
Output is correct |
28 |
Correct |
32 ms |
8328 KB |
Output is correct |
29 |
Correct |
49 ms |
11824 KB |
Output is correct |
30 |
Correct |
66 ms |
15268 KB |
Output is correct |
31 |
Correct |
82 ms |
18628 KB |
Output is correct |
32 |
Correct |
1 ms |
1364 KB |
Output is correct |
33 |
Correct |
1 ms |
1364 KB |
Output is correct |
34 |
Correct |
1 ms |
1364 KB |
Output is correct |
35 |
Correct |
1 ms |
1364 KB |
Output is correct |
36 |
Correct |
1 ms |
1364 KB |
Output is correct |
37 |
Correct |
1 ms |
1364 KB |
Output is correct |
38 |
Correct |
1 ms |
1452 KB |
Output is correct |
39 |
Correct |
1 ms |
1364 KB |
Output is correct |
40 |
Correct |
1 ms |
1452 KB |
Output is correct |
41 |
Correct |
1 ms |
1364 KB |
Output is correct |
42 |
Correct |
1 ms |
1364 KB |
Output is correct |
43 |
Correct |
1 ms |
1596 KB |
Output is correct |
44 |
Correct |
2 ms |
1596 KB |
Output is correct |
45 |
Correct |
40 ms |
9716 KB |
Output is correct |
46 |
Correct |
60 ms |
13344 KB |
Output is correct |
47 |
Correct |
57 ms |
13088 KB |
Output is correct |
48 |
Correct |
1 ms |
1364 KB |
Output is correct |
49 |
Correct |
1 ms |
1364 KB |
Output is correct |
50 |
Correct |
1 ms |
1364 KB |
Output is correct |
51 |
Correct |
1 ms |
1364 KB |
Output is correct |
52 |
Correct |
1 ms |
1364 KB |
Output is correct |
53 |
Correct |
1 ms |
1364 KB |
Output is correct |
54 |
Correct |
1 ms |
1364 KB |
Output is correct |
55 |
Correct |
98 ms |
21576 KB |
Output is correct |
56 |
Correct |
1 ms |
1364 KB |
Output is correct |
57 |
Correct |
2 ms |
1620 KB |
Output is correct |
58 |
Correct |
4 ms |
2260 KB |
Output is correct |
59 |
Correct |
3 ms |
2160 KB |
Output is correct |
60 |
Correct |
47 ms |
11528 KB |
Output is correct |
61 |
Correct |
65 ms |
14992 KB |
Output is correct |
62 |
Correct |
79 ms |
18176 KB |
Output is correct |
63 |
Correct |
112 ms |
21644 KB |
Output is correct |
64 |
Correct |
1 ms |
1364 KB |
Output is correct |
65 |
Correct |
1 ms |
1364 KB |
Output is correct |
66 |
Correct |
1 ms |
1364 KB |
Output is correct |
67 |
Correct |
79 ms |
17444 KB |
Output is correct |
68 |
Correct |
89 ms |
17760 KB |
Output is correct |
69 |
Correct |
77 ms |
17032 KB |
Output is correct |
70 |
Correct |
2 ms |
1620 KB |
Output is correct |
71 |
Correct |
3 ms |
1840 KB |
Output is correct |
72 |
Correct |
45 ms |
9512 KB |
Output is correct |
73 |
Correct |
62 ms |
13584 KB |
Output is correct |
74 |
Correct |
80 ms |
17488 KB |
Output is correct |
75 |
Correct |
87 ms |
20116 KB |
Output is correct |
76 |
Correct |
76 ms |
17692 KB |
Output is correct |
77 |
Correct |
2 ms |
1748 KB |
Output is correct |
78 |
Correct |
3 ms |
2004 KB |
Output is correct |
79 |
Correct |
41 ms |
9884 KB |
Output is correct |
80 |
Correct |
64 ms |
14244 KB |
Output is correct |
81 |
Correct |
84 ms |
18584 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
1364 KB |
Output is correct |
2 |
Correct |
1 ms |
1364 KB |
Output is correct |
3 |
Correct |
1 ms |
1364 KB |
Output is correct |
4 |
Correct |
1 ms |
1364 KB |
Output is correct |
5 |
Correct |
1 ms |
1364 KB |
Output is correct |
6 |
Correct |
1 ms |
1364 KB |
Output is correct |
7 |
Correct |
1 ms |
1428 KB |
Output is correct |
8 |
Correct |
1 ms |
1364 KB |
Output is correct |
9 |
Correct |
39 ms |
9284 KB |
Output is correct |
10 |
Correct |
4 ms |
2388 KB |
Output is correct |
11 |
Correct |
19 ms |
5812 KB |
Output is correct |
12 |
Correct |
7 ms |
2900 KB |
Output is correct |
13 |
Correct |
9 ms |
3532 KB |
Output is correct |
14 |
Correct |
1 ms |
1492 KB |
Output is correct |
15 |
Correct |
1 ms |
1492 KB |
Output is correct |
16 |
Correct |
38 ms |
8764 KB |
Output is correct |
17 |
Runtime error |
3 ms |
2772 KB |
Execution killed with signal 11 |
18 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
1364 KB |
Output is correct |
2 |
Correct |
1 ms |
1364 KB |
Output is correct |
3 |
Correct |
1 ms |
1364 KB |
Output is correct |
4 |
Correct |
1 ms |
1364 KB |
Output is correct |
5 |
Correct |
1 ms |
1364 KB |
Output is correct |
6 |
Correct |
1 ms |
1364 KB |
Output is correct |
7 |
Correct |
1 ms |
1428 KB |
Output is correct |
8 |
Correct |
1 ms |
1364 KB |
Output is correct |
9 |
Correct |
39 ms |
9284 KB |
Output is correct |
10 |
Correct |
4 ms |
2388 KB |
Output is correct |
11 |
Correct |
19 ms |
5812 KB |
Output is correct |
12 |
Correct |
7 ms |
2900 KB |
Output is correct |
13 |
Correct |
9 ms |
3532 KB |
Output is correct |
14 |
Correct |
1 ms |
1492 KB |
Output is correct |
15 |
Correct |
1 ms |
1492 KB |
Output is correct |
16 |
Correct |
38 ms |
8764 KB |
Output is correct |
17 |
Runtime error |
36 ms |
9108 KB |
Execution killed with signal 11 |
18 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
1364 KB |
Output is correct |
2 |
Correct |
1 ms |
1364 KB |
Output is correct |
3 |
Correct |
1 ms |
1364 KB |
Output is correct |
4 |
Correct |
1 ms |
1364 KB |
Output is correct |
5 |
Correct |
1 ms |
1364 KB |
Output is correct |
6 |
Correct |
1 ms |
1364 KB |
Output is correct |
7 |
Correct |
1 ms |
1428 KB |
Output is correct |
8 |
Correct |
1 ms |
1364 KB |
Output is correct |
9 |
Correct |
39 ms |
9284 KB |
Output is correct |
10 |
Correct |
4 ms |
2388 KB |
Output is correct |
11 |
Correct |
19 ms |
5812 KB |
Output is correct |
12 |
Correct |
7 ms |
2900 KB |
Output is correct |
13 |
Correct |
9 ms |
3532 KB |
Output is correct |
14 |
Correct |
1 ms |
1492 KB |
Output is correct |
15 |
Correct |
1 ms |
1492 KB |
Output is correct |
16 |
Correct |
38 ms |
8764 KB |
Output is correct |
17 |
Correct |
1 ms |
1364 KB |
Output is correct |
18 |
Correct |
1 ms |
1364 KB |
Output is correct |
19 |
Correct |
1 ms |
1364 KB |
Output is correct |
20 |
Correct |
1 ms |
1364 KB |
Output is correct |
21 |
Correct |
1 ms |
1364 KB |
Output is correct |
22 |
Correct |
1 ms |
1364 KB |
Output is correct |
23 |
Correct |
82 ms |
16928 KB |
Output is correct |
24 |
Correct |
1 ms |
1364 KB |
Output is correct |
25 |
Correct |
2 ms |
1492 KB |
Output is correct |
26 |
Correct |
2 ms |
1620 KB |
Output is correct |
27 |
Correct |
2 ms |
1748 KB |
Output is correct |
28 |
Correct |
32 ms |
8328 KB |
Output is correct |
29 |
Correct |
49 ms |
11824 KB |
Output is correct |
30 |
Correct |
66 ms |
15268 KB |
Output is correct |
31 |
Correct |
82 ms |
18628 KB |
Output is correct |
32 |
Correct |
1 ms |
1364 KB |
Output is correct |
33 |
Correct |
1 ms |
1364 KB |
Output is correct |
34 |
Correct |
1 ms |
1364 KB |
Output is correct |
35 |
Correct |
1 ms |
1364 KB |
Output is correct |
36 |
Correct |
1 ms |
1364 KB |
Output is correct |
37 |
Correct |
1 ms |
1364 KB |
Output is correct |
38 |
Correct |
1 ms |
1452 KB |
Output is correct |
39 |
Correct |
1 ms |
1364 KB |
Output is correct |
40 |
Correct |
1 ms |
1452 KB |
Output is correct |
41 |
Correct |
1 ms |
1364 KB |
Output is correct |
42 |
Correct |
1 ms |
1364 KB |
Output is correct |
43 |
Correct |
1 ms |
1596 KB |
Output is correct |
44 |
Correct |
2 ms |
1596 KB |
Output is correct |
45 |
Correct |
40 ms |
9716 KB |
Output is correct |
46 |
Correct |
60 ms |
13344 KB |
Output is correct |
47 |
Correct |
57 ms |
13088 KB |
Output is correct |
48 |
Correct |
1 ms |
1364 KB |
Output is correct |
49 |
Correct |
1 ms |
1364 KB |
Output is correct |
50 |
Correct |
1 ms |
1364 KB |
Output is correct |
51 |
Correct |
1 ms |
1364 KB |
Output is correct |
52 |
Correct |
1 ms |
1364 KB |
Output is correct |
53 |
Correct |
1 ms |
1364 KB |
Output is correct |
54 |
Correct |
1 ms |
1364 KB |
Output is correct |
55 |
Correct |
98 ms |
21576 KB |
Output is correct |
56 |
Correct |
1 ms |
1364 KB |
Output is correct |
57 |
Correct |
2 ms |
1620 KB |
Output is correct |
58 |
Correct |
4 ms |
2260 KB |
Output is correct |
59 |
Correct |
3 ms |
2160 KB |
Output is correct |
60 |
Correct |
47 ms |
11528 KB |
Output is correct |
61 |
Correct |
65 ms |
14992 KB |
Output is correct |
62 |
Correct |
79 ms |
18176 KB |
Output is correct |
63 |
Correct |
112 ms |
21644 KB |
Output is correct |
64 |
Correct |
1 ms |
1364 KB |
Output is correct |
65 |
Correct |
1 ms |
1364 KB |
Output is correct |
66 |
Correct |
1 ms |
1364 KB |
Output is correct |
67 |
Correct |
79 ms |
17444 KB |
Output is correct |
68 |
Correct |
89 ms |
17760 KB |
Output is correct |
69 |
Correct |
77 ms |
17032 KB |
Output is correct |
70 |
Correct |
2 ms |
1620 KB |
Output is correct |
71 |
Correct |
3 ms |
1840 KB |
Output is correct |
72 |
Correct |
45 ms |
9512 KB |
Output is correct |
73 |
Correct |
62 ms |
13584 KB |
Output is correct |
74 |
Correct |
80 ms |
17488 KB |
Output is correct |
75 |
Correct |
87 ms |
20116 KB |
Output is correct |
76 |
Correct |
76 ms |
17692 KB |
Output is correct |
77 |
Correct |
2 ms |
1748 KB |
Output is correct |
78 |
Correct |
3 ms |
2004 KB |
Output is correct |
79 |
Correct |
41 ms |
9884 KB |
Output is correct |
80 |
Correct |
64 ms |
14244 KB |
Output is correct |
81 |
Correct |
84 ms |
18584 KB |
Output is correct |
82 |
Runtime error |
3 ms |
2772 KB |
Execution killed with signal 11 |
83 |
Halted |
0 ms |
0 KB |
- |