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;
using ll = long long;
const int MAXN=2001; // 1-index that shit
const int INF=1000000000;
vector<int> adj[MAXN];
map<pair<int,int>,int> M;
int DistanceSum(int N, int *X, int *Y)
{
for(int i=0; i<N; i++)
{
int x=X[i];
int y=Y[i];
M[make_pair(x,y)]=i+1;
for(int x_b=-1; x_b<=1; x_b++)
{
for(int y_b=-1; y_b<=1; y_b++)
{
if(abs(x_b) + abs(y_b) != 1) continue;
if(M[make_pair(x+x_b,y+y_b)])
{
int cur = M[make_pair(x+x_b,y+y_b)];
adj[cur].push_back(i+1);
adj[i+1].push_back(cur);
}
}
}
}
ll ans=0;
for(int u=1; u<=N; u++)
{
vector<int> dis(N+1,INF);
dis[u]=0;
vector<int> BFS = {u};
while(!BFS.empty())
{
vector<int> new_BFS;
for(auto w:BFS)
{
for(auto v:adj[w])
{
if(dis[v]!=INF) continue;
dis[v]=dis[w]+1;
ans += ll(dis[v]);
// cout << u << " " << v << " " << dis[v] << endl;
new_BFS.push_back(v);
}
}
BFS = new_BFS;
}
}
return ll(ans/2LL);
}
# | 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... |