#include "parks.h"
#include <bits/stdc++.h>
using namespace std;
#define forn(i,n) for(int i=0;i<n;++i)
#define pb push_back
#define all(x) x.begin(), x.end()
#define pi pair<int,int>
#define f first
#define s second
struct DSU {
vector<int> p,sz;
int tot;
DSU(int n) {
forn(i,n) p.pb(i), sz.pb(1);
tot=n;
}
int get(int u) {
return p[u]==u?u:get(p[u]);
}
void uni(int u, int v) {
u=get(u), v=get(v);
if (sz[u]<sz[v]) swap(u,v);
sz[u]+=sz[v];
p[v]=u;
--tot;
}
};
int p3(vector<int> x, vector<int> y) {
int n=x.size();
vector<int> u,v,a,b;
map<pi,int> m;
forn(i,n) m[{x[i],y[i]}]=i;
DSU dsu(n);
vector<pi> z1={{0,-2},{0,2}};
vector<pi> z2={{-2,0},{2,0}};
forn(i,n) {
int f=x[i], s=y[i];
for(auto&x:z1) {
if (m.count({f+x.f,s+x.s})) {
if (i<m[{f+x.f,s+x.s}]) {
if (dsu.get(i)==dsu.get(m[{f+x.f,s+x.s}])) continue;
dsu.uni(i,m[{f+x.f,s+x.s}]);
u.pb(i), v.pb(m[{f+x.f,s+x.s}]);
}
}
}
}
forn(i,n) {
int f=x[i], s=y[i];
for(auto&x:z2) {
if (m.count({f+x.f,s+x.s})) {
if (i<m[{f+x.f,s+x.s}]) {
if (dsu.get(i)==dsu.get(m[{f+x.f,s+x.s}])) continue;
dsu.uni(i,m[{f+x.f,s+x.s}]);
u.pb(i), v.pb(m[{f+x.f,s+x.s}]);
}
}
}
}
if (u.size()!=n-1) return 0;
forn(i,n-1) {
int x1=x[u[i]], y1=y[u[i]];
int x2=x[v[i]], y2=y[v[i]];
if (x1==x2) {
if (x1==2) {
a.pb(1);
b.pb(max(y1,y2)-1);
} else if (x1==6) {
a.pb(7);
b.pb(max(y1,y2)-1);
} else {
if (max(y1,y2)%4) {
a.pb(3);
b.pb(max(y1,y2)-1);
} else {
a.pb(5);
b.pb(max(y1,y2)-1);
}
}
} else {
if ((max(x1,x2)+y1)%4) {
a.pb(5);
b.pb(y1+1);
} else {
a.pb(3);
b.pb(y1-1);
}
}
}
build(u,v,a,b);
return 1;
}
int construct_roads(vector<int> x, vector<int> y) {
int mx=0; for(auto&v:x) mx=max(mx,v);
if (mx<=6) return p3(x,y);
int n=x.size();
vector<int> u,v,a,b;
map<pi,int> m;
forn(i,n) m[{x[i],y[i]}]=i;
DSU dsu(n);
vector<pi> z={{-2,0},{2,0},{0,-2},{0,2}};
forn(i,n) {
int f=x[i], s=y[i];
for(auto&x:z) {
if (m.count({f+x.f,s+x.s})) {
if (i<m[{f+x.f,s+x.s}]) {
if (dsu.get(i)==dsu.get(m[{f+x.f,s+x.s}])) continue;
dsu.uni(i,m[{f+x.f,s+x.s}]);
u.pb(i), v.pb(m[{f+x.f,s+x.s}]);
}
}
}
}
if (u.size()!=n-1) return 0;
forn(i,n-1) {
int x1=x[u[i]], y1=y[u[i]];
int x2=x[v[i]], y2=y[v[i]];
if (x1==x2) {
if ((max(y1,y2)+x1)%4) {
a.pb(x1+1);
b.pb(max(y1,y2)-1);
} else {
a.pb(x1-1);
b.pb(max(y1,y2)-1);
}
} else {
if ((max(x1,x2)+y1)%4) {
a.pb(max(x1,x2)-1);
b.pb(y1-1);
} else {
a.pb(max(x1,x2)-1);
b.pb(y1+1);
}
}
}
build(u,v,a,b);
return 1;
}
Compilation message
parks.cpp: In function 'int p3(std::vector<int>, std::vector<int>)':
parks.cpp:64:14: warning: comparison of integer expressions of different signedness: 'std::vector<int>::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
64 | if (u.size()!=n-1) return 0;
| ~~~~~~~~^~~~~
parks.cpp: In function 'int construct_roads(std::vector<int>, std::vector<int>)':
parks.cpp:122:14: warning: comparison of integer expressions of different signedness: 'std::vector<int>::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
122 | if (u.size()!=n-1) return 0;
| ~~~~~~~~^~~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
1 ms |
212 KB |
Output is correct |
3 |
Correct |
0 ms |
212 KB |
Output is correct |
4 |
Correct |
0 ms |
300 KB |
Output is correct |
5 |
Correct |
1 ms |
212 KB |
Output is correct |
6 |
Correct |
1 ms |
212 KB |
Output is correct |
7 |
Correct |
1 ms |
212 KB |
Output is correct |
8 |
Correct |
1 ms |
212 KB |
Output is correct |
9 |
Correct |
152 ms |
15012 KB |
Output is correct |
10 |
Correct |
11 ms |
1976 KB |
Output is correct |
11 |
Correct |
67 ms |
8312 KB |
Output is correct |
12 |
Correct |
16 ms |
2804 KB |
Output is correct |
13 |
Correct |
45 ms |
5396 KB |
Output is correct |
14 |
Correct |
1 ms |
340 KB |
Output is correct |
15 |
Correct |
2 ms |
436 KB |
Output is correct |
16 |
Correct |
154 ms |
15004 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
1 ms |
212 KB |
Output is correct |
3 |
Correct |
0 ms |
212 KB |
Output is correct |
4 |
Correct |
0 ms |
300 KB |
Output is correct |
5 |
Correct |
1 ms |
212 KB |
Output is correct |
6 |
Correct |
1 ms |
212 KB |
Output is correct |
7 |
Correct |
1 ms |
212 KB |
Output is correct |
8 |
Correct |
1 ms |
212 KB |
Output is correct |
9 |
Correct |
152 ms |
15012 KB |
Output is correct |
10 |
Correct |
11 ms |
1976 KB |
Output is correct |
11 |
Correct |
67 ms |
8312 KB |
Output is correct |
12 |
Correct |
16 ms |
2804 KB |
Output is correct |
13 |
Correct |
45 ms |
5396 KB |
Output is correct |
14 |
Correct |
1 ms |
340 KB |
Output is correct |
15 |
Correct |
2 ms |
436 KB |
Output is correct |
16 |
Correct |
154 ms |
15004 KB |
Output is correct |
17 |
Correct |
0 ms |
212 KB |
Output is correct |
18 |
Correct |
0 ms |
212 KB |
Output is correct |
19 |
Incorrect |
1 ms |
296 KB |
Tree (a[4], b[4]) = (5, 7) is not adjacent to edge between u[4]=0 @(4, 6) and v[4]=5 @(2, 6) |
20 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
1 ms |
212 KB |
Output is correct |
3 |
Correct |
0 ms |
212 KB |
Output is correct |
4 |
Correct |
0 ms |
300 KB |
Output is correct |
5 |
Correct |
1 ms |
212 KB |
Output is correct |
6 |
Correct |
1 ms |
212 KB |
Output is correct |
7 |
Correct |
1 ms |
212 KB |
Output is correct |
8 |
Correct |
1 ms |
212 KB |
Output is correct |
9 |
Correct |
152 ms |
15012 KB |
Output is correct |
10 |
Correct |
11 ms |
1976 KB |
Output is correct |
11 |
Correct |
67 ms |
8312 KB |
Output is correct |
12 |
Correct |
16 ms |
2804 KB |
Output is correct |
13 |
Correct |
45 ms |
5396 KB |
Output is correct |
14 |
Correct |
1 ms |
340 KB |
Output is correct |
15 |
Correct |
2 ms |
436 KB |
Output is correct |
16 |
Correct |
154 ms |
15004 KB |
Output is correct |
17 |
Correct |
0 ms |
212 KB |
Output is correct |
18 |
Correct |
0 ms |
212 KB |
Output is correct |
19 |
Incorrect |
1 ms |
296 KB |
Tree (a[4], b[4]) = (5, 7) is not adjacent to edge between u[4]=0 @(4, 6) and v[4]=5 @(2, 6) |
20 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
1 ms |
212 KB |
Output is correct |
3 |
Correct |
0 ms |
212 KB |
Output is correct |
4 |
Correct |
0 ms |
300 KB |
Output is correct |
5 |
Correct |
1 ms |
212 KB |
Output is correct |
6 |
Correct |
1 ms |
212 KB |
Output is correct |
7 |
Correct |
1 ms |
212 KB |
Output is correct |
8 |
Correct |
1 ms |
212 KB |
Output is correct |
9 |
Correct |
152 ms |
15012 KB |
Output is correct |
10 |
Correct |
11 ms |
1976 KB |
Output is correct |
11 |
Correct |
67 ms |
8312 KB |
Output is correct |
12 |
Correct |
16 ms |
2804 KB |
Output is correct |
13 |
Correct |
45 ms |
5396 KB |
Output is correct |
14 |
Correct |
1 ms |
340 KB |
Output is correct |
15 |
Correct |
2 ms |
436 KB |
Output is correct |
16 |
Correct |
154 ms |
15004 KB |
Output is correct |
17 |
Correct |
1 ms |
300 KB |
Output is correct |
18 |
Correct |
1 ms |
212 KB |
Output is correct |
19 |
Correct |
1 ms |
300 KB |
Output is correct |
20 |
Correct |
438 ms |
27372 KB |
Output is correct |
21 |
Correct |
451 ms |
27404 KB |
Output is correct |
22 |
Correct |
496 ms |
27392 KB |
Output is correct |
23 |
Correct |
372 ms |
23440 KB |
Output is correct |
24 |
Correct |
281 ms |
18076 KB |
Output is correct |
25 |
Correct |
464 ms |
20364 KB |
Output is correct |
26 |
Correct |
422 ms |
20276 KB |
Output is correct |
27 |
Correct |
484 ms |
27380 KB |
Output is correct |
28 |
Correct |
454 ms |
27524 KB |
Output is correct |
29 |
Correct |
530 ms |
27576 KB |
Output is correct |
30 |
Correct |
529 ms |
27420 KB |
Output is correct |
31 |
Correct |
1 ms |
212 KB |
Output is correct |
32 |
Correct |
23 ms |
2672 KB |
Output is correct |
33 |
Correct |
107 ms |
9524 KB |
Output is correct |
34 |
Correct |
416 ms |
27388 KB |
Output is correct |
35 |
Correct |
13 ms |
1492 KB |
Output is correct |
36 |
Correct |
81 ms |
5636 KB |
Output is correct |
37 |
Correct |
180 ms |
10484 KB |
Output is correct |
38 |
Correct |
161 ms |
11688 KB |
Output is correct |
39 |
Correct |
242 ms |
15540 KB |
Output is correct |
40 |
Correct |
316 ms |
19456 KB |
Output is correct |
41 |
Correct |
417 ms |
23500 KB |
Output is correct |
42 |
Correct |
539 ms |
27432 KB |
Output is correct |
43 |
Correct |
1 ms |
212 KB |
Output is correct |
44 |
Incorrect |
1 ms |
212 KB |
Tree (a[0], b[0]) = (5, 3) is not adjacent to edge between u[0]=0 @(2, 2) and v[0]=1 @(4, 2) |
45 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
1 ms |
212 KB |
Output is correct |
3 |
Correct |
0 ms |
212 KB |
Output is correct |
4 |
Correct |
0 ms |
300 KB |
Output is correct |
5 |
Correct |
1 ms |
212 KB |
Output is correct |
6 |
Correct |
1 ms |
212 KB |
Output is correct |
7 |
Correct |
1 ms |
212 KB |
Output is correct |
8 |
Correct |
1 ms |
212 KB |
Output is correct |
9 |
Correct |
152 ms |
15012 KB |
Output is correct |
10 |
Correct |
11 ms |
1976 KB |
Output is correct |
11 |
Correct |
67 ms |
8312 KB |
Output is correct |
12 |
Correct |
16 ms |
2804 KB |
Output is correct |
13 |
Correct |
45 ms |
5396 KB |
Output is correct |
14 |
Correct |
1 ms |
340 KB |
Output is correct |
15 |
Correct |
2 ms |
436 KB |
Output is correct |
16 |
Correct |
154 ms |
15004 KB |
Output is correct |
17 |
Correct |
421 ms |
27456 KB |
Output is correct |
18 |
Correct |
411 ms |
27584 KB |
Output is correct |
19 |
Correct |
478 ms |
27520 KB |
Output is correct |
20 |
Correct |
530 ms |
26928 KB |
Output is correct |
21 |
Correct |
446 ms |
24184 KB |
Output is correct |
22 |
Correct |
0 ms |
212 KB |
Output is correct |
23 |
Correct |
57 ms |
5220 KB |
Output is correct |
24 |
Correct |
31 ms |
2484 KB |
Output is correct |
25 |
Correct |
125 ms |
7760 KB |
Output is correct |
26 |
Correct |
236 ms |
12340 KB |
Output is correct |
27 |
Correct |
219 ms |
14232 KB |
Output is correct |
28 |
Correct |
296 ms |
17816 KB |
Output is correct |
29 |
Correct |
390 ms |
20684 KB |
Output is correct |
30 |
Correct |
481 ms |
24076 KB |
Output is correct |
31 |
Correct |
505 ms |
27420 KB |
Output is correct |
32 |
Incorrect |
508 ms |
29032 KB |
Tree (a[159996], b[159996]) = (5, 30183) is not adjacent to edge between u[159996]=2 @(4, 30182) and v[159996]=134374 @(2, 30182) |
33 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
1 ms |
212 KB |
Output is correct |
3 |
Correct |
0 ms |
212 KB |
Output is correct |
4 |
Correct |
0 ms |
300 KB |
Output is correct |
5 |
Correct |
1 ms |
212 KB |
Output is correct |
6 |
Correct |
1 ms |
212 KB |
Output is correct |
7 |
Correct |
1 ms |
212 KB |
Output is correct |
8 |
Correct |
1 ms |
212 KB |
Output is correct |
9 |
Correct |
152 ms |
15012 KB |
Output is correct |
10 |
Correct |
11 ms |
1976 KB |
Output is correct |
11 |
Correct |
67 ms |
8312 KB |
Output is correct |
12 |
Correct |
16 ms |
2804 KB |
Output is correct |
13 |
Correct |
45 ms |
5396 KB |
Output is correct |
14 |
Correct |
1 ms |
340 KB |
Output is correct |
15 |
Correct |
2 ms |
436 KB |
Output is correct |
16 |
Correct |
154 ms |
15004 KB |
Output is correct |
17 |
Correct |
0 ms |
212 KB |
Output is correct |
18 |
Correct |
0 ms |
212 KB |
Output is correct |
19 |
Incorrect |
1 ms |
296 KB |
Tree (a[4], b[4]) = (5, 7) is not adjacent to edge between u[4]=0 @(4, 6) and v[4]=5 @(2, 6) |
20 |
Halted |
0 ms |
0 KB |
- |