#include "parks.h"
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define pb push_back
#define pii pair<int, int>
#define ff first
#define ss second
const int mxN = 2e5 + 1;
const int dx[mxN] = {0, 1, 0, -1}, dy[mxN] = {1, 0, -1, 0};
bool vis[mxN];
pair<pii, int> pts[mxN];
pii opts[mxN];
map<pii, int> allpts;
int n;
bool CheckConnected() {
queue<pii> q;
set<pii> track;
q.push(pts[0].ff);
track.insert(pts[0].ff);
while (!q.empty()) {
pii cur = q.front();
q.pop();
for (int k = 0; k < 4; k++) {
int nx = cur.ff + dx[k] * 2;
int ny = cur.ss + dy[k] * 2;
if (allpts.find({nx, ny}) != allpts.end() && track.find({nx, ny}) == track.end()) {
q.push({nx, ny});
track.insert({nx, ny});
}
}
}
return (int(track.size()) == n);
}
bool cmp(pair<pii, int> a, pair<pii, int> b) {
if (a.ff.ss != b.ff.ss) return a.ff.ss < b.ff.ss;
return a.ff.ff < b.ff.ff;
}
void st12() {
vector<pii> edge;
vis[pts[0].ss] = true;
for (int i = 0; i < n; i++) {
if (allpts.find({pts[i].ff.ff, pts[i].ff.ss + 2}) != allpts.end()) {
int v = allpts[{pts[i].ff.ff, pts[i].ff.ss + 2}];
if (!vis[v]) {
edge.pb({pts[i].ss, v});
vis[v] = true;
}
}
if (pts[i].ff.ff == 4 && allpts.find({2, pts[i].ff.ss}) != allpts.end()) {
int v = allpts[{2, pts[i].ff.ss}];
if (!vis[pts[i].ss] || !vis[v]) {
edge.pb({pts[i].ss, v});
vis[pts[i].ss] = true;
vis[v] = true;
}
}
}
int m = edge.size();
vector<int> u(m), v(m), a(m), b(m);
for (int i = 0; i < m; i++) {
u[i] = edge[i].ff;
v[i] = edge[i].ss;
if (opts[u[i]].ff == opts[v[i]].ff) {
a[i] = (opts[u[i]].ff == 2 ? 1 : 5);
b[i] = ((opts[u[i]].ss + opts[v[i]].ss) >> 1);
} else {
a[i] = 3;
b[i] = opts[u[i]].ss - 1;
}
}
build(u, v, a, b);
return;
}
void st3() {
}
int construct_roads(vector<int> ox, vector<int> oy) {
n = ox.size();
int minx = 1e9;
for (int i = 0; i < n; i++) {
pts[i] = {{ox[i], oy[i]}, i};
opts[i] = pts[i].ff;
allpts[pts[i].ff] = i;
minx = min(minx, pts[i].ff.ff);
}
sort(pts, pts + n, cmp);
// for (int i = 0; i < n; i++) {
// cout << pts[i].ff.ff << ' ' << pts[i].ff.ss << ' ' << pts[i].ss << endl;
// }
if (!CheckConnected()) return 0;
if (minx == 2 || minx == 4) st12();
else if (minx == 6) st3();
return 1;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
336 KB |
Output is correct |
2 |
Correct |
0 ms |
212 KB |
Output is correct |
3 |
Correct |
1 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 |
214 ms |
17692 KB |
Output is correct |
10 |
Correct |
13 ms |
2004 KB |
Output is correct |
11 |
Correct |
92 ms |
9392 KB |
Output is correct |
12 |
Correct |
24 ms |
2856 KB |
Output is correct |
13 |
Correct |
39 ms |
5964 KB |
Output is correct |
14 |
Correct |
2 ms |
340 KB |
Output is correct |
15 |
Correct |
2 ms |
468 KB |
Output is correct |
16 |
Correct |
186 ms |
17652 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
336 KB |
Output is correct |
2 |
Correct |
0 ms |
212 KB |
Output is correct |
3 |
Correct |
1 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 |
214 ms |
17692 KB |
Output is correct |
10 |
Correct |
13 ms |
2004 KB |
Output is correct |
11 |
Correct |
92 ms |
9392 KB |
Output is correct |
12 |
Correct |
24 ms |
2856 KB |
Output is correct |
13 |
Correct |
39 ms |
5964 KB |
Output is correct |
14 |
Correct |
2 ms |
340 KB |
Output is correct |
15 |
Correct |
2 ms |
468 KB |
Output is correct |
16 |
Correct |
186 ms |
17652 KB |
Output is correct |
17 |
Correct |
1 ms |
212 KB |
Output is correct |
18 |
Correct |
1 ms |
212 KB |
Output is correct |
19 |
Correct |
1 ms |
212 KB |
Output is correct |
20 |
Correct |
1 ms |
212 KB |
Output is correct |
21 |
Correct |
1 ms |
212 KB |
Output is correct |
22 |
Correct |
0 ms |
212 KB |
Output is correct |
23 |
Correct |
495 ms |
35260 KB |
Output is correct |
24 |
Correct |
1 ms |
212 KB |
Output is correct |
25 |
Correct |
3 ms |
468 KB |
Output is correct |
26 |
Correct |
3 ms |
596 KB |
Output is correct |
27 |
Correct |
3 ms |
712 KB |
Output is correct |
28 |
Correct |
163 ms |
14784 KB |
Output is correct |
29 |
Correct |
290 ms |
21772 KB |
Output is correct |
30 |
Correct |
401 ms |
29644 KB |
Output is correct |
31 |
Correct |
497 ms |
37000 KB |
Output is correct |
32 |
Correct |
1 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 |
1 ms |
212 KB |
Output is correct |
37 |
Correct |
1 ms |
212 KB |
Output is correct |
38 |
Correct |
1 ms |
212 KB |
Output is correct |
39 |
Correct |
1 ms |
212 KB |
Output is correct |
40 |
Correct |
1 ms |
212 KB |
Output is correct |
41 |
Correct |
1 ms |
316 KB |
Output is correct |
42 |
Correct |
1 ms |
312 KB |
Output is correct |
43 |
Correct |
2 ms |
448 KB |
Output is correct |
44 |
Correct |
3 ms |
744 KB |
Output is correct |
45 |
Correct |
226 ms |
18556 KB |
Output is correct |
46 |
Correct |
291 ms |
26732 KB |
Output is correct |
47 |
Correct |
315 ms |
26796 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
336 KB |
Output is correct |
2 |
Correct |
0 ms |
212 KB |
Output is correct |
3 |
Correct |
1 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 |
214 ms |
17692 KB |
Output is correct |
10 |
Correct |
13 ms |
2004 KB |
Output is correct |
11 |
Correct |
92 ms |
9392 KB |
Output is correct |
12 |
Correct |
24 ms |
2856 KB |
Output is correct |
13 |
Correct |
39 ms |
5964 KB |
Output is correct |
14 |
Correct |
2 ms |
340 KB |
Output is correct |
15 |
Correct |
2 ms |
468 KB |
Output is correct |
16 |
Correct |
186 ms |
17652 KB |
Output is correct |
17 |
Correct |
1 ms |
212 KB |
Output is correct |
18 |
Correct |
1 ms |
212 KB |
Output is correct |
19 |
Correct |
1 ms |
212 KB |
Output is correct |
20 |
Correct |
1 ms |
212 KB |
Output is correct |
21 |
Correct |
1 ms |
212 KB |
Output is correct |
22 |
Correct |
0 ms |
212 KB |
Output is correct |
23 |
Correct |
495 ms |
35260 KB |
Output is correct |
24 |
Correct |
1 ms |
212 KB |
Output is correct |
25 |
Correct |
3 ms |
468 KB |
Output is correct |
26 |
Correct |
3 ms |
596 KB |
Output is correct |
27 |
Correct |
3 ms |
712 KB |
Output is correct |
28 |
Correct |
163 ms |
14784 KB |
Output is correct |
29 |
Correct |
290 ms |
21772 KB |
Output is correct |
30 |
Correct |
401 ms |
29644 KB |
Output is correct |
31 |
Correct |
497 ms |
37000 KB |
Output is correct |
32 |
Correct |
1 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 |
1 ms |
212 KB |
Output is correct |
37 |
Correct |
1 ms |
212 KB |
Output is correct |
38 |
Correct |
1 ms |
212 KB |
Output is correct |
39 |
Correct |
1 ms |
212 KB |
Output is correct |
40 |
Correct |
1 ms |
212 KB |
Output is correct |
41 |
Correct |
1 ms |
316 KB |
Output is correct |
42 |
Correct |
1 ms |
312 KB |
Output is correct |
43 |
Correct |
2 ms |
448 KB |
Output is correct |
44 |
Correct |
3 ms |
744 KB |
Output is correct |
45 |
Correct |
226 ms |
18556 KB |
Output is correct |
46 |
Correct |
291 ms |
26732 KB |
Output is correct |
47 |
Correct |
315 ms |
26796 KB |
Output is correct |
48 |
Incorrect |
1 ms |
212 KB |
Tree @(5, 3) appears more than once: for edges on positions 0 and 1 |
49 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
336 KB |
Output is correct |
2 |
Correct |
0 ms |
212 KB |
Output is correct |
3 |
Correct |
1 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 |
214 ms |
17692 KB |
Output is correct |
10 |
Correct |
13 ms |
2004 KB |
Output is correct |
11 |
Correct |
92 ms |
9392 KB |
Output is correct |
12 |
Correct |
24 ms |
2856 KB |
Output is correct |
13 |
Correct |
39 ms |
5964 KB |
Output is correct |
14 |
Correct |
2 ms |
340 KB |
Output is correct |
15 |
Correct |
2 ms |
468 KB |
Output is correct |
16 |
Correct |
186 ms |
17652 KB |
Output is correct |
17 |
Incorrect |
0 ms |
212 KB |
Wrong answer detected in grader |
18 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
336 KB |
Output is correct |
2 |
Correct |
0 ms |
212 KB |
Output is correct |
3 |
Correct |
1 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 |
214 ms |
17692 KB |
Output is correct |
10 |
Correct |
13 ms |
2004 KB |
Output is correct |
11 |
Correct |
92 ms |
9392 KB |
Output is correct |
12 |
Correct |
24 ms |
2856 KB |
Output is correct |
13 |
Correct |
39 ms |
5964 KB |
Output is correct |
14 |
Correct |
2 ms |
340 KB |
Output is correct |
15 |
Correct |
2 ms |
468 KB |
Output is correct |
16 |
Correct |
186 ms |
17652 KB |
Output is correct |
17 |
Incorrect |
458 ms |
29912 KB |
Tree (a[2], b[2]) = (5, 3) is not adjacent to edge between u[2]=138413 @(100002, 2) and v[2]=87394 @(100002, 4) |
18 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
336 KB |
Output is correct |
2 |
Correct |
0 ms |
212 KB |
Output is correct |
3 |
Correct |
1 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 |
214 ms |
17692 KB |
Output is correct |
10 |
Correct |
13 ms |
2004 KB |
Output is correct |
11 |
Correct |
92 ms |
9392 KB |
Output is correct |
12 |
Correct |
24 ms |
2856 KB |
Output is correct |
13 |
Correct |
39 ms |
5964 KB |
Output is correct |
14 |
Correct |
2 ms |
340 KB |
Output is correct |
15 |
Correct |
2 ms |
468 KB |
Output is correct |
16 |
Correct |
186 ms |
17652 KB |
Output is correct |
17 |
Correct |
1 ms |
212 KB |
Output is correct |
18 |
Correct |
1 ms |
212 KB |
Output is correct |
19 |
Correct |
1 ms |
212 KB |
Output is correct |
20 |
Correct |
1 ms |
212 KB |
Output is correct |
21 |
Correct |
1 ms |
212 KB |
Output is correct |
22 |
Correct |
0 ms |
212 KB |
Output is correct |
23 |
Correct |
495 ms |
35260 KB |
Output is correct |
24 |
Correct |
1 ms |
212 KB |
Output is correct |
25 |
Correct |
3 ms |
468 KB |
Output is correct |
26 |
Correct |
3 ms |
596 KB |
Output is correct |
27 |
Correct |
3 ms |
712 KB |
Output is correct |
28 |
Correct |
163 ms |
14784 KB |
Output is correct |
29 |
Correct |
290 ms |
21772 KB |
Output is correct |
30 |
Correct |
401 ms |
29644 KB |
Output is correct |
31 |
Correct |
497 ms |
37000 KB |
Output is correct |
32 |
Correct |
1 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 |
1 ms |
212 KB |
Output is correct |
37 |
Correct |
1 ms |
212 KB |
Output is correct |
38 |
Correct |
1 ms |
212 KB |
Output is correct |
39 |
Correct |
1 ms |
212 KB |
Output is correct |
40 |
Correct |
1 ms |
212 KB |
Output is correct |
41 |
Correct |
1 ms |
316 KB |
Output is correct |
42 |
Correct |
1 ms |
312 KB |
Output is correct |
43 |
Correct |
2 ms |
448 KB |
Output is correct |
44 |
Correct |
3 ms |
744 KB |
Output is correct |
45 |
Correct |
226 ms |
18556 KB |
Output is correct |
46 |
Correct |
291 ms |
26732 KB |
Output is correct |
47 |
Correct |
315 ms |
26796 KB |
Output is correct |
48 |
Incorrect |
1 ms |
212 KB |
Tree @(5, 3) appears more than once: for edges on positions 0 and 1 |
49 |
Halted |
0 ms |
0 KB |
- |