#include "parks.h"
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
#define ll long long
#define add push_back
#define len(a) ((int)(a).size())
#define all(a) a.begin(), a.end()
#define pii pair<pair<int, int>, int>
#define fr first.first
#define sc first.second
#define index second
const int N = 2e5 + 5;
int parent[N], sz[N];
bool point[N][2];
void make_set(int v) {
parent[v] = v;
sz[v] = 1;
}
int find_set(int v) {
if (v == parent[v])
return v;
return parent[v] = find_set(parent[v]);
}
void union_sets(int a, int b) {
a = find_set(a);
b = find_set(b);
if (a != b) {
if (sz[a] < sz[b])
swap(a, b);
parent[b] = a;
sz[a] += sz[b];
}
}
int construct_roads(vector<int> x, vector<int> y) {
if (len(x) == 1) {
build({}, {}, {}, {});
return 1;
}
vector<pii> vec;
for(int i = 0; i < len(x); i++){
vec.add({{x[i], y[i]}, i});
make_set(i);
}
sort(all(vec));
vector<int> u, v, a, b;
int qanak = 1;
for(int i = 1; i < len(vec); i++){
if(vec[i].fr != vec[i - 1].fr) qanak++;
else if(vec[i].sc - vec[i - 1].sc == 2) {
u.add(vec[i - 1].index);
v.add(vec[i].index);
union_sets(vec[i - 1].index, vec[i].index);
}
}
for(int i = 0; i < len(vec); i++) swap(vec[i].fr, vec[i].sc);
sort(all(vec));
// for(int i = 0; i < len(vec); i++){
// cout << vec[i].fr << " " << vec[i].sc << endl;
// }
// cout << "---------" << endl;
for(int i = 1; i < len(vec); i++){
if(vec[i].fr == vec[i - 1].fr && vec[i].sc - vec[i - 1].sc == 2){
if(find_set(vec[i].index) != find_set(vec[i - 1].index)){
u.add(vec[i - 1].index);
v.add(vec[i].index);
union_sets(vec[i - 1].index, vec[i].index);
}
}
}
// for(int i = 0; i < len(u); i++){
// cout << u[i] << " " << v[i] << endl;
// }
for(int i = 1; i < len(x); i++){
if(find_set(i) != find_set(i - 1)){
return 0;
}
}
a.resize(len(u));
b.resize(len(u));
for(int i = 0; i < len(u); i++){
if(x[u[i]] != x[v[i]]){
if(x[u[i]] == 2 || x[v[i]] == 2){
a[i] = 3;
b[i] = y[u[i]] + 1;
point[y[u[i]] + 1][0] = true;
}
continue;
}
if(x[u[i]] == 2){
a[i] = x[u[i]] - 1;
b[i] = min(y[u[i]], y[v[i]]) + 1;
}
if(x[u[i]] == 6){
a[i] = x[u[i]] + 1;
b[i] = min(y[u[i]], y[v[i]]) + 1;
}
}
for(int i = 0; i < len(u); i++){
if(x[u[i]] == x[v[i]] && x[u[i]] == 4){
b[i] = min(y[u[i]], y[v[i]]) + 1;
if(!point[b[i]][0]){
a[i] = x[u[i]] - 1;
}
else {
a[i] = x[u[i]] + 1;
point[b[i]][1] = true;
}
}
}
for(int i = 0; i < len(u); i++){
if(x[u[i]] != x[v[i]] && (x[u[i]] == 6 || x[v[i]] == 6)){
a[i] = 5;
b[i] = y[u[i]] + 1;
if(point[b[i]][1]) b[i] -= 2;
}
}
build(u, v, a, b);
return 1;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
340 KB |
Output is correct |
2 |
Correct |
1 ms |
212 KB |
Output is correct |
3 |
Correct |
1 ms |
212 KB |
Output is correct |
4 |
Correct |
1 ms |
212 KB |
Output is correct |
5 |
Correct |
1 ms |
212 KB |
Output is correct |
6 |
Correct |
1 ms |
312 KB |
Output is correct |
7 |
Correct |
0 ms |
212 KB |
Output is correct |
8 |
Correct |
0 ms |
212 KB |
Output is correct |
9 |
Correct |
63 ms |
9892 KB |
Output is correct |
10 |
Correct |
6 ms |
1184 KB |
Output is correct |
11 |
Correct |
27 ms |
5288 KB |
Output is correct |
12 |
Correct |
8 ms |
1712 KB |
Output is correct |
13 |
Correct |
15 ms |
2896 KB |
Output is correct |
14 |
Correct |
1 ms |
340 KB |
Output is correct |
15 |
Correct |
1 ms |
340 KB |
Output is correct |
16 |
Correct |
64 ms |
9800 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
340 KB |
Output is correct |
2 |
Correct |
1 ms |
212 KB |
Output is correct |
3 |
Correct |
1 ms |
212 KB |
Output is correct |
4 |
Correct |
1 ms |
212 KB |
Output is correct |
5 |
Correct |
1 ms |
212 KB |
Output is correct |
6 |
Correct |
1 ms |
312 KB |
Output is correct |
7 |
Correct |
0 ms |
212 KB |
Output is correct |
8 |
Correct |
0 ms |
212 KB |
Output is correct |
9 |
Correct |
63 ms |
9892 KB |
Output is correct |
10 |
Correct |
6 ms |
1184 KB |
Output is correct |
11 |
Correct |
27 ms |
5288 KB |
Output is correct |
12 |
Correct |
8 ms |
1712 KB |
Output is correct |
13 |
Correct |
15 ms |
2896 KB |
Output is correct |
14 |
Correct |
1 ms |
340 KB |
Output is correct |
15 |
Correct |
1 ms |
340 KB |
Output is correct |
16 |
Correct |
64 ms |
9800 KB |
Output is correct |
17 |
Correct |
1 ms |
212 KB |
Output is correct |
18 |
Correct |
0 ms |
212 KB |
Output is correct |
19 |
Correct |
1 ms |
308 KB |
Output is correct |
20 |
Correct |
0 ms |
212 KB |
Output is correct |
21 |
Correct |
0 ms |
308 KB |
Output is correct |
22 |
Correct |
1 ms |
312 KB |
Output is correct |
23 |
Correct |
151 ms |
19232 KB |
Output is correct |
24 |
Correct |
1 ms |
212 KB |
Output is correct |
25 |
Correct |
2 ms |
340 KB |
Output is correct |
26 |
Correct |
2 ms |
468 KB |
Output is correct |
27 |
Correct |
3 ms |
468 KB |
Output is correct |
28 |
Correct |
55 ms |
7728 KB |
Output is correct |
29 |
Correct |
84 ms |
11780 KB |
Output is correct |
30 |
Correct |
122 ms |
15172 KB |
Output is correct |
31 |
Correct |
152 ms |
19320 KB |
Output is correct |
32 |
Correct |
0 ms |
212 KB |
Output is correct |
33 |
Correct |
0 ms |
212 KB |
Output is correct |
34 |
Correct |
1 ms |
212 KB |
Output is correct |
35 |
Correct |
1 ms |
212 KB |
Output is correct |
36 |
Correct |
0 ms |
212 KB |
Output is correct |
37 |
Correct |
1 ms |
212 KB |
Output is correct |
38 |
Correct |
1 ms |
312 KB |
Output is correct |
39 |
Correct |
0 ms |
212 KB |
Output is correct |
40 |
Correct |
1 ms |
316 KB |
Output is correct |
41 |
Correct |
0 ms |
212 KB |
Output is correct |
42 |
Correct |
1 ms |
212 KB |
Output is correct |
43 |
Correct |
1 ms |
340 KB |
Output is correct |
44 |
Correct |
2 ms |
468 KB |
Output is correct |
45 |
Correct |
78 ms |
10220 KB |
Output is correct |
46 |
Correct |
112 ms |
14164 KB |
Output is correct |
47 |
Correct |
110 ms |
14148 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
340 KB |
Output is correct |
2 |
Correct |
1 ms |
212 KB |
Output is correct |
3 |
Correct |
1 ms |
212 KB |
Output is correct |
4 |
Correct |
1 ms |
212 KB |
Output is correct |
5 |
Correct |
1 ms |
212 KB |
Output is correct |
6 |
Correct |
1 ms |
312 KB |
Output is correct |
7 |
Correct |
0 ms |
212 KB |
Output is correct |
8 |
Correct |
0 ms |
212 KB |
Output is correct |
9 |
Correct |
63 ms |
9892 KB |
Output is correct |
10 |
Correct |
6 ms |
1184 KB |
Output is correct |
11 |
Correct |
27 ms |
5288 KB |
Output is correct |
12 |
Correct |
8 ms |
1712 KB |
Output is correct |
13 |
Correct |
15 ms |
2896 KB |
Output is correct |
14 |
Correct |
1 ms |
340 KB |
Output is correct |
15 |
Correct |
1 ms |
340 KB |
Output is correct |
16 |
Correct |
64 ms |
9800 KB |
Output is correct |
17 |
Correct |
1 ms |
212 KB |
Output is correct |
18 |
Correct |
0 ms |
212 KB |
Output is correct |
19 |
Correct |
1 ms |
308 KB |
Output is correct |
20 |
Correct |
0 ms |
212 KB |
Output is correct |
21 |
Correct |
0 ms |
308 KB |
Output is correct |
22 |
Correct |
1 ms |
312 KB |
Output is correct |
23 |
Correct |
151 ms |
19232 KB |
Output is correct |
24 |
Correct |
1 ms |
212 KB |
Output is correct |
25 |
Correct |
2 ms |
340 KB |
Output is correct |
26 |
Correct |
2 ms |
468 KB |
Output is correct |
27 |
Correct |
3 ms |
468 KB |
Output is correct |
28 |
Correct |
55 ms |
7728 KB |
Output is correct |
29 |
Correct |
84 ms |
11780 KB |
Output is correct |
30 |
Correct |
122 ms |
15172 KB |
Output is correct |
31 |
Correct |
152 ms |
19320 KB |
Output is correct |
32 |
Correct |
0 ms |
212 KB |
Output is correct |
33 |
Correct |
0 ms |
212 KB |
Output is correct |
34 |
Correct |
1 ms |
212 KB |
Output is correct |
35 |
Correct |
1 ms |
212 KB |
Output is correct |
36 |
Correct |
0 ms |
212 KB |
Output is correct |
37 |
Correct |
1 ms |
212 KB |
Output is correct |
38 |
Correct |
1 ms |
312 KB |
Output is correct |
39 |
Correct |
0 ms |
212 KB |
Output is correct |
40 |
Correct |
1 ms |
316 KB |
Output is correct |
41 |
Correct |
0 ms |
212 KB |
Output is correct |
42 |
Correct |
1 ms |
212 KB |
Output is correct |
43 |
Correct |
1 ms |
340 KB |
Output is correct |
44 |
Correct |
2 ms |
468 KB |
Output is correct |
45 |
Correct |
78 ms |
10220 KB |
Output is correct |
46 |
Correct |
112 ms |
14164 KB |
Output is correct |
47 |
Correct |
110 ms |
14148 KB |
Output is correct |
48 |
Correct |
0 ms |
212 KB |
Output is correct |
49 |
Correct |
1 ms |
212 KB |
Output is correct |
50 |
Correct |
0 ms |
212 KB |
Output is correct |
51 |
Correct |
0 ms |
212 KB |
Output is correct |
52 |
Correct |
1 ms |
212 KB |
Output is correct |
53 |
Correct |
0 ms |
212 KB |
Output is correct |
54 |
Correct |
1 ms |
312 KB |
Output is correct |
55 |
Correct |
133 ms |
19168 KB |
Output is correct |
56 |
Correct |
0 ms |
212 KB |
Output is correct |
57 |
Correct |
1 ms |
468 KB |
Output is correct |
58 |
Correct |
4 ms |
980 KB |
Output is correct |
59 |
Correct |
4 ms |
920 KB |
Output is correct |
60 |
Correct |
78 ms |
9772 KB |
Output is correct |
61 |
Correct |
91 ms |
12820 KB |
Output is correct |
62 |
Correct |
109 ms |
15748 KB |
Output is correct |
63 |
Correct |
136 ms |
19316 KB |
Output is correct |
64 |
Correct |
1 ms |
212 KB |
Output is correct |
65 |
Correct |
1 ms |
212 KB |
Output is correct |
66 |
Correct |
1 ms |
308 KB |
Output is correct |
67 |
Correct |
150 ms |
19304 KB |
Output is correct |
68 |
Correct |
145 ms |
19292 KB |
Output is correct |
69 |
Correct |
146 ms |
19176 KB |
Output is correct |
70 |
Correct |
2 ms |
468 KB |
Output is correct |
71 |
Correct |
4 ms |
724 KB |
Output is correct |
72 |
Correct |
68 ms |
9932 KB |
Output is correct |
73 |
Correct |
106 ms |
14640 KB |
Output is correct |
74 |
Correct |
170 ms |
19808 KB |
Output is correct |
75 |
Correct |
136 ms |
19540 KB |
Output is correct |
76 |
Correct |
153 ms |
19292 KB |
Output is correct |
77 |
Correct |
2 ms |
596 KB |
Output is correct |
78 |
Correct |
3 ms |
852 KB |
Output is correct |
79 |
Correct |
66 ms |
9956 KB |
Output is correct |
80 |
Correct |
119 ms |
14552 KB |
Output is correct |
81 |
Correct |
140 ms |
19704 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
340 KB |
Output is correct |
2 |
Correct |
1 ms |
212 KB |
Output is correct |
3 |
Correct |
1 ms |
212 KB |
Output is correct |
4 |
Correct |
1 ms |
212 KB |
Output is correct |
5 |
Correct |
1 ms |
212 KB |
Output is correct |
6 |
Correct |
1 ms |
312 KB |
Output is correct |
7 |
Correct |
0 ms |
212 KB |
Output is correct |
8 |
Correct |
0 ms |
212 KB |
Output is correct |
9 |
Correct |
63 ms |
9892 KB |
Output is correct |
10 |
Correct |
6 ms |
1184 KB |
Output is correct |
11 |
Correct |
27 ms |
5288 KB |
Output is correct |
12 |
Correct |
8 ms |
1712 KB |
Output is correct |
13 |
Correct |
15 ms |
2896 KB |
Output is correct |
14 |
Correct |
1 ms |
340 KB |
Output is correct |
15 |
Correct |
1 ms |
340 KB |
Output is correct |
16 |
Correct |
64 ms |
9800 KB |
Output is correct |
17 |
Incorrect |
1 ms |
212 KB |
a[0] = 0 is not an odd integer |
18 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
340 KB |
Output is correct |
2 |
Correct |
1 ms |
212 KB |
Output is correct |
3 |
Correct |
1 ms |
212 KB |
Output is correct |
4 |
Correct |
1 ms |
212 KB |
Output is correct |
5 |
Correct |
1 ms |
212 KB |
Output is correct |
6 |
Correct |
1 ms |
312 KB |
Output is correct |
7 |
Correct |
0 ms |
212 KB |
Output is correct |
8 |
Correct |
0 ms |
212 KB |
Output is correct |
9 |
Correct |
63 ms |
9892 KB |
Output is correct |
10 |
Correct |
6 ms |
1184 KB |
Output is correct |
11 |
Correct |
27 ms |
5288 KB |
Output is correct |
12 |
Correct |
8 ms |
1712 KB |
Output is correct |
13 |
Correct |
15 ms |
2896 KB |
Output is correct |
14 |
Correct |
1 ms |
340 KB |
Output is correct |
15 |
Correct |
1 ms |
340 KB |
Output is correct |
16 |
Correct |
64 ms |
9800 KB |
Output is correct |
17 |
Incorrect |
147 ms |
19344 KB |
a[50000] = 0 is not an odd integer |
18 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
340 KB |
Output is correct |
2 |
Correct |
1 ms |
212 KB |
Output is correct |
3 |
Correct |
1 ms |
212 KB |
Output is correct |
4 |
Correct |
1 ms |
212 KB |
Output is correct |
5 |
Correct |
1 ms |
212 KB |
Output is correct |
6 |
Correct |
1 ms |
312 KB |
Output is correct |
7 |
Correct |
0 ms |
212 KB |
Output is correct |
8 |
Correct |
0 ms |
212 KB |
Output is correct |
9 |
Correct |
63 ms |
9892 KB |
Output is correct |
10 |
Correct |
6 ms |
1184 KB |
Output is correct |
11 |
Correct |
27 ms |
5288 KB |
Output is correct |
12 |
Correct |
8 ms |
1712 KB |
Output is correct |
13 |
Correct |
15 ms |
2896 KB |
Output is correct |
14 |
Correct |
1 ms |
340 KB |
Output is correct |
15 |
Correct |
1 ms |
340 KB |
Output is correct |
16 |
Correct |
64 ms |
9800 KB |
Output is correct |
17 |
Correct |
1 ms |
212 KB |
Output is correct |
18 |
Correct |
0 ms |
212 KB |
Output is correct |
19 |
Correct |
1 ms |
308 KB |
Output is correct |
20 |
Correct |
0 ms |
212 KB |
Output is correct |
21 |
Correct |
0 ms |
308 KB |
Output is correct |
22 |
Correct |
1 ms |
312 KB |
Output is correct |
23 |
Correct |
151 ms |
19232 KB |
Output is correct |
24 |
Correct |
1 ms |
212 KB |
Output is correct |
25 |
Correct |
2 ms |
340 KB |
Output is correct |
26 |
Correct |
2 ms |
468 KB |
Output is correct |
27 |
Correct |
3 ms |
468 KB |
Output is correct |
28 |
Correct |
55 ms |
7728 KB |
Output is correct |
29 |
Correct |
84 ms |
11780 KB |
Output is correct |
30 |
Correct |
122 ms |
15172 KB |
Output is correct |
31 |
Correct |
152 ms |
19320 KB |
Output is correct |
32 |
Correct |
0 ms |
212 KB |
Output is correct |
33 |
Correct |
0 ms |
212 KB |
Output is correct |
34 |
Correct |
1 ms |
212 KB |
Output is correct |
35 |
Correct |
1 ms |
212 KB |
Output is correct |
36 |
Correct |
0 ms |
212 KB |
Output is correct |
37 |
Correct |
1 ms |
212 KB |
Output is correct |
38 |
Correct |
1 ms |
312 KB |
Output is correct |
39 |
Correct |
0 ms |
212 KB |
Output is correct |
40 |
Correct |
1 ms |
316 KB |
Output is correct |
41 |
Correct |
0 ms |
212 KB |
Output is correct |
42 |
Correct |
1 ms |
212 KB |
Output is correct |
43 |
Correct |
1 ms |
340 KB |
Output is correct |
44 |
Correct |
2 ms |
468 KB |
Output is correct |
45 |
Correct |
78 ms |
10220 KB |
Output is correct |
46 |
Correct |
112 ms |
14164 KB |
Output is correct |
47 |
Correct |
110 ms |
14148 KB |
Output is correct |
48 |
Correct |
0 ms |
212 KB |
Output is correct |
49 |
Correct |
1 ms |
212 KB |
Output is correct |
50 |
Correct |
0 ms |
212 KB |
Output is correct |
51 |
Correct |
0 ms |
212 KB |
Output is correct |
52 |
Correct |
1 ms |
212 KB |
Output is correct |
53 |
Correct |
0 ms |
212 KB |
Output is correct |
54 |
Correct |
1 ms |
312 KB |
Output is correct |
55 |
Correct |
133 ms |
19168 KB |
Output is correct |
56 |
Correct |
0 ms |
212 KB |
Output is correct |
57 |
Correct |
1 ms |
468 KB |
Output is correct |
58 |
Correct |
4 ms |
980 KB |
Output is correct |
59 |
Correct |
4 ms |
920 KB |
Output is correct |
60 |
Correct |
78 ms |
9772 KB |
Output is correct |
61 |
Correct |
91 ms |
12820 KB |
Output is correct |
62 |
Correct |
109 ms |
15748 KB |
Output is correct |
63 |
Correct |
136 ms |
19316 KB |
Output is correct |
64 |
Correct |
1 ms |
212 KB |
Output is correct |
65 |
Correct |
1 ms |
212 KB |
Output is correct |
66 |
Correct |
1 ms |
308 KB |
Output is correct |
67 |
Correct |
150 ms |
19304 KB |
Output is correct |
68 |
Correct |
145 ms |
19292 KB |
Output is correct |
69 |
Correct |
146 ms |
19176 KB |
Output is correct |
70 |
Correct |
2 ms |
468 KB |
Output is correct |
71 |
Correct |
4 ms |
724 KB |
Output is correct |
72 |
Correct |
68 ms |
9932 KB |
Output is correct |
73 |
Correct |
106 ms |
14640 KB |
Output is correct |
74 |
Correct |
170 ms |
19808 KB |
Output is correct |
75 |
Correct |
136 ms |
19540 KB |
Output is correct |
76 |
Correct |
153 ms |
19292 KB |
Output is correct |
77 |
Correct |
2 ms |
596 KB |
Output is correct |
78 |
Correct |
3 ms |
852 KB |
Output is correct |
79 |
Correct |
66 ms |
9956 KB |
Output is correct |
80 |
Correct |
119 ms |
14552 KB |
Output is correct |
81 |
Correct |
140 ms |
19704 KB |
Output is correct |
82 |
Incorrect |
1 ms |
212 KB |
a[0] = 0 is not an odd integer |
83 |
Halted |
0 ms |
0 KB |
- |