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 ll long long
//#define int ll
#define rep(n) rep1(i,n)
#define rep1(i,n) rep2(i,0,n)
#define rep2(i,a,b) for(int i=a; i<(b); ++i)
#define rep3(i,a,b) for(int i=a; i>=(b); --i)
#define chkmax(a,b) (a=max(a,b))
#define chkmin(a,b) (a=min(a,b))
#define sz(a) ((int)a.size())
#define all(a) a.begin(),a.end()
#define pb push_back
#define pii pair<int,int>
#define pow2(x) (1ll<<(x))
#ifdef zisk
#define bug(...) cerr << "#" << __LINE__ << ": " << #__VA_ARGS__ << "- ", _do(__VA_ARGS__)
template<typename T> void _do(T x){cerr << x << endl;}
template<typename T, typename ...S> void _do(T x, S... y){cerr << x << ", "; _do(y...);}
#else
#define bug(...) 49
#endif
const int maxn=200005;
int n;
vector<pii> p;
map<pii,int> mp;
map<pii,vector<pii>> adj;
set<array<int,4>> edges;
int par[maxn];
int Find(int x){return x==par[x]?x:par[x]=Find(par[x]);}
#define y1 _y_1
pii get(int x1, int y1, int x2, int y2){
if(x1==x2){
if((x1+y1)%4==0) return pii(x1+1,y1+1);
else return pii(x1-1,y1+1);
}
else{
if((x1+y1)%4==0) return pii(x1+1,y1-1);
else return pii(x1+1,y1+1);
}
}
int construct_roads(vector<int> x, vector<int> y) {
n=sz(x);
rep(n) par[i]=i;
rep(n) mp[{x[i],y[i]}]=i;
vector<int> u, v, a, b;
rep(n){
if(mp.count({x[i],y[i]+2})){
int k=mp[{x[i],y[i]+2}];
if(Find(i)!=Find(k)){
bug(i,k);
par[Find(k)]=Find(i);
edges.insert({x[i],y[i],x[i],y[i]+2});
adj[{x[i],y[i]}].pb({x[i],y[i]+2});
adj[{x[i],y[i]+2}].pb({x[i],y[i]});
}
}
}
rep(n) p.pb({x[i],y[i]});
sort(all(p));
for(auto [x0,y0]: p){
if(mp.count({x0+2,y0})){
int k=mp[{x0+2,y0}];
if(Find(mp[{x0,y0}])!=Find(k)){
bug(mp[{x0,y0}],k);
par[Find(k)]=Find(mp[{x0,y0}]);
edges.insert({x0,y0,x0+2,y0});
adj[{x0,y0}].pb({x0+2,y0});
adj[{x0+2,y0}].pb({x0,y0});
}
}
}
bool flag=1;
rep(n) if(Find(i)!=Find(0)) flag=0;
if(!flag) return 0;
rep(n) if((x[i]+y[i])%4==0){
if(edges.count({x[i],y[i],x[i],y[i]+2})&&edges.count({x[i]+2,y[i],x[i]+2,y[i]+2})){
edges.erase({x[i]+2,y[i],x[i]+2,y[i]+2});
assert(!edges.count({x[i],y[i]+2,x[i]+2,y[i]+2}));
edges.insert({x[i],y[i]+2,x[i]+2,y[i]+2});
}
}
set<pii> st;
for(auto arr: edges){
u.pb(mp[{arr[0],arr[1]}]),v.pb(mp[{arr[2],arr[3]}]);
pii tmp=get(arr[0],arr[1],arr[2],arr[3]);
assert(!st.count(tmp));
st.insert(tmp);
a.pb(tmp.first),b.pb(tmp.second);
}
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:23:18: warning: statement has no effect [-Wunused-value]
23 | #define bug(...) 49
| ^~
parks.cpp:57:17: note: in expansion of macro 'bug'
57 | bug(i,k);
| ^~~
parks.cpp:23:18: warning: statement has no effect [-Wunused-value]
23 | #define bug(...) 49
| ^~
parks.cpp:71:17: note: in expansion of macro 'bug'
71 | bug(mp[{x0,y0}],k);
| ^~~
# | 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... |