///~~~LOTA~~~///
#include "parks.h"
#include <bits/stdc++.h>
using namespace std;
#define nl '\n'
#define ff first
#define ss second
#define ll long long
#define append push_back
#define pii pair<int,int>
#define all(x) (x).begin(),(x).end()
#define N 100001
int siz[N];
int par[N];
int root(int v){
if(!par[v]) return v;
par[v]=root(par[v]);
return par[v];
}
void merge(int v,int u){
v=root(v);
u=root(u);
par[u]=v;
siz[v]+=siz[u];
}
bool same(int v,int u){
return (root(v)==root(u));
}
int construct_roads(vector<int> x,vector<int> y){
map<pii,int> c,z;
int n,m,o,p,q,r;
n=x.size();
for(int i=1;i<=n;i++)
siz[i]=1;
vector<int> v,u,a,b;
for(int i=0;i<n;i++)
z[{x[i],y[i]}]=i+1;
for(auto& i:z){
p=i.ff.ff;
q=i.ff.ss;
r=z[{p-2,q}];
if(r){
if(!same(i.ss,r)){
merge(i.ss,r);
v.append(i.ss-1);
u.append(r-1);
if(!c[{p-1,q-1}]){
a.append(p-1);
b.append(q-1);
c[{p-1,q-1}]=1;
}
else if(!c[{p-1,q+1}]){
a.append(p-1);
b.append(q+1);
c[{p-1,q+1}]=1;
}
else return 0;
}
}
r=z[{p,q-2}];
if(r){
if(!same(i.ss,r)){
merge(i.ss,r);
v.append(i.ss-1);
u.append(r-1);
if(!c[{p-1,q-1}]){
a.append(p-1);
b.append(q-1);
c[{p-1,q-1}]=1;
}
else if(!c[{p+1,q-1}]){
a.append(p+1);
b.append(q-1);
c[{p+1,q-1}]=1;
}
else return 0;
}
}
}
if(siz[root(1)]!=n) return 0;
build(u,v,a,b);
return 1;
}
Compilation message
parks.cpp: In function 'int construct_roads(std::vector<int>, std::vector<int>)':
parks.cpp:31:11: warning: unused variable 'm' [-Wunused-variable]
31 | int n,m,o,p,q,r;
| ^
parks.cpp:31:13: warning: unused variable 'o' [-Wunused-variable]
31 | int n,m,o,p,q,r;
| ^
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
0 ms |
348 KB |
Output is correct |
6 |
Correct |
0 ms |
348 KB |
Output is correct |
7 |
Correct |
0 ms |
348 KB |
Output is correct |
8 |
Correct |
1 ms |
348 KB |
Output is correct |
9 |
Correct |
170 ms |
28112 KB |
Output is correct |
10 |
Correct |
14 ms |
3164 KB |
Output is correct |
11 |
Correct |
64 ms |
15392 KB |
Output is correct |
12 |
Correct |
15 ms |
4700 KB |
Output is correct |
13 |
Correct |
39 ms |
11208 KB |
Output is correct |
14 |
Correct |
1 ms |
604 KB |
Output is correct |
15 |
Correct |
2 ms |
860 KB |
Output is correct |
16 |
Correct |
150 ms |
27600 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
0 ms |
348 KB |
Output is correct |
6 |
Correct |
0 ms |
348 KB |
Output is correct |
7 |
Correct |
0 ms |
348 KB |
Output is correct |
8 |
Correct |
1 ms |
348 KB |
Output is correct |
9 |
Correct |
170 ms |
28112 KB |
Output is correct |
10 |
Correct |
14 ms |
3164 KB |
Output is correct |
11 |
Correct |
64 ms |
15392 KB |
Output is correct |
12 |
Correct |
15 ms |
4700 KB |
Output is correct |
13 |
Correct |
39 ms |
11208 KB |
Output is correct |
14 |
Correct |
1 ms |
604 KB |
Output is correct |
15 |
Correct |
2 ms |
860 KB |
Output is correct |
16 |
Correct |
150 ms |
27600 KB |
Output is correct |
17 |
Correct |
1 ms |
352 KB |
Output is correct |
18 |
Correct |
1 ms |
356 KB |
Output is correct |
19 |
Correct |
1 ms |
360 KB |
Output is correct |
20 |
Correct |
0 ms |
360 KB |
Output is correct |
21 |
Correct |
0 ms |
352 KB |
Output is correct |
22 |
Correct |
0 ms |
348 KB |
Output is correct |
23 |
Runtime error |
29 ms |
9164 KB |
Execution killed with signal 11 |
24 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
0 ms |
348 KB |
Output is correct |
6 |
Correct |
0 ms |
348 KB |
Output is correct |
7 |
Correct |
0 ms |
348 KB |
Output is correct |
8 |
Correct |
1 ms |
348 KB |
Output is correct |
9 |
Correct |
170 ms |
28112 KB |
Output is correct |
10 |
Correct |
14 ms |
3164 KB |
Output is correct |
11 |
Correct |
64 ms |
15392 KB |
Output is correct |
12 |
Correct |
15 ms |
4700 KB |
Output is correct |
13 |
Correct |
39 ms |
11208 KB |
Output is correct |
14 |
Correct |
1 ms |
604 KB |
Output is correct |
15 |
Correct |
2 ms |
860 KB |
Output is correct |
16 |
Correct |
150 ms |
27600 KB |
Output is correct |
17 |
Correct |
1 ms |
352 KB |
Output is correct |
18 |
Correct |
1 ms |
356 KB |
Output is correct |
19 |
Correct |
1 ms |
360 KB |
Output is correct |
20 |
Correct |
0 ms |
360 KB |
Output is correct |
21 |
Correct |
0 ms |
352 KB |
Output is correct |
22 |
Correct |
0 ms |
348 KB |
Output is correct |
23 |
Runtime error |
29 ms |
9164 KB |
Execution killed with signal 11 |
24 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
0 ms |
348 KB |
Output is correct |
6 |
Correct |
0 ms |
348 KB |
Output is correct |
7 |
Correct |
0 ms |
348 KB |
Output is correct |
8 |
Correct |
1 ms |
348 KB |
Output is correct |
9 |
Correct |
170 ms |
28112 KB |
Output is correct |
10 |
Correct |
14 ms |
3164 KB |
Output is correct |
11 |
Correct |
64 ms |
15392 KB |
Output is correct |
12 |
Correct |
15 ms |
4700 KB |
Output is correct |
13 |
Correct |
39 ms |
11208 KB |
Output is correct |
14 |
Correct |
1 ms |
604 KB |
Output is correct |
15 |
Correct |
2 ms |
860 KB |
Output is correct |
16 |
Correct |
150 ms |
27600 KB |
Output is correct |
17 |
Correct |
0 ms |
348 KB |
Output is correct |
18 |
Correct |
0 ms |
348 KB |
Output is correct |
19 |
Correct |
0 ms |
348 KB |
Output is correct |
20 |
Runtime error |
31 ms |
10064 KB |
Execution killed with signal 11 |
21 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
0 ms |
348 KB |
Output is correct |
6 |
Correct |
0 ms |
348 KB |
Output is correct |
7 |
Correct |
0 ms |
348 KB |
Output is correct |
8 |
Correct |
1 ms |
348 KB |
Output is correct |
9 |
Correct |
170 ms |
28112 KB |
Output is correct |
10 |
Correct |
14 ms |
3164 KB |
Output is correct |
11 |
Correct |
64 ms |
15392 KB |
Output is correct |
12 |
Correct |
15 ms |
4700 KB |
Output is correct |
13 |
Correct |
39 ms |
11208 KB |
Output is correct |
14 |
Correct |
1 ms |
604 KB |
Output is correct |
15 |
Correct |
2 ms |
860 KB |
Output is correct |
16 |
Correct |
150 ms |
27600 KB |
Output is correct |
17 |
Runtime error |
30 ms |
9544 KB |
Execution killed with signal 11 |
18 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
0 ms |
348 KB |
Output is correct |
6 |
Correct |
0 ms |
348 KB |
Output is correct |
7 |
Correct |
0 ms |
348 KB |
Output is correct |
8 |
Correct |
1 ms |
348 KB |
Output is correct |
9 |
Correct |
170 ms |
28112 KB |
Output is correct |
10 |
Correct |
14 ms |
3164 KB |
Output is correct |
11 |
Correct |
64 ms |
15392 KB |
Output is correct |
12 |
Correct |
15 ms |
4700 KB |
Output is correct |
13 |
Correct |
39 ms |
11208 KB |
Output is correct |
14 |
Correct |
1 ms |
604 KB |
Output is correct |
15 |
Correct |
2 ms |
860 KB |
Output is correct |
16 |
Correct |
150 ms |
27600 KB |
Output is correct |
17 |
Correct |
1 ms |
352 KB |
Output is correct |
18 |
Correct |
1 ms |
356 KB |
Output is correct |
19 |
Correct |
1 ms |
360 KB |
Output is correct |
20 |
Correct |
0 ms |
360 KB |
Output is correct |
21 |
Correct |
0 ms |
352 KB |
Output is correct |
22 |
Correct |
0 ms |
348 KB |
Output is correct |
23 |
Runtime error |
29 ms |
9164 KB |
Execution killed with signal 11 |
24 |
Halted |
0 ms |
0 KB |
- |