/* Ignut
started: 16.08.2024
now: 16.08.2024
████████████████████████████████████████████████████████████████████
████████████████████████████████ ████████████████████████████████
██████████████████████████████ ██████████████████████████████
██████ ██████████████████ ██████████████████ ██████
██████ ██████████████ ██████████████ ██████
██████ ██ ████████████ ████████████ ██ ██████
██████ ████ ██████████ ██████████ ████ ██████
██████ ████ ██████████ ██████████ ████ ██████
██████ ████ ██████████ ██████████ ██████ ██████
██████ ██████ ██████████ ██████████ ██████ ██████
██████ ██████ ████████ ████████ ██████ ██████
██████ ██████ ██████ ██████ ██████ ██████
██████ ████ ████ ████ ████ ██████
██████ ██████████ ████ ██████████ ██████
██████ ██ ██████ ████████ ██████ ██ ██████
██████ ██████ ████████ ██████ ██████
██████ ██ ██ ██████
██████████████████████ ████ ████ ██████████████████████
████████████████████████ ██ ██ ████████████████████████
██████████████████████████ ██████████████████████████
██████████████████████████████ ██████████████████████████████
████████████████████████████████████████████████████████████████████
*/
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
void build(vector<int> u, vector<int> v, vector<int> a, vector<int> b);
struct DSU {
int cntComp;
vector<int> p, sz;
void Init(int n) {
cntComp = n;
p.assign(n, 0);
iota(p.begin(), p.end(), 0);
sz.assign(n, 1);
}
int Get(int v) {
return p[v] == v ? v : p[v] = Get(p[v]);
}
void Unite(int u, int v) {
u = Get(u), v = Get(v);
if (u == v) return;
cntComp --;
if (sz[u] > sz[v]) swap(u, v);
p[u] = v;
sz[v] += sz[u];
}
};
int construct_roads(vector<int> x, vector<int> y) {
int n = x.size();
map<pair<int, int>, int> mp;
for (int i = 0; i < n; i ++) mp[{x[i], y[i]}] = i + 1;
DSU dsu; dsu.Init(n);
vector<int> u, v, a, b;
auto MakeEdge = [&u, &v, &a, &b, &dsu, &x, &y](int i, int j) -> void {
u.push_back(i);
v.push_back(j);
dsu.Unite(i, j);
int X;
if (x[i] == 2 && x[j] == 2) X = 1;
else if (x[i] == 4 && x[j] == 4) X = 5;
else X = 3;
int Y;
if (y[i] == y[j]) Y = y[i] - 1;
else Y = (y[i] + y[j]) / 2;
a.push_back(X);
b.push_back(Y);
};
for (int i = 0; i < n; i ++) {
if (mp.count({x[i] + 2, y[i]})) {
MakeEdge(i, mp[{x[i] + 2, y[i]}] - 1);
}
if (mp.count({x[i], y[i] + 2})) {
MakeEdge(i, mp[{x[i], y[i] + 2}] - 1);
}
}
if (dsu.cntComp > 1) return 0;
build(u, v, a, b);
return 1;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
1 ms |
388 KB |
Output is correct |
6 |
Correct |
0 ms |
348 KB |
Output is correct |
7 |
Correct |
0 ms |
348 KB |
Output is correct |
8 |
Correct |
1 ms |
348 KB |
Output is correct |
9 |
Correct |
102 ms |
13772 KB |
Output is correct |
10 |
Correct |
6 ms |
1884 KB |
Output is correct |
11 |
Correct |
37 ms |
7636 KB |
Output is correct |
12 |
Correct |
9 ms |
2648 KB |
Output is correct |
13 |
Correct |
24 ms |
5080 KB |
Output is correct |
14 |
Correct |
1 ms |
348 KB |
Output is correct |
15 |
Correct |
1 ms |
604 KB |
Output is correct |
16 |
Correct |
99 ms |
13872 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
1 ms |
388 KB |
Output is correct |
6 |
Correct |
0 ms |
348 KB |
Output is correct |
7 |
Correct |
0 ms |
348 KB |
Output is correct |
8 |
Correct |
1 ms |
348 KB |
Output is correct |
9 |
Correct |
102 ms |
13772 KB |
Output is correct |
10 |
Correct |
6 ms |
1884 KB |
Output is correct |
11 |
Correct |
37 ms |
7636 KB |
Output is correct |
12 |
Correct |
9 ms |
2648 KB |
Output is correct |
13 |
Correct |
24 ms |
5080 KB |
Output is correct |
14 |
Correct |
1 ms |
348 KB |
Output is correct |
15 |
Correct |
1 ms |
604 KB |
Output is correct |
16 |
Correct |
99 ms |
13872 KB |
Output is correct |
17 |
Correct |
0 ms |
348 KB |
Output is correct |
18 |
Correct |
0 ms |
344 KB |
Output is correct |
19 |
Correct |
0 ms |
348 KB |
Output is correct |
20 |
Correct |
0 ms |
348 KB |
Output is correct |
21 |
Correct |
0 ms |
348 KB |
Output is correct |
22 |
Correct |
0 ms |
348 KB |
Output is correct |
23 |
Correct |
299 ms |
31740 KB |
Output is correct |
24 |
Correct |
0 ms |
344 KB |
Output is correct |
25 |
Correct |
1 ms |
600 KB |
Output is correct |
26 |
Correct |
2 ms |
600 KB |
Output is correct |
27 |
Correct |
3 ms |
856 KB |
Output is correct |
28 |
Correct |
95 ms |
12924 KB |
Output is correct |
29 |
Correct |
164 ms |
19272 KB |
Output is correct |
30 |
Correct |
216 ms |
25460 KB |
Output is correct |
31 |
Correct |
288 ms |
31640 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 |
344 KB |
Output is correct |
35 |
Correct |
0 ms |
348 KB |
Output is correct |
36 |
Correct |
0 ms |
348 KB |
Output is correct |
37 |
Correct |
0 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 |
0 ms |
360 KB |
Output is correct |
41 |
Correct |
0 ms |
348 KB |
Output is correct |
42 |
Correct |
0 ms |
348 KB |
Output is correct |
43 |
Correct |
1 ms |
604 KB |
Output is correct |
44 |
Correct |
2 ms |
604 KB |
Output is correct |
45 |
Correct |
109 ms |
13876 KB |
Output is correct |
46 |
Correct |
169 ms |
19876 KB |
Output is correct |
47 |
Correct |
170 ms |
19880 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
1 ms |
388 KB |
Output is correct |
6 |
Correct |
0 ms |
348 KB |
Output is correct |
7 |
Correct |
0 ms |
348 KB |
Output is correct |
8 |
Correct |
1 ms |
348 KB |
Output is correct |
9 |
Correct |
102 ms |
13772 KB |
Output is correct |
10 |
Correct |
6 ms |
1884 KB |
Output is correct |
11 |
Correct |
37 ms |
7636 KB |
Output is correct |
12 |
Correct |
9 ms |
2648 KB |
Output is correct |
13 |
Correct |
24 ms |
5080 KB |
Output is correct |
14 |
Correct |
1 ms |
348 KB |
Output is correct |
15 |
Correct |
1 ms |
604 KB |
Output is correct |
16 |
Correct |
99 ms |
13872 KB |
Output is correct |
17 |
Correct |
0 ms |
348 KB |
Output is correct |
18 |
Correct |
0 ms |
344 KB |
Output is correct |
19 |
Correct |
0 ms |
348 KB |
Output is correct |
20 |
Correct |
0 ms |
348 KB |
Output is correct |
21 |
Correct |
0 ms |
348 KB |
Output is correct |
22 |
Correct |
0 ms |
348 KB |
Output is correct |
23 |
Correct |
299 ms |
31740 KB |
Output is correct |
24 |
Correct |
0 ms |
344 KB |
Output is correct |
25 |
Correct |
1 ms |
600 KB |
Output is correct |
26 |
Correct |
2 ms |
600 KB |
Output is correct |
27 |
Correct |
3 ms |
856 KB |
Output is correct |
28 |
Correct |
95 ms |
12924 KB |
Output is correct |
29 |
Correct |
164 ms |
19272 KB |
Output is correct |
30 |
Correct |
216 ms |
25460 KB |
Output is correct |
31 |
Correct |
288 ms |
31640 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 |
344 KB |
Output is correct |
35 |
Correct |
0 ms |
348 KB |
Output is correct |
36 |
Correct |
0 ms |
348 KB |
Output is correct |
37 |
Correct |
0 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 |
0 ms |
360 KB |
Output is correct |
41 |
Correct |
0 ms |
348 KB |
Output is correct |
42 |
Correct |
0 ms |
348 KB |
Output is correct |
43 |
Correct |
1 ms |
604 KB |
Output is correct |
44 |
Correct |
2 ms |
604 KB |
Output is correct |
45 |
Correct |
109 ms |
13876 KB |
Output is correct |
46 |
Correct |
169 ms |
19876 KB |
Output is correct |
47 |
Correct |
170 ms |
19880 KB |
Output is correct |
48 |
Incorrect |
1 ms |
348 KB |
Tree (a[0], b[0]) = (3, 3) is not adjacent to edge between u[0]=0 @(6, 2) and v[0]=2 @(6, 4) |
49 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
1 ms |
388 KB |
Output is correct |
6 |
Correct |
0 ms |
348 KB |
Output is correct |
7 |
Correct |
0 ms |
348 KB |
Output is correct |
8 |
Correct |
1 ms |
348 KB |
Output is correct |
9 |
Correct |
102 ms |
13772 KB |
Output is correct |
10 |
Correct |
6 ms |
1884 KB |
Output is correct |
11 |
Correct |
37 ms |
7636 KB |
Output is correct |
12 |
Correct |
9 ms |
2648 KB |
Output is correct |
13 |
Correct |
24 ms |
5080 KB |
Output is correct |
14 |
Correct |
1 ms |
348 KB |
Output is correct |
15 |
Correct |
1 ms |
604 KB |
Output is correct |
16 |
Correct |
99 ms |
13872 KB |
Output is correct |
17 |
Incorrect |
0 ms |
348 KB |
Tree (a[0], b[0]) = (3, 3) is not adjacent to edge between u[0]=0 @(200000, 2) and v[0]=1 @(200000, 4) |
18 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
1 ms |
388 KB |
Output is correct |
6 |
Correct |
0 ms |
348 KB |
Output is correct |
7 |
Correct |
0 ms |
348 KB |
Output is correct |
8 |
Correct |
1 ms |
348 KB |
Output is correct |
9 |
Correct |
102 ms |
13772 KB |
Output is correct |
10 |
Correct |
6 ms |
1884 KB |
Output is correct |
11 |
Correct |
37 ms |
7636 KB |
Output is correct |
12 |
Correct |
9 ms |
2648 KB |
Output is correct |
13 |
Correct |
24 ms |
5080 KB |
Output is correct |
14 |
Correct |
1 ms |
348 KB |
Output is correct |
15 |
Correct |
1 ms |
604 KB |
Output is correct |
16 |
Correct |
99 ms |
13872 KB |
Output is correct |
17 |
Incorrect |
252 ms |
27052 KB |
Tree (a[0], b[0]) = (3, 100001) is not adjacent to edge between u[0]=0 @(82422, 100002) and v[0]=168975 @(82424, 100002) |
18 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
1 ms |
388 KB |
Output is correct |
6 |
Correct |
0 ms |
348 KB |
Output is correct |
7 |
Correct |
0 ms |
348 KB |
Output is correct |
8 |
Correct |
1 ms |
348 KB |
Output is correct |
9 |
Correct |
102 ms |
13772 KB |
Output is correct |
10 |
Correct |
6 ms |
1884 KB |
Output is correct |
11 |
Correct |
37 ms |
7636 KB |
Output is correct |
12 |
Correct |
9 ms |
2648 KB |
Output is correct |
13 |
Correct |
24 ms |
5080 KB |
Output is correct |
14 |
Correct |
1 ms |
348 KB |
Output is correct |
15 |
Correct |
1 ms |
604 KB |
Output is correct |
16 |
Correct |
99 ms |
13872 KB |
Output is correct |
17 |
Correct |
0 ms |
348 KB |
Output is correct |
18 |
Correct |
0 ms |
344 KB |
Output is correct |
19 |
Correct |
0 ms |
348 KB |
Output is correct |
20 |
Correct |
0 ms |
348 KB |
Output is correct |
21 |
Correct |
0 ms |
348 KB |
Output is correct |
22 |
Correct |
0 ms |
348 KB |
Output is correct |
23 |
Correct |
299 ms |
31740 KB |
Output is correct |
24 |
Correct |
0 ms |
344 KB |
Output is correct |
25 |
Correct |
1 ms |
600 KB |
Output is correct |
26 |
Correct |
2 ms |
600 KB |
Output is correct |
27 |
Correct |
3 ms |
856 KB |
Output is correct |
28 |
Correct |
95 ms |
12924 KB |
Output is correct |
29 |
Correct |
164 ms |
19272 KB |
Output is correct |
30 |
Correct |
216 ms |
25460 KB |
Output is correct |
31 |
Correct |
288 ms |
31640 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 |
344 KB |
Output is correct |
35 |
Correct |
0 ms |
348 KB |
Output is correct |
36 |
Correct |
0 ms |
348 KB |
Output is correct |
37 |
Correct |
0 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 |
0 ms |
360 KB |
Output is correct |
41 |
Correct |
0 ms |
348 KB |
Output is correct |
42 |
Correct |
0 ms |
348 KB |
Output is correct |
43 |
Correct |
1 ms |
604 KB |
Output is correct |
44 |
Correct |
2 ms |
604 KB |
Output is correct |
45 |
Correct |
109 ms |
13876 KB |
Output is correct |
46 |
Correct |
169 ms |
19876 KB |
Output is correct |
47 |
Correct |
170 ms |
19880 KB |
Output is correct |
48 |
Incorrect |
1 ms |
348 KB |
Tree (a[0], b[0]) = (3, 3) is not adjacent to edge between u[0]=0 @(6, 2) and v[0]=2 @(6, 4) |
49 |
Halted |
0 ms |
0 KB |
- |