#include "parks.h"
#include <bits/stdc++.h>
using namespace std;
#define pb push_back
#define all(x) x.begin(), x.end()
#define en cout << '\n';
#define ll long long int
const int N = 3e5+10;
struct Dsu{
vector<int> s, p;
Dsu(int n){
s.resize(n, 1);
p.resize(n);
for(int i = 0; i < n; ++i) p[i] = i;
}
int find(int v){
if(p[v] == v) return v;
return p[v] = find(p[v]);
}
void merge(int a, int b){
a = find(a);
b = find(b);
if(a != b){
if(s[a] > s[b]) swap(a, b);
p[a] = b;
s[b] += s[a];
}
}
};
int construct_roads(std::vector<int> x, std::vector<int> y) {
if (x.size() == 1) {
build({}, {}, {}, {});
return 1;
}
int n = x.size();
vector<int> u, v, a, b;
Dsu d(n);
vector<pair<int, int>> L, R;
for(int i = 0; i < n; ++i){
if(x[i] == 2) L.pb({y[i], i});
else R.pb({y[i], i});
}
sort(all(L));
sort(all(R));
for(int i = 0; i + 1 < L.size(); ++i){
if(L[i].first < L[i + 1].first - 2) continue;
u.pb(L[i].second);
v.pb(L[i + 1].second);
a.pb(1);
b.pb(L[i + 1].first + L[i].first>>1);
d.merge(L[i].second, L[i + 1].second);
}
for(int i = 0; i + 1 < R.size(); ++i){
if(R[i].first < R[i + 1].first - 2) continue;
u.pb(R[i].second);
v.pb(R[i + 1].second);
a.pb(5);
b.pb(R[i + 1].first + R[i].first>>1);
d.merge(R[i].second, R[i + 1].second);
}
if(!R.empty() && !L.empty()){
int p = 0;
for(int i = 0; i < L.size(); ++i){
while(R[p].first < L[i].first) ++p;
if(L[i].first == R[p].first){
u.pb(L[i].second);
v.pb(R[p].second);
a.pb(3);
b.pb(L[i].first - 1);
d.merge(L[i].second, R[p].second);
}
}
}
if(d.s[d.find(0)] < n) 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:51:26: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
51 | for(int i = 0; i + 1 < L.size(); ++i){
| ~~~~~~^~~~~~~~~~
parks.cpp:56:29: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
56 | b.pb(L[i + 1].first + L[i].first>>1);
parks.cpp:59:26: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
59 | for(int i = 0; i + 1 < R.size(); ++i){
| ~~~~~~^~~~~~~~~~
parks.cpp:64:29: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
64 | b.pb(R[i + 1].first + R[i].first>>1);
parks.cpp:70:26: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
70 | for(int i = 0; i < L.size(); ++i){
| ~~^~~~~~~~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
2 |
Correct |
0 ms |
344 KB |
Output is correct |
3 |
Correct |
1 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
0 ms |
348 KB |
Output is correct |
6 |
Correct |
0 ms |
348 KB |
Output is correct |
7 |
Correct |
0 ms |
348 KB |
Output is correct |
8 |
Correct |
0 ms |
348 KB |
Output is correct |
9 |
Correct |
51 ms |
8388 KB |
Output is correct |
10 |
Correct |
5 ms |
1292 KB |
Output is correct |
11 |
Correct |
29 ms |
4820 KB |
Output is correct |
12 |
Correct |
6 ms |
1764 KB |
Output is correct |
13 |
Correct |
8 ms |
3028 KB |
Output is correct |
14 |
Correct |
0 ms |
348 KB |
Output is correct |
15 |
Correct |
1 ms |
348 KB |
Output is correct |
16 |
Correct |
47 ms |
8656 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
2 |
Correct |
0 ms |
344 KB |
Output is correct |
3 |
Correct |
1 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
0 ms |
348 KB |
Output is correct |
6 |
Correct |
0 ms |
348 KB |
Output is correct |
7 |
Correct |
0 ms |
348 KB |
Output is correct |
8 |
Correct |
0 ms |
348 KB |
Output is correct |
9 |
Correct |
51 ms |
8388 KB |
Output is correct |
10 |
Correct |
5 ms |
1292 KB |
Output is correct |
11 |
Correct |
29 ms |
4820 KB |
Output is correct |
12 |
Correct |
6 ms |
1764 KB |
Output is correct |
13 |
Correct |
8 ms |
3028 KB |
Output is correct |
14 |
Correct |
0 ms |
348 KB |
Output is correct |
15 |
Correct |
1 ms |
348 KB |
Output is correct |
16 |
Correct |
47 ms |
8656 KB |
Output is correct |
17 |
Correct |
0 ms |
348 KB |
Output is correct |
18 |
Correct |
0 ms |
348 KB |
Output is correct |
19 |
Correct |
0 ms |
348 KB |
Output is correct |
20 |
Correct |
1 ms |
348 KB |
Output is correct |
21 |
Correct |
0 ms |
348 KB |
Output is correct |
22 |
Correct |
0 ms |
424 KB |
Output is correct |
23 |
Correct |
127 ms |
20716 KB |
Output is correct |
24 |
Correct |
0 ms |
348 KB |
Output is correct |
25 |
Correct |
1 ms |
604 KB |
Output is correct |
26 |
Correct |
1 ms |
704 KB |
Output is correct |
27 |
Correct |
2 ms |
604 KB |
Output is correct |
28 |
Correct |
64 ms |
9368 KB |
Output is correct |
29 |
Correct |
74 ms |
13628 KB |
Output is correct |
30 |
Correct |
103 ms |
18268 KB |
Output is correct |
31 |
Correct |
127 ms |
22452 KB |
Output is correct |
32 |
Correct |
0 ms |
348 KB |
Output is correct |
33 |
Correct |
0 ms |
348 KB |
Output is correct |
34 |
Correct |
0 ms |
348 KB |
Output is correct |
35 |
Correct |
0 ms |
348 KB |
Output is correct |
36 |
Correct |
0 ms |
600 KB |
Output is correct |
37 |
Correct |
1 ms |
348 KB |
Output is correct |
38 |
Correct |
0 ms |
348 KB |
Output is correct |
39 |
Correct |
0 ms |
348 KB |
Output is correct |
40 |
Correct |
1 ms |
348 KB |
Output is correct |
41 |
Correct |
1 ms |
348 KB |
Output is correct |
42 |
Correct |
0 ms |
348 KB |
Output is correct |
43 |
Correct |
1 ms |
348 KB |
Output is correct |
44 |
Correct |
1 ms |
604 KB |
Output is correct |
45 |
Correct |
50 ms |
9304 KB |
Output is correct |
46 |
Correct |
71 ms |
14040 KB |
Output is correct |
47 |
Correct |
71 ms |
13896 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
2 |
Correct |
0 ms |
344 KB |
Output is correct |
3 |
Correct |
1 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
0 ms |
348 KB |
Output is correct |
6 |
Correct |
0 ms |
348 KB |
Output is correct |
7 |
Correct |
0 ms |
348 KB |
Output is correct |
8 |
Correct |
0 ms |
348 KB |
Output is correct |
9 |
Correct |
51 ms |
8388 KB |
Output is correct |
10 |
Correct |
5 ms |
1292 KB |
Output is correct |
11 |
Correct |
29 ms |
4820 KB |
Output is correct |
12 |
Correct |
6 ms |
1764 KB |
Output is correct |
13 |
Correct |
8 ms |
3028 KB |
Output is correct |
14 |
Correct |
0 ms |
348 KB |
Output is correct |
15 |
Correct |
1 ms |
348 KB |
Output is correct |
16 |
Correct |
47 ms |
8656 KB |
Output is correct |
17 |
Correct |
0 ms |
348 KB |
Output is correct |
18 |
Correct |
0 ms |
348 KB |
Output is correct |
19 |
Correct |
0 ms |
348 KB |
Output is correct |
20 |
Correct |
1 ms |
348 KB |
Output is correct |
21 |
Correct |
0 ms |
348 KB |
Output is correct |
22 |
Correct |
0 ms |
424 KB |
Output is correct |
23 |
Correct |
127 ms |
20716 KB |
Output is correct |
24 |
Correct |
0 ms |
348 KB |
Output is correct |
25 |
Correct |
1 ms |
604 KB |
Output is correct |
26 |
Correct |
1 ms |
704 KB |
Output is correct |
27 |
Correct |
2 ms |
604 KB |
Output is correct |
28 |
Correct |
64 ms |
9368 KB |
Output is correct |
29 |
Correct |
74 ms |
13628 KB |
Output is correct |
30 |
Correct |
103 ms |
18268 KB |
Output is correct |
31 |
Correct |
127 ms |
22452 KB |
Output is correct |
32 |
Correct |
0 ms |
348 KB |
Output is correct |
33 |
Correct |
0 ms |
348 KB |
Output is correct |
34 |
Correct |
0 ms |
348 KB |
Output is correct |
35 |
Correct |
0 ms |
348 KB |
Output is correct |
36 |
Correct |
0 ms |
600 KB |
Output is correct |
37 |
Correct |
1 ms |
348 KB |
Output is correct |
38 |
Correct |
0 ms |
348 KB |
Output is correct |
39 |
Correct |
0 ms |
348 KB |
Output is correct |
40 |
Correct |
1 ms |
348 KB |
Output is correct |
41 |
Correct |
1 ms |
348 KB |
Output is correct |
42 |
Correct |
0 ms |
348 KB |
Output is correct |
43 |
Correct |
1 ms |
348 KB |
Output is correct |
44 |
Correct |
1 ms |
604 KB |
Output is correct |
45 |
Correct |
50 ms |
9304 KB |
Output is correct |
46 |
Correct |
71 ms |
14040 KB |
Output is correct |
47 |
Correct |
71 ms |
13896 KB |
Output is correct |
48 |
Incorrect |
0 ms |
344 KB |
b[0] = 2 is not an odd integer |
49 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
2 |
Correct |
0 ms |
344 KB |
Output is correct |
3 |
Correct |
1 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
0 ms |
348 KB |
Output is correct |
6 |
Correct |
0 ms |
348 KB |
Output is correct |
7 |
Correct |
0 ms |
348 KB |
Output is correct |
8 |
Correct |
0 ms |
348 KB |
Output is correct |
9 |
Correct |
51 ms |
8388 KB |
Output is correct |
10 |
Correct |
5 ms |
1292 KB |
Output is correct |
11 |
Correct |
29 ms |
4820 KB |
Output is correct |
12 |
Correct |
6 ms |
1764 KB |
Output is correct |
13 |
Correct |
8 ms |
3028 KB |
Output is correct |
14 |
Correct |
0 ms |
348 KB |
Output is correct |
15 |
Correct |
1 ms |
348 KB |
Output is correct |
16 |
Correct |
47 ms |
8656 KB |
Output is correct |
17 |
Incorrect |
1 ms |
348 KB |
b[0] = 2 is not an odd integer |
18 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
2 |
Correct |
0 ms |
344 KB |
Output is correct |
3 |
Correct |
1 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
0 ms |
348 KB |
Output is correct |
6 |
Correct |
0 ms |
348 KB |
Output is correct |
7 |
Correct |
0 ms |
348 KB |
Output is correct |
8 |
Correct |
0 ms |
348 KB |
Output is correct |
9 |
Correct |
51 ms |
8388 KB |
Output is correct |
10 |
Correct |
5 ms |
1292 KB |
Output is correct |
11 |
Correct |
29 ms |
4820 KB |
Output is correct |
12 |
Correct |
6 ms |
1764 KB |
Output is correct |
13 |
Correct |
8 ms |
3028 KB |
Output is correct |
14 |
Correct |
0 ms |
348 KB |
Output is correct |
15 |
Correct |
1 ms |
348 KB |
Output is correct |
16 |
Correct |
47 ms |
8656 KB |
Output is correct |
17 |
Incorrect |
112 ms |
21060 KB |
Pair u[50000]=2 @(82816, 2) and v[50000]=3 @(97624, 2) does not form a valid edge (distance != 2) |
18 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
2 |
Correct |
0 ms |
344 KB |
Output is correct |
3 |
Correct |
1 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
0 ms |
348 KB |
Output is correct |
6 |
Correct |
0 ms |
348 KB |
Output is correct |
7 |
Correct |
0 ms |
348 KB |
Output is correct |
8 |
Correct |
0 ms |
348 KB |
Output is correct |
9 |
Correct |
51 ms |
8388 KB |
Output is correct |
10 |
Correct |
5 ms |
1292 KB |
Output is correct |
11 |
Correct |
29 ms |
4820 KB |
Output is correct |
12 |
Correct |
6 ms |
1764 KB |
Output is correct |
13 |
Correct |
8 ms |
3028 KB |
Output is correct |
14 |
Correct |
0 ms |
348 KB |
Output is correct |
15 |
Correct |
1 ms |
348 KB |
Output is correct |
16 |
Correct |
47 ms |
8656 KB |
Output is correct |
17 |
Correct |
0 ms |
348 KB |
Output is correct |
18 |
Correct |
0 ms |
348 KB |
Output is correct |
19 |
Correct |
0 ms |
348 KB |
Output is correct |
20 |
Correct |
1 ms |
348 KB |
Output is correct |
21 |
Correct |
0 ms |
348 KB |
Output is correct |
22 |
Correct |
0 ms |
424 KB |
Output is correct |
23 |
Correct |
127 ms |
20716 KB |
Output is correct |
24 |
Correct |
0 ms |
348 KB |
Output is correct |
25 |
Correct |
1 ms |
604 KB |
Output is correct |
26 |
Correct |
1 ms |
704 KB |
Output is correct |
27 |
Correct |
2 ms |
604 KB |
Output is correct |
28 |
Correct |
64 ms |
9368 KB |
Output is correct |
29 |
Correct |
74 ms |
13628 KB |
Output is correct |
30 |
Correct |
103 ms |
18268 KB |
Output is correct |
31 |
Correct |
127 ms |
22452 KB |
Output is correct |
32 |
Correct |
0 ms |
348 KB |
Output is correct |
33 |
Correct |
0 ms |
348 KB |
Output is correct |
34 |
Correct |
0 ms |
348 KB |
Output is correct |
35 |
Correct |
0 ms |
348 KB |
Output is correct |
36 |
Correct |
0 ms |
600 KB |
Output is correct |
37 |
Correct |
1 ms |
348 KB |
Output is correct |
38 |
Correct |
0 ms |
348 KB |
Output is correct |
39 |
Correct |
0 ms |
348 KB |
Output is correct |
40 |
Correct |
1 ms |
348 KB |
Output is correct |
41 |
Correct |
1 ms |
348 KB |
Output is correct |
42 |
Correct |
0 ms |
348 KB |
Output is correct |
43 |
Correct |
1 ms |
348 KB |
Output is correct |
44 |
Correct |
1 ms |
604 KB |
Output is correct |
45 |
Correct |
50 ms |
9304 KB |
Output is correct |
46 |
Correct |
71 ms |
14040 KB |
Output is correct |
47 |
Correct |
71 ms |
13896 KB |
Output is correct |
48 |
Incorrect |
0 ms |
344 KB |
b[0] = 2 is not an odd integer |
49 |
Halted |
0 ms |
0 KB |
- |