# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
400253 | ly20 | Towns (IOI15_towns) | C++17 | 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 "towns.h"
#include <bits/stdc++.h>
using namespace std;
const int MAXN = 120;
int dist[MAXN][MAXN];
int gd(int a, int b) {
if(dist[a][b] == 0) {
dist[a][b] = getDistance(a, b);
dist[b][a] = dist[a][b];
}
return dist[a][b];
}
int hubDistance(int n, int sub) {
//int resp = 0;
int mx1 = 1, mx = 0;
int a, b;
for(int i = 2; i <= n; i++) {
int d = gd(1, i);
if(d > mx) {
mx = d; mx1 = i;
}
}
a = mx1; mx = 0;
for(int i = 1; i <= n; i++) {
if(i == a) continue;
int d = gd(a, i);
if(d > mx) {
mx = d; mx1 = i;
}
}
b = mx1;
int dim = mx;
//set <int> di;
int resp = dim;
for(int i = 1; i <= n; i++) {
if(i == a || i == b) continue;
int d = gd(a, i) - (gd(a, i) + gd(b, i) - dim) / 2;
resp = min(resp, max(d, dim - d));
}
return resp;
}