#include "parks.h"
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define REP(i,n) for(int i = 0; i < n; i ++)
#define FOR(i,a,b) for(int i = a; i < b; i ++)
#define vi vector<int>
#define pb push_back
#define SZ(v) (int)v.size()
#define remax(a,b) a = max(a,b)
#define remin(a,b) a = min(a,b)
#define all(v) v.begin(),v.end()
#define pii pair<int,int>
#define F first
#define S second
const int MX = 200005;
int n;
pii a[MX];
set<pair<pii,int> > st;
vector<pii> dir = {{-2,0},{2,0},{0,-2},{0,2}};
vi adj[MX];
int par[MX];
int find(int x){
if(par[x] == x) return x;
return par[x] = find(par[x]);
}
signed construct_roads(vector<signed> x, vector<signed> y){
n = SZ(x);
REP(i,n){
a[i] = {x[i],y[i]};
st.insert({a[i],i});
par[i] = i;
}
vector<pii> edges;
REP(i,n){
REP(j,4){
pii bruh = {x[i]+dir[j].F,y[i]+dir[j].S};
auto it = st.lower_bound({bruh,0});
if(it != st.end()){
if((*it).F == bruh){
adj[i].pb((*it).S);
if(i < (*it).S) edges.pb({i,(*it).S});
}
}
}
}
vector<signed> u0, v0, a0, b0;
for(auto i:edges){
int u = i.F,v = i.S;
// cout << u << " " << v << "\n";
if(find(u) == find(v)) continue;
if(a[u] > a[v]) swap(u,v);
if(x[u] != x[v]){
continue;
}
else{
par[find(u)] = find(v);
u0.pb(u);
v0.pb(v);
if((x[u]+y[u])%4 == 0){
a0.pb(x[u]-1);
b0.pb(y[u]+1);
}
else{
a0.pb(x[u]+1);
b0.pb(y[u]+1);
}
}
}
for(auto i:edges){
int u = i.F,v = i.S;
// cout << u << " " << v << "\n";
if(find(u) == find(v)) continue;
if(a[u] > a[v]) swap(u,v);
if(x[u] != x[v]){
par[find(u)] = find(v);
u0.pb(u);
v0.pb(v);
if((x[u]+y[u])%4 == 0){
a0.pb(x[u]+1);
b0.pb(y[u]+1);
}
else{
a0.pb(x[u]+1);
b0.pb(y[u]-1);
}
}
else{
continue;
}
}
REP(i,n){
if(find(i) != find(1)) return 0;
}
build(u0, v0, a0, b0);
return 1;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
3 ms |
4940 KB |
Output is correct |
2 |
Correct |
4 ms |
4940 KB |
Output is correct |
3 |
Correct |
5 ms |
4940 KB |
Output is correct |
4 |
Correct |
4 ms |
4940 KB |
Output is correct |
5 |
Correct |
4 ms |
4940 KB |
Output is correct |
6 |
Correct |
4 ms |
4940 KB |
Output is correct |
7 |
Correct |
4 ms |
4940 KB |
Output is correct |
8 |
Correct |
4 ms |
4940 KB |
Output is correct |
9 |
Correct |
228 ms |
24956 KB |
Output is correct |
10 |
Correct |
17 ms |
7112 KB |
Output is correct |
11 |
Correct |
82 ms |
16392 KB |
Output is correct |
12 |
Correct |
28 ms |
8184 KB |
Output is correct |
13 |
Correct |
52 ms |
13240 KB |
Output is correct |
14 |
Correct |
6 ms |
5068 KB |
Output is correct |
15 |
Correct |
5 ms |
5324 KB |
Output is correct |
16 |
Correct |
243 ms |
24828 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
3 ms |
4940 KB |
Output is correct |
2 |
Correct |
4 ms |
4940 KB |
Output is correct |
3 |
Correct |
5 ms |
4940 KB |
Output is correct |
4 |
Correct |
4 ms |
4940 KB |
Output is correct |
5 |
Correct |
4 ms |
4940 KB |
Output is correct |
6 |
Correct |
4 ms |
4940 KB |
Output is correct |
7 |
Correct |
4 ms |
4940 KB |
Output is correct |
8 |
Correct |
4 ms |
4940 KB |
Output is correct |
9 |
Correct |
228 ms |
24956 KB |
Output is correct |
10 |
Correct |
17 ms |
7112 KB |
Output is correct |
11 |
Correct |
82 ms |
16392 KB |
Output is correct |
12 |
Correct |
28 ms |
8184 KB |
Output is correct |
13 |
Correct |
52 ms |
13240 KB |
Output is correct |
14 |
Correct |
6 ms |
5068 KB |
Output is correct |
15 |
Correct |
5 ms |
5324 KB |
Output is correct |
16 |
Correct |
243 ms |
24828 KB |
Output is correct |
17 |
Correct |
4 ms |
4940 KB |
Output is correct |
18 |
Incorrect |
4 ms |
4940 KB |
Tree @(3, 5) appears more than once: for edges on positions 0 and 1 |
19 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
3 ms |
4940 KB |
Output is correct |
2 |
Correct |
4 ms |
4940 KB |
Output is correct |
3 |
Correct |
5 ms |
4940 KB |
Output is correct |
4 |
Correct |
4 ms |
4940 KB |
Output is correct |
5 |
Correct |
4 ms |
4940 KB |
Output is correct |
6 |
Correct |
4 ms |
4940 KB |
Output is correct |
7 |
Correct |
4 ms |
4940 KB |
Output is correct |
8 |
Correct |
4 ms |
4940 KB |
Output is correct |
9 |
Correct |
228 ms |
24956 KB |
Output is correct |
10 |
Correct |
17 ms |
7112 KB |
Output is correct |
11 |
Correct |
82 ms |
16392 KB |
Output is correct |
12 |
Correct |
28 ms |
8184 KB |
Output is correct |
13 |
Correct |
52 ms |
13240 KB |
Output is correct |
14 |
Correct |
6 ms |
5068 KB |
Output is correct |
15 |
Correct |
5 ms |
5324 KB |
Output is correct |
16 |
Correct |
243 ms |
24828 KB |
Output is correct |
17 |
Correct |
4 ms |
4940 KB |
Output is correct |
18 |
Incorrect |
4 ms |
4940 KB |
Tree @(3, 5) appears more than once: for edges on positions 0 and 1 |
19 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
3 ms |
4940 KB |
Output is correct |
2 |
Correct |
4 ms |
4940 KB |
Output is correct |
3 |
Correct |
5 ms |
4940 KB |
Output is correct |
4 |
Correct |
4 ms |
4940 KB |
Output is correct |
5 |
Correct |
4 ms |
4940 KB |
Output is correct |
6 |
Correct |
4 ms |
4940 KB |
Output is correct |
7 |
Correct |
4 ms |
4940 KB |
Output is correct |
8 |
Correct |
4 ms |
4940 KB |
Output is correct |
9 |
Correct |
228 ms |
24956 KB |
Output is correct |
10 |
Correct |
17 ms |
7112 KB |
Output is correct |
11 |
Correct |
82 ms |
16392 KB |
Output is correct |
12 |
Correct |
28 ms |
8184 KB |
Output is correct |
13 |
Correct |
52 ms |
13240 KB |
Output is correct |
14 |
Correct |
6 ms |
5068 KB |
Output is correct |
15 |
Correct |
5 ms |
5324 KB |
Output is correct |
16 |
Correct |
243 ms |
24828 KB |
Output is correct |
17 |
Correct |
5 ms |
4940 KB |
Output is correct |
18 |
Correct |
5 ms |
4940 KB |
Output is correct |
19 |
Correct |
4 ms |
4940 KB |
Output is correct |
20 |
Correct |
699 ms |
45268 KB |
Output is correct |
21 |
Correct |
748 ms |
45008 KB |
Output is correct |
22 |
Correct |
727 ms |
45136 KB |
Output is correct |
23 |
Correct |
577 ms |
39252 KB |
Output is correct |
24 |
Correct |
620 ms |
25332 KB |
Output is correct |
25 |
Correct |
810 ms |
40184 KB |
Output is correct |
26 |
Correct |
596 ms |
40076 KB |
Output is correct |
27 |
Correct |
713 ms |
44852 KB |
Output is correct |
28 |
Correct |
674 ms |
44856 KB |
Output is correct |
29 |
Correct |
920 ms |
44820 KB |
Output is correct |
30 |
Correct |
834 ms |
44804 KB |
Output is correct |
31 |
Correct |
5 ms |
4940 KB |
Output is correct |
32 |
Correct |
36 ms |
7860 KB |
Output is correct |
33 |
Correct |
164 ms |
15132 KB |
Output is correct |
34 |
Correct |
602 ms |
45328 KB |
Output is correct |
35 |
Correct |
24 ms |
6856 KB |
Output is correct |
36 |
Correct |
137 ms |
13924 KB |
Output is correct |
37 |
Correct |
295 ms |
23020 KB |
Output is correct |
38 |
Correct |
227 ms |
21760 KB |
Output is correct |
39 |
Correct |
425 ms |
27432 KB |
Output is correct |
40 |
Correct |
576 ms |
34600 KB |
Output is correct |
41 |
Correct |
757 ms |
40332 KB |
Output is correct |
42 |
Correct |
1050 ms |
46084 KB |
Output is correct |
43 |
Correct |
3 ms |
4940 KB |
Output is correct |
44 |
Correct |
4 ms |
4940 KB |
Output is correct |
45 |
Correct |
3 ms |
4940 KB |
Output is correct |
46 |
Correct |
4 ms |
4940 KB |
Output is correct |
47 |
Correct |
4 ms |
4940 KB |
Output is correct |
48 |
Correct |
4 ms |
4940 KB |
Output is correct |
49 |
Correct |
8 ms |
4940 KB |
Output is correct |
50 |
Correct |
3 ms |
4940 KB |
Output is correct |
51 |
Correct |
3 ms |
4940 KB |
Output is correct |
52 |
Correct |
3 ms |
4940 KB |
Output is correct |
53 |
Correct |
3 ms |
4940 KB |
Output is correct |
54 |
Correct |
5 ms |
5324 KB |
Output is correct |
55 |
Correct |
7 ms |
5452 KB |
Output is correct |
56 |
Correct |
288 ms |
25284 KB |
Output is correct |
57 |
Correct |
544 ms |
35236 KB |
Output is correct |
58 |
Correct |
521 ms |
35248 KB |
Output is correct |
59 |
Correct |
4 ms |
4940 KB |
Output is correct |
60 |
Correct |
4 ms |
4940 KB |
Output is correct |
61 |
Correct |
4 ms |
4940 KB |
Output is correct |
62 |
Correct |
640 ms |
44824 KB |
Output is correct |
63 |
Correct |
604 ms |
44752 KB |
Output is correct |
64 |
Correct |
619 ms |
44624 KB |
Output is correct |
65 |
Correct |
8 ms |
5708 KB |
Output is correct |
66 |
Correct |
14 ms |
6312 KB |
Output is correct |
67 |
Correct |
304 ms |
25244 KB |
Output is correct |
68 |
Correct |
537 ms |
36088 KB |
Output is correct |
69 |
Correct |
869 ms |
45600 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
3 ms |
4940 KB |
Output is correct |
2 |
Correct |
4 ms |
4940 KB |
Output is correct |
3 |
Correct |
5 ms |
4940 KB |
Output is correct |
4 |
Correct |
4 ms |
4940 KB |
Output is correct |
5 |
Correct |
4 ms |
4940 KB |
Output is correct |
6 |
Correct |
4 ms |
4940 KB |
Output is correct |
7 |
Correct |
4 ms |
4940 KB |
Output is correct |
8 |
Correct |
4 ms |
4940 KB |
Output is correct |
9 |
Correct |
228 ms |
24956 KB |
Output is correct |
10 |
Correct |
17 ms |
7112 KB |
Output is correct |
11 |
Correct |
82 ms |
16392 KB |
Output is correct |
12 |
Correct |
28 ms |
8184 KB |
Output is correct |
13 |
Correct |
52 ms |
13240 KB |
Output is correct |
14 |
Correct |
6 ms |
5068 KB |
Output is correct |
15 |
Correct |
5 ms |
5324 KB |
Output is correct |
16 |
Correct |
243 ms |
24828 KB |
Output is correct |
17 |
Correct |
698 ms |
44912 KB |
Output is correct |
18 |
Correct |
703 ms |
44948 KB |
Output is correct |
19 |
Correct |
748 ms |
45068 KB |
Output is correct |
20 |
Correct |
936 ms |
46144 KB |
Output is correct |
21 |
Correct |
808 ms |
40940 KB |
Output is correct |
22 |
Correct |
3 ms |
4940 KB |
Output is correct |
23 |
Correct |
70 ms |
11480 KB |
Output is correct |
24 |
Correct |
38 ms |
8752 KB |
Output is correct |
25 |
Correct |
221 ms |
18344 KB |
Output is correct |
26 |
Correct |
375 ms |
26824 KB |
Output is correct |
27 |
Correct |
350 ms |
25896 KB |
Output is correct |
28 |
Correct |
462 ms |
30664 KB |
Output is correct |
29 |
Correct |
655 ms |
37040 KB |
Output is correct |
30 |
Correct |
725 ms |
41892 KB |
Output is correct |
31 |
Correct |
1077 ms |
46744 KB |
Output is correct |
32 |
Correct |
958 ms |
46716 KB |
Output is correct |
33 |
Correct |
639 ms |
44820 KB |
Output is correct |
34 |
Correct |
10 ms |
5836 KB |
Output is correct |
35 |
Correct |
19 ms |
6672 KB |
Output is correct |
36 |
Correct |
387 ms |
25540 KB |
Output is correct |
37 |
Correct |
520 ms |
36588 KB |
Output is correct |
38 |
Correct |
868 ms |
46060 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
3 ms |
4940 KB |
Output is correct |
2 |
Correct |
4 ms |
4940 KB |
Output is correct |
3 |
Correct |
5 ms |
4940 KB |
Output is correct |
4 |
Correct |
4 ms |
4940 KB |
Output is correct |
5 |
Correct |
4 ms |
4940 KB |
Output is correct |
6 |
Correct |
4 ms |
4940 KB |
Output is correct |
7 |
Correct |
4 ms |
4940 KB |
Output is correct |
8 |
Correct |
4 ms |
4940 KB |
Output is correct |
9 |
Correct |
228 ms |
24956 KB |
Output is correct |
10 |
Correct |
17 ms |
7112 KB |
Output is correct |
11 |
Correct |
82 ms |
16392 KB |
Output is correct |
12 |
Correct |
28 ms |
8184 KB |
Output is correct |
13 |
Correct |
52 ms |
13240 KB |
Output is correct |
14 |
Correct |
6 ms |
5068 KB |
Output is correct |
15 |
Correct |
5 ms |
5324 KB |
Output is correct |
16 |
Correct |
243 ms |
24828 KB |
Output is correct |
17 |
Correct |
4 ms |
4940 KB |
Output is correct |
18 |
Incorrect |
4 ms |
4940 KB |
Tree @(3, 5) appears more than once: for edges on positions 0 and 1 |
19 |
Halted |
0 ms |
0 KB |
- |