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 N = 500;
int memo[N][N];
int dist(int u,int v){
if(u == v)return 0;
if(u > v)swap(u, v);
if(memo[u][v] != -1)return memo[u][v];
return memo[u][v] = getDistance(u, v);
}
int hubDistance(int n, int sub) {
memset(memo, -1, sizeof memo);
int u = 0;
for(int i = 1;i < n;i++){
if(dist(i, 0) > dist(u, 0))u = i;
}
int v = 0;
for(int i = 1;i < n;i++){
if(dist(i, u) > dist(v, u))v = i;
}
int ans = 1e9;;
for(int i = 0;i <n;i++){
int d = ( dist(i, u) + dist(i, v) - dist(u, v)) / 2;
ans = min(ans, max(dist(i, u) - d, dist(i, v) - d));
}
return ans;
}
Compilation message (stderr)
towns.cpp: In function 'int hubDistance(int, int)':
towns.cpp:17:28: warning: unused parameter 'sub' [-Wunused-parameter]
17 | int hubDistance(int n, int sub) {
| ~~~~^~~
# | 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... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |