# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
990285 | starchan | 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<bits/stdc++.h>
#include "towns.h"
using namespace std;
#define in array<int, 2>
#define pb push_back
#define pob pop_back
int hubDistance(int n, int sub)
{
in opt = {0, 0};
for(int i = 1; i < n; i++)
opt = max(opt, {getDistance(i, 0), i});
int a = opt[1]; opt = {0, a};
vector<int> d1(n), d2(n); d1[a] = 0;
for(int i = 0; i < n; i++)
{
if(i == a) continue;
opt = max(opt, {d1[i] = getDistance(i, a), i});
}
auto [D, b] = opt; d2[b] = 0;
map<int, vector<int>> diam; diam[0].pb(a); diam[D].pb(b);
for(int i = 0; i < n; i++)
{
if(i == a || i == b)
continue;
d2[i] = getDistance(i, b);
diam[(d1[i]-d2[i]+D)/2].pb(i);
}
int R = INF;
for(auto [X, v]: diam)
R = min(R, max(X, D-X));
vector<vector<int>> gd;
for(auto [X, v]: diam)
{
if(max(X, D-X) == R)
gd.pb(v);
}
return R;
}