#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> 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 (x1==2) {
a.pb(1);
b.pb(max(y1,y2)-1);
} else {
a.pb(5);
b.pb(max(y1,y2)-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<=4) 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:51:14: warning: comparison of integer expressions of different signedness: 'std::vector<int>::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
51 | if (u.size()!=n-1) return 0;
| ~~~~~~~~^~~~~
parks.cpp: In function 'int construct_roads(std::vector<int>, std::vector<int>)':
parks.cpp:96:14: warning: comparison of integer expressions of different signedness: 'std::vector<int>::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
96 | if (u.size()!=n-1) return 0;
| ~~~~~~~~^~~~~
# |
결과 |
실행 시간 |
메모리 |
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 |
300 KB |
Output is correct |
5 |
Correct |
1 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 |
156 ms |
14780 KB |
Output is correct |
10 |
Correct |
11 ms |
2004 KB |
Output is correct |
11 |
Correct |
74 ms |
8176 KB |
Output is correct |
12 |
Correct |
16 ms |
2772 KB |
Output is correct |
13 |
Correct |
52 ms |
5188 KB |
Output is correct |
14 |
Correct |
2 ms |
340 KB |
Output is correct |
15 |
Correct |
2 ms |
468 KB |
Output is correct |
16 |
Correct |
166 ms |
14900 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
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 |
300 KB |
Output is correct |
5 |
Correct |
1 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 |
156 ms |
14780 KB |
Output is correct |
10 |
Correct |
11 ms |
2004 KB |
Output is correct |
11 |
Correct |
74 ms |
8176 KB |
Output is correct |
12 |
Correct |
16 ms |
2772 KB |
Output is correct |
13 |
Correct |
52 ms |
5188 KB |
Output is correct |
14 |
Correct |
2 ms |
340 KB |
Output is correct |
15 |
Correct |
2 ms |
468 KB |
Output is correct |
16 |
Correct |
166 ms |
14900 KB |
Output is correct |
17 |
Correct |
1 ms |
296 KB |
Output is correct |
18 |
Correct |
0 ms |
212 KB |
Output is correct |
19 |
Correct |
0 ms |
212 KB |
Output is correct |
20 |
Correct |
0 ms |
296 KB |
Output is correct |
21 |
Correct |
1 ms |
212 KB |
Output is correct |
22 |
Correct |
1 ms |
300 KB |
Output is correct |
23 |
Correct |
485 ms |
30220 KB |
Output is correct |
24 |
Correct |
0 ms |
212 KB |
Output is correct |
25 |
Correct |
2 ms |
468 KB |
Output is correct |
26 |
Correct |
4 ms |
596 KB |
Output is correct |
27 |
Correct |
5 ms |
760 KB |
Output is correct |
28 |
Correct |
169 ms |
12652 KB |
Output is correct |
29 |
Correct |
273 ms |
18304 KB |
Output is correct |
30 |
Correct |
361 ms |
24276 KB |
Output is correct |
31 |
Correct |
508 ms |
30260 KB |
Output is correct |
32 |
Correct |
1 ms |
212 KB |
Output is correct |
33 |
Correct |
0 ms |
212 KB |
Output is correct |
34 |
Correct |
0 ms |
212 KB |
Output is correct |
35 |
Correct |
1 ms |
296 KB |
Output is correct |
36 |
Correct |
0 ms |
212 KB |
Output is correct |
37 |
Correct |
0 ms |
212 KB |
Output is correct |
38 |
Correct |
0 ms |
212 KB |
Output is correct |
39 |
Correct |
0 ms |
212 KB |
Output is correct |
40 |
Correct |
0 ms |
212 KB |
Output is correct |
41 |
Correct |
0 ms |
212 KB |
Output is correct |
42 |
Correct |
0 ms |
212 KB |
Output is correct |
43 |
Correct |
2 ms |
468 KB |
Output is correct |
44 |
Correct |
3 ms |
596 KB |
Output is correct |
45 |
Correct |
190 ms |
15424 KB |
Output is correct |
46 |
Correct |
281 ms |
21972 KB |
Output is correct |
47 |
Correct |
303 ms |
22032 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
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 |
300 KB |
Output is correct |
5 |
Correct |
1 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 |
156 ms |
14780 KB |
Output is correct |
10 |
Correct |
11 ms |
2004 KB |
Output is correct |
11 |
Correct |
74 ms |
8176 KB |
Output is correct |
12 |
Correct |
16 ms |
2772 KB |
Output is correct |
13 |
Correct |
52 ms |
5188 KB |
Output is correct |
14 |
Correct |
2 ms |
340 KB |
Output is correct |
15 |
Correct |
2 ms |
468 KB |
Output is correct |
16 |
Correct |
166 ms |
14900 KB |
Output is correct |
17 |
Correct |
1 ms |
296 KB |
Output is correct |
18 |
Correct |
0 ms |
212 KB |
Output is correct |
19 |
Correct |
0 ms |
212 KB |
Output is correct |
20 |
Correct |
0 ms |
296 KB |
Output is correct |
21 |
Correct |
1 ms |
212 KB |
Output is correct |
22 |
Correct |
1 ms |
300 KB |
Output is correct |
23 |
Correct |
485 ms |
30220 KB |
Output is correct |
24 |
Correct |
0 ms |
212 KB |
Output is correct |
25 |
Correct |
2 ms |
468 KB |
Output is correct |
26 |
Correct |
4 ms |
596 KB |
Output is correct |
27 |
Correct |
5 ms |
760 KB |
Output is correct |
28 |
Correct |
169 ms |
12652 KB |
Output is correct |
29 |
Correct |
273 ms |
18304 KB |
Output is correct |
30 |
Correct |
361 ms |
24276 KB |
Output is correct |
31 |
Correct |
508 ms |
30260 KB |
Output is correct |
32 |
Correct |
1 ms |
212 KB |
Output is correct |
33 |
Correct |
0 ms |
212 KB |
Output is correct |
34 |
Correct |
0 ms |
212 KB |
Output is correct |
35 |
Correct |
1 ms |
296 KB |
Output is correct |
36 |
Correct |
0 ms |
212 KB |
Output is correct |
37 |
Correct |
0 ms |
212 KB |
Output is correct |
38 |
Correct |
0 ms |
212 KB |
Output is correct |
39 |
Correct |
0 ms |
212 KB |
Output is correct |
40 |
Correct |
0 ms |
212 KB |
Output is correct |
41 |
Correct |
0 ms |
212 KB |
Output is correct |
42 |
Correct |
0 ms |
212 KB |
Output is correct |
43 |
Correct |
2 ms |
468 KB |
Output is correct |
44 |
Correct |
3 ms |
596 KB |
Output is correct |
45 |
Correct |
190 ms |
15424 KB |
Output is correct |
46 |
Correct |
281 ms |
21972 KB |
Output is correct |
47 |
Correct |
303 ms |
22032 KB |
Output is correct |
48 |
Correct |
1 ms |
212 KB |
Output is correct |
49 |
Correct |
1 ms |
212 KB |
Output is correct |
50 |
Incorrect |
0 ms |
212 KB |
Tree @(5, 3) appears more than once: for edges on positions 0 and 4 |
51 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
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 |
300 KB |
Output is correct |
5 |
Correct |
1 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 |
156 ms |
14780 KB |
Output is correct |
10 |
Correct |
11 ms |
2004 KB |
Output is correct |
11 |
Correct |
74 ms |
8176 KB |
Output is correct |
12 |
Correct |
16 ms |
2772 KB |
Output is correct |
13 |
Correct |
52 ms |
5188 KB |
Output is correct |
14 |
Correct |
2 ms |
340 KB |
Output is correct |
15 |
Correct |
2 ms |
468 KB |
Output is correct |
16 |
Correct |
166 ms |
14900 KB |
Output is correct |
17 |
Correct |
1 ms |
296 KB |
Output is correct |
18 |
Correct |
0 ms |
212 KB |
Output is correct |
19 |
Correct |
1 ms |
300 KB |
Output is correct |
20 |
Correct |
433 ms |
27280 KB |
Output is correct |
21 |
Correct |
469 ms |
27328 KB |
Output is correct |
22 |
Correct |
536 ms |
27232 KB |
Output is correct |
23 |
Correct |
376 ms |
23380 KB |
Output is correct |
24 |
Correct |
293 ms |
17984 KB |
Output is correct |
25 |
Correct |
443 ms |
20164 KB |
Output is correct |
26 |
Correct |
424 ms |
20128 KB |
Output is correct |
27 |
Correct |
479 ms |
27544 KB |
Output is correct |
28 |
Correct |
516 ms |
27276 KB |
Output is correct |
29 |
Correct |
551 ms |
27424 KB |
Output is correct |
30 |
Correct |
494 ms |
27340 KB |
Output is correct |
31 |
Correct |
1 ms |
336 KB |
Output is correct |
32 |
Correct |
24 ms |
2636 KB |
Output is correct |
33 |
Correct |
94 ms |
9392 KB |
Output is correct |
34 |
Correct |
511 ms |
27244 KB |
Output is correct |
35 |
Correct |
15 ms |
1492 KB |
Output is correct |
36 |
Correct |
92 ms |
5528 KB |
Output is correct |
37 |
Correct |
223 ms |
10376 KB |
Output is correct |
38 |
Correct |
159 ms |
11584 KB |
Output is correct |
39 |
Correct |
263 ms |
15252 KB |
Output is correct |
40 |
Correct |
362 ms |
19252 KB |
Output is correct |
41 |
Correct |
438 ms |
23332 KB |
Output is correct |
42 |
Correct |
603 ms |
27340 KB |
Output is correct |
43 |
Correct |
0 ms |
212 KB |
Output is correct |
44 |
Correct |
1 ms |
340 KB |
Output is correct |
45 |
Correct |
1 ms |
212 KB |
Output is correct |
46 |
Correct |
1 ms |
212 KB |
Output is correct |
47 |
Correct |
0 ms |
212 KB |
Output is correct |
48 |
Correct |
0 ms |
212 KB |
Output is correct |
49 |
Correct |
1 ms |
212 KB |
Output is correct |
50 |
Correct |
1 ms |
212 KB |
Output is correct |
51 |
Correct |
1 ms |
212 KB |
Output is correct |
52 |
Correct |
1 ms |
212 KB |
Output is correct |
53 |
Correct |
1 ms |
212 KB |
Output is correct |
54 |
Correct |
3 ms |
468 KB |
Output is correct |
55 |
Correct |
3 ms |
596 KB |
Output is correct |
56 |
Correct |
213 ms |
14824 KB |
Output is correct |
57 |
Correct |
349 ms |
21108 KB |
Output is correct |
58 |
Correct |
334 ms |
21124 KB |
Output is correct |
59 |
Correct |
1 ms |
212 KB |
Output is correct |
60 |
Correct |
1 ms |
296 KB |
Output is correct |
61 |
Correct |
1 ms |
212 KB |
Output is correct |
62 |
Correct |
437 ms |
27276 KB |
Output is correct |
63 |
Correct |
407 ms |
27300 KB |
Output is correct |
64 |
Correct |
399 ms |
27092 KB |
Output is correct |
65 |
Correct |
5 ms |
724 KB |
Output is correct |
66 |
Correct |
9 ms |
1084 KB |
Output is correct |
67 |
Correct |
195 ms |
14120 KB |
Output is correct |
68 |
Correct |
337 ms |
20656 KB |
Output is correct |
69 |
Correct |
562 ms |
27336 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
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 |
300 KB |
Output is correct |
5 |
Correct |
1 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 |
156 ms |
14780 KB |
Output is correct |
10 |
Correct |
11 ms |
2004 KB |
Output is correct |
11 |
Correct |
74 ms |
8176 KB |
Output is correct |
12 |
Correct |
16 ms |
2772 KB |
Output is correct |
13 |
Correct |
52 ms |
5188 KB |
Output is correct |
14 |
Correct |
2 ms |
340 KB |
Output is correct |
15 |
Correct |
2 ms |
468 KB |
Output is correct |
16 |
Correct |
166 ms |
14900 KB |
Output is correct |
17 |
Correct |
438 ms |
27336 KB |
Output is correct |
18 |
Correct |
491 ms |
27268 KB |
Output is correct |
19 |
Correct |
530 ms |
27256 KB |
Output is correct |
20 |
Correct |
577 ms |
26720 KB |
Output is correct |
21 |
Correct |
446 ms |
23976 KB |
Output is correct |
22 |
Correct |
1 ms |
296 KB |
Output is correct |
23 |
Correct |
68 ms |
5080 KB |
Output is correct |
24 |
Correct |
36 ms |
2600 KB |
Output is correct |
25 |
Correct |
142 ms |
7720 KB |
Output is correct |
26 |
Correct |
263 ms |
12208 KB |
Output is correct |
27 |
Correct |
270 ms |
13964 KB |
Output is correct |
28 |
Correct |
295 ms |
17556 KB |
Output is correct |
29 |
Correct |
404 ms |
20588 KB |
Output is correct |
30 |
Correct |
458 ms |
23924 KB |
Output is correct |
31 |
Correct |
638 ms |
27304 KB |
Output is correct |
32 |
Correct |
605 ms |
27284 KB |
Output is correct |
33 |
Correct |
394 ms |
27316 KB |
Output is correct |
34 |
Correct |
6 ms |
852 KB |
Output is correct |
35 |
Correct |
11 ms |
1344 KB |
Output is correct |
36 |
Correct |
199 ms |
14048 KB |
Output is correct |
37 |
Correct |
315 ms |
20560 KB |
Output is correct |
38 |
Correct |
502 ms |
27332 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
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 |
300 KB |
Output is correct |
5 |
Correct |
1 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 |
156 ms |
14780 KB |
Output is correct |
10 |
Correct |
11 ms |
2004 KB |
Output is correct |
11 |
Correct |
74 ms |
8176 KB |
Output is correct |
12 |
Correct |
16 ms |
2772 KB |
Output is correct |
13 |
Correct |
52 ms |
5188 KB |
Output is correct |
14 |
Correct |
2 ms |
340 KB |
Output is correct |
15 |
Correct |
2 ms |
468 KB |
Output is correct |
16 |
Correct |
166 ms |
14900 KB |
Output is correct |
17 |
Correct |
1 ms |
296 KB |
Output is correct |
18 |
Correct |
0 ms |
212 KB |
Output is correct |
19 |
Correct |
0 ms |
212 KB |
Output is correct |
20 |
Correct |
0 ms |
296 KB |
Output is correct |
21 |
Correct |
1 ms |
212 KB |
Output is correct |
22 |
Correct |
1 ms |
300 KB |
Output is correct |
23 |
Correct |
485 ms |
30220 KB |
Output is correct |
24 |
Correct |
0 ms |
212 KB |
Output is correct |
25 |
Correct |
2 ms |
468 KB |
Output is correct |
26 |
Correct |
4 ms |
596 KB |
Output is correct |
27 |
Correct |
5 ms |
760 KB |
Output is correct |
28 |
Correct |
169 ms |
12652 KB |
Output is correct |
29 |
Correct |
273 ms |
18304 KB |
Output is correct |
30 |
Correct |
361 ms |
24276 KB |
Output is correct |
31 |
Correct |
508 ms |
30260 KB |
Output is correct |
32 |
Correct |
1 ms |
212 KB |
Output is correct |
33 |
Correct |
0 ms |
212 KB |
Output is correct |
34 |
Correct |
0 ms |
212 KB |
Output is correct |
35 |
Correct |
1 ms |
296 KB |
Output is correct |
36 |
Correct |
0 ms |
212 KB |
Output is correct |
37 |
Correct |
0 ms |
212 KB |
Output is correct |
38 |
Correct |
0 ms |
212 KB |
Output is correct |
39 |
Correct |
0 ms |
212 KB |
Output is correct |
40 |
Correct |
0 ms |
212 KB |
Output is correct |
41 |
Correct |
0 ms |
212 KB |
Output is correct |
42 |
Correct |
0 ms |
212 KB |
Output is correct |
43 |
Correct |
2 ms |
468 KB |
Output is correct |
44 |
Correct |
3 ms |
596 KB |
Output is correct |
45 |
Correct |
190 ms |
15424 KB |
Output is correct |
46 |
Correct |
281 ms |
21972 KB |
Output is correct |
47 |
Correct |
303 ms |
22032 KB |
Output is correct |
48 |
Correct |
1 ms |
212 KB |
Output is correct |
49 |
Correct |
1 ms |
212 KB |
Output is correct |
50 |
Incorrect |
0 ms |
212 KB |
Tree @(5, 3) appears more than once: for edges on positions 0 and 4 |
51 |
Halted |
0 ms |
0 KB |
- |