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 construct_roads(vector<int> x,vector<int> y){
int n = x.size();
map<pair<int,int>,int> lookup;
for(int i=0;i<n;i++)lookup[{x[i],y[i]}]=i;
vector<int> u,v,a,b;
vector<vector<int>> adj(n);
for(int i=0;i<n;i++){
if(lookup[{x[i]+2,y[i]}]>i){
u.emplace_back(i);
v.emplace_back(lookup[{x[i]+2,y[i]}]);
adj[i].emplace_back(lookup[{x[i]+2,y[i]}]);
adj[lookup[{x[i]+2,y[i]}]].emplace_back(i);
a.emplace_back(x[i]+1);
b.emplace_back(y[i]-1);
}
if(lookup[{x[i]-2,y[i]}]>i){
u.emplace_back(i);
v.emplace_back(lookup[{x[i]-2,y[i]}]);
adj[i].emplace_back(lookup[{x[i]-2,y[i]}]);
adj[lookup[{x[i]-2,y[i]}]].emplace_back(i);
a.emplace_back(x[i]-1);
b.emplace_back(y[i]-1);
}
if(lookup[{x[i],y[i]+2}]>i){
u.emplace_back(i);
v.emplace_back(lookup[{x[i],y[i]+2}]);
adj[i].emplace_back(lookup[{x[i],y[i]+2}]);
adj[lookup[{x[i],y[i]+2}]].emplace_back(i);
if(x[i]==2)a.emplace_back(x[i]-1);
else a.emplace_back(x[i]+1);
b.emplace_back(y[i]+1);
}
if(lookup[{x[i],y[i]-2}]>i){
u.emplace_back(i);
v.emplace_back(lookup[{x[i],y[i]-2}]);
adj[i].emplace_back(lookup[{x[i],y[i]-2}]);
adj[lookup[{x[i],y[i]-2}]].emplace_back(i);
if(x[i]==2)a.emplace_back(x[i]-1);
else a.emplace_back(x[i]+1);
b.emplace_back(y[i]-1);
}
}
vector<bool> visited(n);
int vis = 0;
function<void(int)> dfs = [&](int x){
if(visited[x])return;
visited[x]=true;
vis++;
for(int&i:adj[x])dfs(i);
};
dfs(0);
if(vis!=n)return 0;
build(u,v,a,b);
return 1;
}
# | 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... |