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;
typedef vector<ll> vii;
typedef pair<ll,ll> pii;
#define pb push_back
#define F first
#define S second
#define all(v) v.begin(),v.end()
const ll M=2e6+50;
vii adj[M];
bool vis[M];
void dfs(ll x){
if(vis[x])
return;
vis[x]=1;
for(auto it:adj[x]){
dfs(it);
}
}
int construct_roads(std::vector<int> x, std::vector<int> y) {
vector<pair<int,int>>f,m,b;
for(int i=0;i<x.size();i++){
if(x[i]==2){
f.pb({y[i],i});
}
else
b.pb({y[i],i});
}
sort(all(f)),sort(all(b));
vector<int>e1,e2,ax,ay;
for(int i=0;i<ll(f.size())-1;i++){
if(f[i+1].F-f[i].F==2){
e1.pb(f[i].S);
e2.pb(f[i+1].S);
ax.pb(1);
ay.pb(f[i].F+1);
}
}
for(int i=0;i<ll(b.size())-1;i++){
if(b[i+1].F-b[i].F==2){
e1.pb(b[i].S);
e2.pb(b[i+1].S);
ax.pb(5);
ay.pb(b[i].F+1);
}
}
ll i=0,j=0;
while(1){
if(i==f.size()||j==b.size())
break;
if(f[i].F==b[j].F){
e1.pb(f[i].S),e2.pb(b[j].S);
ax.pb(3),ay.pb(f[i].F-1);
i++,j++;
}
else if(f[i].F<b[j].F){
i++;
}
else if(b[j].F<f[i].F){
j++;
}
}
for(int i=0;i<e1.size();i++)
adj[e1[i]].pb(e2[i]),adj[e2[i]].pb(e1[i]);
dfs(0);
for(int i=0;i<x.size();i++){
if(!vis[i])
return 0;
}
build(e1,e2,ax,ay);
return 1;
}
Compilation message (stderr)
parks.cpp: In function 'int construct_roads(std::vector<int>, std::vector<int>)':
parks.cpp:24:18: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
24 | for(int i=0;i<x.size();i++){
| ~^~~~~~~~~
parks.cpp:51:13: warning: comparison of integer expressions of different signedness: 'll' {aka 'long long int'} and 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
51 | if(i==f.size()||j==b.size())
| ~^~~~~~~~~~
parks.cpp:51:26: warning: comparison of integer expressions of different signedness: 'll' {aka 'long long int'} and 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
51 | if(i==f.size()||j==b.size())
| ~^~~~~~~~~~
parks.cpp:65:18: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
65 | for(int i=0;i<e1.size();i++)
| ~^~~~~~~~~~
parks.cpp:68:18: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
68 | for(int i=0;i<x.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... |