This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include "parks.h"
#include <bits/stdc++.h>
using namespace std;
int n,order[200001],p[200001],cnt;
map <int, int> mp[300001];
vector <int> px,py;
int f(int i){
return (p[i]==i?i:p[i]=f(p[i]));
}
bool unite(int i, int j){
i=f(i);
j=f(j);
if (i==j)
return false;
p[j]=i;
return true;
}
int construct_roads(vector <int> x, vector <int> y){
vector <int32_t> u,v,a,b;
n=x.size();
for (int i=0;i<n;i++)
mp[x[i]][y[i]]=i;
iota(order,order+n,0);
px=x,py=y;
sort(order,order+n,[](int i, int j){return make_pair(px[i],py[i])<make_pair(px[j],py[j]);});
for (int i=0;i<n;i++){
if (mp[x[i]-2].count(y[i])){
int X=x[i]-1,Y=(x[i]%4?(y[i]+3)/4*4-1:y[i]/4*4+1);
if (!mp[X].count(Y)){
u.push_back(i);
v.push_back(mp[x[i]-2][y[i]]);
a.push_back(X);
b.push_back(Y);
mp[X][Y]=1;
}
}
if (mp[x[i]].count(y[i]-2)){
int X=(y[i]%4?x[i]/4*4+1:(x[i]+3)/4*4-1),Y=y[i]-1;
if (!mp[X].count(Y)){
u.push_back(i);
v.push_back(mp[x[i]][y[i]-2]);
a.push_back(X);
b.push_back(Y);
mp[X][Y]=1;
}
}
}
iota(p,p+n,0);
for (int i=0;i<u.size();i++)
cnt+=unite(u[i],v[i]);
if (cnt<n-1)
return 0;
build(u,v,a,b);
return 1;
}
Compilation message (stderr)
parks.cpp: In function 'int construct_roads(std::vector<int>, std::vector<int>)':
parks.cpp:49:19: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
49 | for (int i=0;i<u.size();i++)
| ~^~~~~~~~~
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |