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;
typedef long long ll;
ll cad[7][200004]={ };
struct UFDS{
typedef long long ll;
ll nds;
vector<ll> P,S;
void init(ll n){
nds=n;
P.resize(n+1);S.resize(n+1);
for(int i=0; i<=n; i++){
P[i]=i;
S[i]=1;
}
}
ll Find_Set(ll i){
if(P[i]==i)return i;
else return P[i]=Find_Set(P[i]);
}
ll Size_Set(ll i){
return S[Find_Set(i)];
}
void Union_Set(ll a, ll b){
a=Find_Set(a);
b=Find_Set(b);
if(a!=b){
P[a]=b;
S[b]+=S[a];
nds--;
}
}
};
int construct_roads(std::vector<int> x, std::vector<int> y) {
if (x.size() == 1) {
build({}, {}, {}, {});
return 1;
}
ll n=x.size();
for(int i=0; i<n; i++)
{
cad[x[i]][y[i]]=i+1;
}
UFDS asd;
asd.init(n);
n=200001;
std::vector<int> u, v, a, b;
ll pl=0;
for(int i=2; i<n; i+=2)
{
if(cad[2][i]!=0&&cad[2][i+2]!=0)
{
u.push_back(cad[2][i]-1);
v.push_back(cad[2][i+2]-1);
a.push_back(1);
b.push_back(i+1);
}
if(cad[6][i]!=0&&cad[6][i+2]!=0)
{
u.push_back(cad[6][i]-1);
v.push_back(cad[6][i+2]-1);
a.push_back(7);
b.push_back(i+1);
}
}
for(int i=2; i<n; i+=2)
{
if(cad[4][i]!=0&&cad[4][i+2]==0)
{
if(cad[2][i]!=0)
{
u.push_back(cad[2][i]-1);
v.push_back(cad[4][i]-1);
a.push_back(3);
b.push_back(i+1);
}
if(cad[6][i]!=0)
{
u.push_back(cad[4][i]-1);
v.push_back(cad[6][i]-1);
a.push_back(5);
b.push_back(i+1);
}
}
else if(cad[4][i]!=0&&cad[2][i+2]==0&&cad[2][i]!=0&&cad[6][i+2]==0&&cad[6][i]!=0)
{
u.push_back(cad[4][i]-1);
v.push_back(cad[4][i+2]-1);
a.push_back(3);
b.push_back(i+1);
u.push_back(cad[2][i]-1);
v.push_back(cad[4][i]-1);
a.push_back(3);
b.push_back(i-1);
u.push_back(cad[6][i]-1);
v.push_back(cad[4][i]-1);
a.push_back(5);
b.push_back(i+1);
}
else if(cad[4][i]!=0&&cad[2][i+2]==0&&cad[2][i]!=0)
{
u.push_back(cad[4][i]-1);
v.push_back(cad[4][i+2]-1);
a.push_back(5);
b.push_back(i+1);
u.push_back(cad[2][i]-1);
v.push_back(cad[4][i]-1);
a.push_back(3);
b.push_back(i+1);
}
else if(cad[4][i]!=0&&cad[6][i+2]==0&&cad[6][i]!=0)
{
u.push_back(cad[4][i]-1);
v.push_back(cad[4][i+2]-1);
a.push_back(3);
b.push_back(i+1);
u.push_back(cad[6][i]-1);
v.push_back(cad[4][i]-1);
a.push_back(5);
b.push_back(i+1);
}
else if(cad[4][i]!=0&&cad[4][i+2]!=0)
{
u.push_back(cad[4][i]-1);
v.push_back(cad[4][i+2]-1);
a.push_back(5);
b.push_back(i+1);
}
}
for(int i=0; i<a.size(); i++)
{
asd.Union_Set(v[i],u[i]);
}
if(asd.Size_Set(0)!=x.size())
{
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:137:19: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
137 | for(int i=0; i<a.size(); i++)
| ~^~~~~~~~~
parks.cpp:141:23: warning: comparison of integer expressions of different signedness: 'UFDS::ll' {aka 'long long int'} and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
141 | if(asd.Size_Set(0)!=x.size())
| ~~~~~~~~~~~~~~~^~~~~~~~~~
parks.cpp:52:8: warning: unused variable 'pl' [-Wunused-variable]
52 | ll pl=0;
| ^~
# | 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... |