#include <bits/stdc++.h>
#include "parks.h"
using namespace std;
const int maxn = 2e5+10;
struct Pt
{
int x, y, ind;
} a[maxn];
struct Road
{
int u, v, x, y;
} road[maxn];
struct DSU
{
int pai[maxn], peso[maxn];
void init(int n)
{
for (int i = 1; i <= n; i++)
pai[i] = i;
}
int Find(int x)
{
if (pai[x] == x) return x;
return pai[x] = Find(pai[x]);
}
void Join(int x, int y)
{
if (x == y) return;
if (peso[x] < peso[y]) swap(x, y);
pai[y] = x, peso[x] += peso[y];
}
} dsu;
bool comp(Pt a, Pt b)
{
if (a.x == b.x) return a.y < b.y;
return a.x < b.x;
}
int construct_roads(vector<int> X, vector<int> Y)
{
int n = X.size();
bool sub = 1;
int mn = 8, mx = 0;
map<pair<int, int>, int> mp;
for (int i = 1; i <= n; i++)
{
a[i] = {X[i-1], Y[i-1], i};
mp[{a[i].x, a[i].y}] = i;
mx = max(mx, a[i].x);
mn = min(mn, a[i].x);
}
if (mx > 6) sub = 0;
dsu.init(n);
if (sub)
{
map<pair<int, int>, int> bench;
sort(a+1, a+n+1, comp);
int ind = 0, cc = n;
for (int i = 1; i < n; i++)
{
if (dsu.Find(a[i].ind) != dsu.Find(a[i+1].ind) && a[i].x == a[i+1].x && a[i].y+2 == a[i+1].y)
{
dsu.Join(a[i].ind, a[i+1].ind), cc--;
road[++ind] = {a[i].ind, a[i+1].ind, a[i].x-1, a[i].y+1};
if (a[i].x == mx)
{
road[ind].x = a[i].x+1, road[ind].y = a[i].y+1;
bench[{a[i].x+1, a[i].y+1}] = 1;
}
else if (a[i].x == mn)
{
bench[{a[i].x-1, a[i].y+1}] = 1;
}
else
{
if (bench[{a[i].x-1, a[i].y+1}] == 1)
{
road[ind].x = a[i].x+1, road[ind].y = a[i].y+1;
bench[{a[i].x+1, a[i].y+1}] = 1;
}
else
{
bench[{a[i].x-1, a[i].y+1}] = 1;
}
}
}
if (mp[{a[i].x+2, a[i].y}] && dsu.Find(a[i].ind) != dsu.Find(mp[{a[i].x+2, a[i].y}]))
{
dsu.Join(a[i].ind, mp[{a[i].x+2, a[i].y}]), cc--;
if (bench[{a[i].x+1, a[i].y+1}])
{
road[++ind] = {a[i].ind, mp[{a[i].x+2, a[i].y}], a[i].x+1, a[i].y-1};
bench[{a[i].x+1, a[i].y-1}] = 1;
}
else
{
road[++ind] = {a[i].ind, mp[{a[i].x+2, a[i].y}], a[i].x+1, a[i].y+1};
bench[{a[i].x+1, a[i].y+1}] = 1;
}
}
}
if (cc != 1) return 0;
vector<int> U, V, A, B;
for (int i = 1; i < n; i++)
{
U.push_back(road[i].u-1), V.push_back(road[i].v-1);
A.push_back(road[i].x), B.push_back(road[i].y);
}
build(U, V, A, B);
return 1;
}
}
Compilation message
parks.cpp: In function 'int construct_roads(std::vector<int>, std::vector<int>)':
parks.cpp:57:30: warning: control reaches end of non-void function [-Wreturn-type]
57 | map<pair<int, int>, int> mp;
| ^~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
204 KB |
Output is correct |
2 |
Correct |
0 ms |
204 KB |
Output is correct |
3 |
Correct |
1 ms |
204 KB |
Output is correct |
4 |
Correct |
0 ms |
204 KB |
Output is correct |
5 |
Correct |
0 ms |
204 KB |
Output is correct |
6 |
Correct |
0 ms |
204 KB |
Output is correct |
7 |
Correct |
0 ms |
204 KB |
Output is correct |
8 |
Correct |
0 ms |
204 KB |
Output is correct |
9 |
Correct |
177 ms |
28972 KB |
Output is correct |
10 |
Correct |
14 ms |
3404 KB |
Output is correct |
11 |
Correct |
78 ms |
15844 KB |
Output is correct |
12 |
Correct |
20 ms |
4832 KB |
Output is correct |
13 |
Correct |
46 ms |
10768 KB |
Output is correct |
14 |
Correct |
1 ms |
460 KB |
Output is correct |
15 |
Correct |
2 ms |
716 KB |
Output is correct |
16 |
Correct |
181 ms |
28952 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
204 KB |
Output is correct |
2 |
Correct |
0 ms |
204 KB |
Output is correct |
3 |
Correct |
1 ms |
204 KB |
Output is correct |
4 |
Correct |
0 ms |
204 KB |
Output is correct |
5 |
Correct |
0 ms |
204 KB |
Output is correct |
6 |
Correct |
0 ms |
204 KB |
Output is correct |
7 |
Correct |
0 ms |
204 KB |
Output is correct |
8 |
Correct |
0 ms |
204 KB |
Output is correct |
9 |
Correct |
177 ms |
28972 KB |
Output is correct |
10 |
Correct |
14 ms |
3404 KB |
Output is correct |
11 |
Correct |
78 ms |
15844 KB |
Output is correct |
12 |
Correct |
20 ms |
4832 KB |
Output is correct |
13 |
Correct |
46 ms |
10768 KB |
Output is correct |
14 |
Correct |
1 ms |
460 KB |
Output is correct |
15 |
Correct |
2 ms |
716 KB |
Output is correct |
16 |
Correct |
181 ms |
28952 KB |
Output is correct |
17 |
Correct |
0 ms |
204 KB |
Output is correct |
18 |
Correct |
0 ms |
204 KB |
Output is correct |
19 |
Correct |
0 ms |
204 KB |
Output is correct |
20 |
Correct |
0 ms |
204 KB |
Output is correct |
21 |
Correct |
0 ms |
204 KB |
Output is correct |
22 |
Correct |
0 ms |
204 KB |
Output is correct |
23 |
Correct |
451 ms |
51216 KB |
Output is correct |
24 |
Correct |
0 ms |
204 KB |
Output is correct |
25 |
Correct |
2 ms |
588 KB |
Output is correct |
26 |
Correct |
4 ms |
972 KB |
Output is correct |
27 |
Correct |
6 ms |
1228 KB |
Output is correct |
28 |
Correct |
153 ms |
20824 KB |
Output is correct |
29 |
Correct |
238 ms |
30992 KB |
Output is correct |
30 |
Correct |
351 ms |
41268 KB |
Output is correct |
31 |
Correct |
445 ms |
51228 KB |
Output is correct |
32 |
Correct |
0 ms |
204 KB |
Output is correct |
33 |
Correct |
0 ms |
204 KB |
Output is correct |
34 |
Correct |
1 ms |
204 KB |
Output is correct |
35 |
Correct |
0 ms |
204 KB |
Output is correct |
36 |
Correct |
0 ms |
204 KB |
Output is correct |
37 |
Correct |
0 ms |
204 KB |
Output is correct |
38 |
Correct |
0 ms |
204 KB |
Output is correct |
39 |
Correct |
1 ms |
204 KB |
Output is correct |
40 |
Correct |
0 ms |
204 KB |
Output is correct |
41 |
Correct |
1 ms |
204 KB |
Output is correct |
42 |
Correct |
0 ms |
204 KB |
Output is correct |
43 |
Correct |
2 ms |
716 KB |
Output is correct |
44 |
Correct |
4 ms |
960 KB |
Output is correct |
45 |
Correct |
185 ms |
27052 KB |
Output is correct |
46 |
Correct |
293 ms |
39060 KB |
Output is correct |
47 |
Correct |
284 ms |
39064 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
204 KB |
Output is correct |
2 |
Correct |
0 ms |
204 KB |
Output is correct |
3 |
Correct |
1 ms |
204 KB |
Output is correct |
4 |
Correct |
0 ms |
204 KB |
Output is correct |
5 |
Correct |
0 ms |
204 KB |
Output is correct |
6 |
Correct |
0 ms |
204 KB |
Output is correct |
7 |
Correct |
0 ms |
204 KB |
Output is correct |
8 |
Correct |
0 ms |
204 KB |
Output is correct |
9 |
Correct |
177 ms |
28972 KB |
Output is correct |
10 |
Correct |
14 ms |
3404 KB |
Output is correct |
11 |
Correct |
78 ms |
15844 KB |
Output is correct |
12 |
Correct |
20 ms |
4832 KB |
Output is correct |
13 |
Correct |
46 ms |
10768 KB |
Output is correct |
14 |
Correct |
1 ms |
460 KB |
Output is correct |
15 |
Correct |
2 ms |
716 KB |
Output is correct |
16 |
Correct |
181 ms |
28952 KB |
Output is correct |
17 |
Correct |
0 ms |
204 KB |
Output is correct |
18 |
Correct |
0 ms |
204 KB |
Output is correct |
19 |
Correct |
0 ms |
204 KB |
Output is correct |
20 |
Correct |
0 ms |
204 KB |
Output is correct |
21 |
Correct |
0 ms |
204 KB |
Output is correct |
22 |
Correct |
0 ms |
204 KB |
Output is correct |
23 |
Correct |
451 ms |
51216 KB |
Output is correct |
24 |
Correct |
0 ms |
204 KB |
Output is correct |
25 |
Correct |
2 ms |
588 KB |
Output is correct |
26 |
Correct |
4 ms |
972 KB |
Output is correct |
27 |
Correct |
6 ms |
1228 KB |
Output is correct |
28 |
Correct |
153 ms |
20824 KB |
Output is correct |
29 |
Correct |
238 ms |
30992 KB |
Output is correct |
30 |
Correct |
351 ms |
41268 KB |
Output is correct |
31 |
Correct |
445 ms |
51228 KB |
Output is correct |
32 |
Correct |
0 ms |
204 KB |
Output is correct |
33 |
Correct |
0 ms |
204 KB |
Output is correct |
34 |
Correct |
1 ms |
204 KB |
Output is correct |
35 |
Correct |
0 ms |
204 KB |
Output is correct |
36 |
Correct |
0 ms |
204 KB |
Output is correct |
37 |
Correct |
0 ms |
204 KB |
Output is correct |
38 |
Correct |
0 ms |
204 KB |
Output is correct |
39 |
Correct |
1 ms |
204 KB |
Output is correct |
40 |
Correct |
0 ms |
204 KB |
Output is correct |
41 |
Correct |
1 ms |
204 KB |
Output is correct |
42 |
Correct |
0 ms |
204 KB |
Output is correct |
43 |
Correct |
2 ms |
716 KB |
Output is correct |
44 |
Correct |
4 ms |
960 KB |
Output is correct |
45 |
Correct |
185 ms |
27052 KB |
Output is correct |
46 |
Correct |
293 ms |
39060 KB |
Output is correct |
47 |
Correct |
284 ms |
39064 KB |
Output is correct |
48 |
Correct |
0 ms |
204 KB |
Output is correct |
49 |
Correct |
0 ms |
204 KB |
Output is correct |
50 |
Correct |
0 ms |
204 KB |
Output is correct |
51 |
Correct |
0 ms |
204 KB |
Output is correct |
52 |
Correct |
0 ms |
204 KB |
Output is correct |
53 |
Incorrect |
1 ms |
204 KB |
Solution announced impossible, but it is possible. |
54 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
204 KB |
Output is correct |
2 |
Correct |
0 ms |
204 KB |
Output is correct |
3 |
Correct |
1 ms |
204 KB |
Output is correct |
4 |
Correct |
0 ms |
204 KB |
Output is correct |
5 |
Correct |
0 ms |
204 KB |
Output is correct |
6 |
Correct |
0 ms |
204 KB |
Output is correct |
7 |
Correct |
0 ms |
204 KB |
Output is correct |
8 |
Correct |
0 ms |
204 KB |
Output is correct |
9 |
Correct |
177 ms |
28972 KB |
Output is correct |
10 |
Correct |
14 ms |
3404 KB |
Output is correct |
11 |
Correct |
78 ms |
15844 KB |
Output is correct |
12 |
Correct |
20 ms |
4832 KB |
Output is correct |
13 |
Correct |
46 ms |
10768 KB |
Output is correct |
14 |
Correct |
1 ms |
460 KB |
Output is correct |
15 |
Correct |
2 ms |
716 KB |
Output is correct |
16 |
Correct |
181 ms |
28952 KB |
Output is correct |
17 |
Runtime error |
4 ms |
460 KB |
Execution killed with signal 6 |
18 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
204 KB |
Output is correct |
2 |
Correct |
0 ms |
204 KB |
Output is correct |
3 |
Correct |
1 ms |
204 KB |
Output is correct |
4 |
Correct |
0 ms |
204 KB |
Output is correct |
5 |
Correct |
0 ms |
204 KB |
Output is correct |
6 |
Correct |
0 ms |
204 KB |
Output is correct |
7 |
Correct |
0 ms |
204 KB |
Output is correct |
8 |
Correct |
0 ms |
204 KB |
Output is correct |
9 |
Correct |
177 ms |
28972 KB |
Output is correct |
10 |
Correct |
14 ms |
3404 KB |
Output is correct |
11 |
Correct |
78 ms |
15844 KB |
Output is correct |
12 |
Correct |
20 ms |
4832 KB |
Output is correct |
13 |
Correct |
46 ms |
10768 KB |
Output is correct |
14 |
Correct |
1 ms |
460 KB |
Output is correct |
15 |
Correct |
2 ms |
716 KB |
Output is correct |
16 |
Correct |
181 ms |
28952 KB |
Output is correct |
17 |
Runtime error |
224 ms |
38416 KB |
Execution killed with signal 6 |
18 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
204 KB |
Output is correct |
2 |
Correct |
0 ms |
204 KB |
Output is correct |
3 |
Correct |
1 ms |
204 KB |
Output is correct |
4 |
Correct |
0 ms |
204 KB |
Output is correct |
5 |
Correct |
0 ms |
204 KB |
Output is correct |
6 |
Correct |
0 ms |
204 KB |
Output is correct |
7 |
Correct |
0 ms |
204 KB |
Output is correct |
8 |
Correct |
0 ms |
204 KB |
Output is correct |
9 |
Correct |
177 ms |
28972 KB |
Output is correct |
10 |
Correct |
14 ms |
3404 KB |
Output is correct |
11 |
Correct |
78 ms |
15844 KB |
Output is correct |
12 |
Correct |
20 ms |
4832 KB |
Output is correct |
13 |
Correct |
46 ms |
10768 KB |
Output is correct |
14 |
Correct |
1 ms |
460 KB |
Output is correct |
15 |
Correct |
2 ms |
716 KB |
Output is correct |
16 |
Correct |
181 ms |
28952 KB |
Output is correct |
17 |
Correct |
0 ms |
204 KB |
Output is correct |
18 |
Correct |
0 ms |
204 KB |
Output is correct |
19 |
Correct |
0 ms |
204 KB |
Output is correct |
20 |
Correct |
0 ms |
204 KB |
Output is correct |
21 |
Correct |
0 ms |
204 KB |
Output is correct |
22 |
Correct |
0 ms |
204 KB |
Output is correct |
23 |
Correct |
451 ms |
51216 KB |
Output is correct |
24 |
Correct |
0 ms |
204 KB |
Output is correct |
25 |
Correct |
2 ms |
588 KB |
Output is correct |
26 |
Correct |
4 ms |
972 KB |
Output is correct |
27 |
Correct |
6 ms |
1228 KB |
Output is correct |
28 |
Correct |
153 ms |
20824 KB |
Output is correct |
29 |
Correct |
238 ms |
30992 KB |
Output is correct |
30 |
Correct |
351 ms |
41268 KB |
Output is correct |
31 |
Correct |
445 ms |
51228 KB |
Output is correct |
32 |
Correct |
0 ms |
204 KB |
Output is correct |
33 |
Correct |
0 ms |
204 KB |
Output is correct |
34 |
Correct |
1 ms |
204 KB |
Output is correct |
35 |
Correct |
0 ms |
204 KB |
Output is correct |
36 |
Correct |
0 ms |
204 KB |
Output is correct |
37 |
Correct |
0 ms |
204 KB |
Output is correct |
38 |
Correct |
0 ms |
204 KB |
Output is correct |
39 |
Correct |
1 ms |
204 KB |
Output is correct |
40 |
Correct |
0 ms |
204 KB |
Output is correct |
41 |
Correct |
1 ms |
204 KB |
Output is correct |
42 |
Correct |
0 ms |
204 KB |
Output is correct |
43 |
Correct |
2 ms |
716 KB |
Output is correct |
44 |
Correct |
4 ms |
960 KB |
Output is correct |
45 |
Correct |
185 ms |
27052 KB |
Output is correct |
46 |
Correct |
293 ms |
39060 KB |
Output is correct |
47 |
Correct |
284 ms |
39064 KB |
Output is correct |
48 |
Correct |
0 ms |
204 KB |
Output is correct |
49 |
Correct |
0 ms |
204 KB |
Output is correct |
50 |
Correct |
0 ms |
204 KB |
Output is correct |
51 |
Correct |
0 ms |
204 KB |
Output is correct |
52 |
Correct |
0 ms |
204 KB |
Output is correct |
53 |
Incorrect |
1 ms |
204 KB |
Solution announced impossible, but it is possible. |
54 |
Halted |
0 ms |
0 KB |
- |