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;
#define vi vector<int>
#define pii pair<int,int>
#define vii vector<pii>
#define fi first
#define se second
class dsu{
public:
vi ind;
vi size;
dsu(int n){
ind=vi(n);
for (int i=0;i<n;i++) ind[i]=i;
size=vi(n,1);
}
int find(int x){
if (ind[x]==x) return x;
ind[x]=find(ind[x]);
return ind[x];
}
void unite(int a, int b){
a=find(a);
b=find(b);
if (a==b) return;
if (size[a]<size[b]) swap(a,b);
size[a]+=size[b];
ind[b]=a;
}
};
int construct_roads(vi cordx, vi cordy){
int n=cordx.size();
vii v(n);
for (int i=0;i<n;i++) v[i]=pii{cordx[i],cordy[i]};
vi u; //ind fuentes
vi w;
vi a; // coord banco
vi b;
map<pii,int> indfuente;
for (int i=0;i<n;i++) indfuente[v[i]]=i+1;
set<pii> posiblesbancos;
for (pii p:v){
posiblesbancos.insert(pii{p.fi+1,p.se+1});
posiblesbancos.insert(pii{p.fi+1,p.se-1});
posiblesbancos.insert(pii{p.fi-1,p.se+1});
posiblesbancos.insert(pii{p.fi-1,p.se-1});
}
for (pii p:posiblesbancos){
if ((p.fi+p.se)%4==0){
if (indfuente[pii{p.fi+1,p.se+1}] && indfuente[pii{p.fi-1,p.se+1}]){
u.push_back(indfuente[pii{p.fi+1,p.se+1}]-1);
w.push_back(indfuente[pii{p.fi-1,p.se+1}]-1);
a.push_back(p.fi);
b.push_back(p.se);
}
else if (indfuente[pii{p.fi+1,p.se-1}] && indfuente[pii{p.fi-1,p.se-1}]){
u.push_back(indfuente[pii{p.fi+1,p.se-1}]-1);
w.push_back(indfuente[pii{p.fi-1,p.se-1}]-1);
a.push_back(p.fi);
b.push_back(p.se);
}
}
else{
if (indfuente[pii{p.fi+1,p.se+1}] && indfuente[pii{p.fi+1,p.se-1}]){
u.push_back(indfuente[pii{p.fi+1,p.se+1}]-1);
w.push_back(indfuente[pii{p.fi+1,p.se-1}]-1);
a.push_back(p.fi);
b.push_back(p.se);
}
else if (indfuente[pii{p.fi-1,p.se+1}] && indfuente[pii{p.fi-1,p.se-1}]){
u.push_back(indfuente[pii{p.fi-1,p.se+1}]-1);
w.push_back(indfuente[pii{p.fi-1,p.se-1}]-1);
a.push_back(p.fi);
b.push_back(p.se);
}
}
}
dsu comp(n);
for (int i=0;i<u.size();i++) comp.unite(u[i],w[i]);
for (int i=0;i<n;i++) if (comp.find(i)!=comp.find(0)) return 0;
build(u,w,a,b);
return 1;
}
Compilation message (stderr)
parks.cpp: In function 'int construct_roads(std::vector<int>, std::vector<int>)':
parks.cpp:94:19: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
94 | for (int i=0;i<u.size();i++) comp.unite(u[i],w[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... |