# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
420561 | LouayFarah | Towns (IOI15_towns) | C++14 | 0 ms | 0 KiB |
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"
#include "towns.h"
using namespace std;
vector<vector<int>> dist;
vector<int> em;
int getDistance(int i, int j);
long long min(long long a, long long b)
{
if(a<=b)
return a;
return b;
}
long long hubDistance(int n, int sub)
{
em.assign(0, n);
dist.assign(n, em);
for(int i = 0; i<n; i++)
{
for(int j = i+1; j<n; j++)
{
int d = getDistance(i, j);
dist[i][j] = d;
dist[j][i] = d;
}
}
long long R = 1e18;
for(int i = 0; i<n; i++)
{
for(int j = i+1; j<n; j++)
{
int node = -1;
long long maxi = -1;
for(int k = 0; k<n; k++)
{
if(k==i||k==j)
continue;
if(dist[i][k]+dist[j][k]>maxi)
{
maxi = dist[i][k] + dist[j][k];
node = k;
}
}
long long temp = (dist[i][node] + dist[j][node] - dist[i][j])/2;
R = min(R, temp);
}
}
return R;
}