#include "parks.h"
#include <bits/stdc++.h>
#define rep(i, n) for(int i = 0; i < (int)(n); i ++)
#define rep1(i, n) for(int i = 1; i <= (int)(n); i ++)
#define MP make_pair
using namespace std;
typedef long long LL;
typedef pair<int, int> PII;
int n, x[200005], y[200005];
PII ord[200005];
int rt[200005];
int root(int x)
{
return rt[x] == x ? x : rt[x] = root(rt[x]);
}
map<PII, int> idx;
vector<int> u, v, a, b;
void add(int i, int j)
{
u.push_back(i);
v.push_back(j);
assert(root(i) != root(j));
rt[root(i)] = root(j);
if(x[i] == x[j]) {
if((x[i] + y[i]) % 2 == 1) a.push_back(x[i] - 1);
else a.push_back(x[i] + 1);
b.push_back((y[i] + y[j]) / 2);
} else {
a.push_back((x[i] + x[j]) / 2);
if((x[i] + y[i]) % 2 == 1) b.push_back(y[i] + 1);
else b.push_back(y[i] - 1);
}
}
int construct_roads(vector<int> X, vector<int> Y)
{
n = (int) X.size();
rep(i, n) {
x[i] = X[i];
y[i] = Y[i];
rt[i] = i;
idx[{x[i], y[i]}] = i;
}
rep(i, n) ord[i] = MP(x[i] + y[i], i);
sort(ord, ord + n);
reverse(ord, ord + n);
rep(id, n) {
int i = ord[id].second;
int id0 = (idx.count(MP(x[i] + 2, y[i])) ? idx[MP(x[i] + 2, y[i])] : -1);
int id1 = (idx.count(MP(x[i], y[i] + 2)) ? idx[MP(x[i], y[i] + 2)] : -1);
if(id0 == -1 && id1 == -1) continue;
if(id0 != -1 && id1 == -1) add(i, id0);
if(id0 == -1 && id1 != -1) add(i, id1);
if(id0 != -1 && id1 != -1) {
if(root(id0) != root(id1)) {
add(i, id0); add(i, id1);
} else {
if(ord[id].first % 2 == 1) add(i, id1);
else add(i, id0);
}
}
}
if((int) u.size() != n - 1) return 0;
build(u, v, a, b);
return 1;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
0 ms |
212 KB |
Output is correct |
3 |
Correct |
0 ms |
212 KB |
Output is correct |
4 |
Correct |
0 ms |
212 KB |
Output is correct |
5 |
Correct |
0 ms |
212 KB |
Output is correct |
6 |
Correct |
0 ms |
212 KB |
Output is correct |
7 |
Correct |
0 ms |
212 KB |
Output is correct |
8 |
Correct |
0 ms |
212 KB |
Output is correct |
9 |
Correct |
109 ms |
14912 KB |
Output is correct |
10 |
Correct |
9 ms |
2004 KB |
Output is correct |
11 |
Correct |
55 ms |
8148 KB |
Output is correct |
12 |
Correct |
13 ms |
2788 KB |
Output is correct |
13 |
Correct |
29 ms |
5460 KB |
Output is correct |
14 |
Correct |
1 ms |
340 KB |
Output is correct |
15 |
Correct |
2 ms |
468 KB |
Output is correct |
16 |
Correct |
109 ms |
14888 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
0 ms |
212 KB |
Output is correct |
3 |
Correct |
0 ms |
212 KB |
Output is correct |
4 |
Correct |
0 ms |
212 KB |
Output is correct |
5 |
Correct |
0 ms |
212 KB |
Output is correct |
6 |
Correct |
0 ms |
212 KB |
Output is correct |
7 |
Correct |
0 ms |
212 KB |
Output is correct |
8 |
Correct |
0 ms |
212 KB |
Output is correct |
9 |
Correct |
109 ms |
14912 KB |
Output is correct |
10 |
Correct |
9 ms |
2004 KB |
Output is correct |
11 |
Correct |
55 ms |
8148 KB |
Output is correct |
12 |
Correct |
13 ms |
2788 KB |
Output is correct |
13 |
Correct |
29 ms |
5460 KB |
Output is correct |
14 |
Correct |
1 ms |
340 KB |
Output is correct |
15 |
Correct |
2 ms |
468 KB |
Output is correct |
16 |
Correct |
109 ms |
14888 KB |
Output is correct |
17 |
Correct |
0 ms |
212 KB |
Output is correct |
18 |
Correct |
0 ms |
212 KB |
Output is correct |
19 |
Correct |
1 ms |
212 KB |
Output is correct |
20 |
Correct |
0 ms |
212 KB |
Output is correct |
21 |
Correct |
0 ms |
212 KB |
Output is correct |
22 |
Correct |
1 ms |
212 KB |
Output is correct |
23 |
Correct |
272 ms |
29336 KB |
Output is correct |
24 |
Correct |
0 ms |
212 KB |
Output is correct |
25 |
Correct |
1 ms |
468 KB |
Output is correct |
26 |
Correct |
2 ms |
596 KB |
Output is correct |
27 |
Correct |
3 ms |
724 KB |
Output is correct |
28 |
Correct |
92 ms |
12064 KB |
Output is correct |
29 |
Incorrect |
146 ms |
17808 KB |
Tree @(3, 80003) appears more than once: for edges on positions 119996 and 119997 |
30 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
0 ms |
212 KB |
Output is correct |
3 |
Correct |
0 ms |
212 KB |
Output is correct |
4 |
Correct |
0 ms |
212 KB |
Output is correct |
5 |
Correct |
0 ms |
212 KB |
Output is correct |
6 |
Correct |
0 ms |
212 KB |
Output is correct |
7 |
Correct |
0 ms |
212 KB |
Output is correct |
8 |
Correct |
0 ms |
212 KB |
Output is correct |
9 |
Correct |
109 ms |
14912 KB |
Output is correct |
10 |
Correct |
9 ms |
2004 KB |
Output is correct |
11 |
Correct |
55 ms |
8148 KB |
Output is correct |
12 |
Correct |
13 ms |
2788 KB |
Output is correct |
13 |
Correct |
29 ms |
5460 KB |
Output is correct |
14 |
Correct |
1 ms |
340 KB |
Output is correct |
15 |
Correct |
2 ms |
468 KB |
Output is correct |
16 |
Correct |
109 ms |
14888 KB |
Output is correct |
17 |
Correct |
0 ms |
212 KB |
Output is correct |
18 |
Correct |
0 ms |
212 KB |
Output is correct |
19 |
Correct |
1 ms |
212 KB |
Output is correct |
20 |
Correct |
0 ms |
212 KB |
Output is correct |
21 |
Correct |
0 ms |
212 KB |
Output is correct |
22 |
Correct |
1 ms |
212 KB |
Output is correct |
23 |
Correct |
272 ms |
29336 KB |
Output is correct |
24 |
Correct |
0 ms |
212 KB |
Output is correct |
25 |
Correct |
1 ms |
468 KB |
Output is correct |
26 |
Correct |
2 ms |
596 KB |
Output is correct |
27 |
Correct |
3 ms |
724 KB |
Output is correct |
28 |
Correct |
92 ms |
12064 KB |
Output is correct |
29 |
Incorrect |
146 ms |
17808 KB |
Tree @(3, 80003) appears more than once: for edges on positions 119996 and 119997 |
30 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
0 ms |
212 KB |
Output is correct |
3 |
Correct |
0 ms |
212 KB |
Output is correct |
4 |
Correct |
0 ms |
212 KB |
Output is correct |
5 |
Correct |
0 ms |
212 KB |
Output is correct |
6 |
Correct |
0 ms |
212 KB |
Output is correct |
7 |
Correct |
0 ms |
212 KB |
Output is correct |
8 |
Correct |
0 ms |
212 KB |
Output is correct |
9 |
Correct |
109 ms |
14912 KB |
Output is correct |
10 |
Correct |
9 ms |
2004 KB |
Output is correct |
11 |
Correct |
55 ms |
8148 KB |
Output is correct |
12 |
Correct |
13 ms |
2788 KB |
Output is correct |
13 |
Correct |
29 ms |
5460 KB |
Output is correct |
14 |
Correct |
1 ms |
340 KB |
Output is correct |
15 |
Correct |
2 ms |
468 KB |
Output is correct |
16 |
Correct |
109 ms |
14888 KB |
Output is correct |
17 |
Correct |
0 ms |
212 KB |
Output is correct |
18 |
Correct |
0 ms |
212 KB |
Output is correct |
19 |
Correct |
0 ms |
212 KB |
Output is correct |
20 |
Correct |
393 ms |
29888 KB |
Output is correct |
21 |
Incorrect |
285 ms |
29576 KB |
Tree @(99999, 100003) appears more than once: for edges on positions 1 and 2 |
22 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
0 ms |
212 KB |
Output is correct |
3 |
Correct |
0 ms |
212 KB |
Output is correct |
4 |
Correct |
0 ms |
212 KB |
Output is correct |
5 |
Correct |
0 ms |
212 KB |
Output is correct |
6 |
Correct |
0 ms |
212 KB |
Output is correct |
7 |
Correct |
0 ms |
212 KB |
Output is correct |
8 |
Correct |
0 ms |
212 KB |
Output is correct |
9 |
Correct |
109 ms |
14912 KB |
Output is correct |
10 |
Correct |
9 ms |
2004 KB |
Output is correct |
11 |
Correct |
55 ms |
8148 KB |
Output is correct |
12 |
Correct |
13 ms |
2788 KB |
Output is correct |
13 |
Correct |
29 ms |
5460 KB |
Output is correct |
14 |
Correct |
1 ms |
340 KB |
Output is correct |
15 |
Correct |
2 ms |
468 KB |
Output is correct |
16 |
Correct |
109 ms |
14888 KB |
Output is correct |
17 |
Incorrect |
296 ms |
29388 KB |
Tree @(3, 100001) appears more than once: for edges on positions 99999 and 100000 |
18 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
0 ms |
212 KB |
Output is correct |
3 |
Correct |
0 ms |
212 KB |
Output is correct |
4 |
Correct |
0 ms |
212 KB |
Output is correct |
5 |
Correct |
0 ms |
212 KB |
Output is correct |
6 |
Correct |
0 ms |
212 KB |
Output is correct |
7 |
Correct |
0 ms |
212 KB |
Output is correct |
8 |
Correct |
0 ms |
212 KB |
Output is correct |
9 |
Correct |
109 ms |
14912 KB |
Output is correct |
10 |
Correct |
9 ms |
2004 KB |
Output is correct |
11 |
Correct |
55 ms |
8148 KB |
Output is correct |
12 |
Correct |
13 ms |
2788 KB |
Output is correct |
13 |
Correct |
29 ms |
5460 KB |
Output is correct |
14 |
Correct |
1 ms |
340 KB |
Output is correct |
15 |
Correct |
2 ms |
468 KB |
Output is correct |
16 |
Correct |
109 ms |
14888 KB |
Output is correct |
17 |
Correct |
0 ms |
212 KB |
Output is correct |
18 |
Correct |
0 ms |
212 KB |
Output is correct |
19 |
Correct |
1 ms |
212 KB |
Output is correct |
20 |
Correct |
0 ms |
212 KB |
Output is correct |
21 |
Correct |
0 ms |
212 KB |
Output is correct |
22 |
Correct |
1 ms |
212 KB |
Output is correct |
23 |
Correct |
272 ms |
29336 KB |
Output is correct |
24 |
Correct |
0 ms |
212 KB |
Output is correct |
25 |
Correct |
1 ms |
468 KB |
Output is correct |
26 |
Correct |
2 ms |
596 KB |
Output is correct |
27 |
Correct |
3 ms |
724 KB |
Output is correct |
28 |
Correct |
92 ms |
12064 KB |
Output is correct |
29 |
Incorrect |
146 ms |
17808 KB |
Tree @(3, 80003) appears more than once: for edges on positions 119996 and 119997 |
30 |
Halted |
0 ms |
0 KB |
- |