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 <bits/stdc++.h>
using namespace std;
#define endl "\n"
#define x first
#define y second
#define pii pair<int,int>
typedef long long int ll;
const int N=2e4+7;
vector<pii> points;
vector<int> adj[N];
int n;
bool vis[N];
int dist[N];
map<pii,int> mp;
vector<pii> edges;
ll ans;
void bfs(int x){
queue<int> q;
memset(vis,0,sizeof vis);
memset(dist,0,sizeof dist);
//cout<<"here"<<endl;
q.push(x);
dist[x]=0;
vis[x]=1;
while(!q.empty()) {
int u=q.front(); q.pop();
for(int v:adj[u]) {
if(!vis[v]) {
vis[v]=1;
q.push(v);
dist[v]=dist[u]+1;
}
}
}
for(int i=0; i<n; i++) {
ans+=dist[i];
}
// cout<<endl;
}
int DistanceSum(int N, int *X, int *Y)
{
n=N;
for(int i=0; i<n; i++) {
points.push_back({X[i],Y[i]});
mp[{X[i],Y[i]}]=i;
}
for(int i=0; i<(int)points.size(); i++) {
for(int j=i+1; j<(int)points.size(); j++) {
if(abs(points[i].x-points[j].x)+abs(points[i].y-points[j].y)==1) {
adj[mp[points[i]]].push_back(mp[points[j]]);
adj[mp[points[j]]].push_back(mp[points[i]]);
edges.push_back({mp[points[i]],mp[points[j]]});
}
}
}
for(int i=0; i<n; i++) {
bfs(i);
}
ans=ans/2;
return ans;
}
# | 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... |