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 = 1e2 + 20;
int memo[maxN][maxN];
int dist(int u, int v) {
if (memo[u][v] != -1) {
return memo[u][v];
}
else {
return memo[u][v] = memo[v][u] = getDistance(u, v);
}
}
int hubDistance(int N, int sub) {
for (int i = 0; i < N; i++) {
for (int j = 0; j < N; j++) {
memo[i][j] = (i == j ? 0 : -1);
}
}
int X = 0;
for (int i = 0; i < N; i++) {
if (dist(0, i) > dist(0, X)) {
X = i;
}
}
int Y = 0;
for (int i = 0; i < N; i++) {
if (dist(X, i) > dist(X, Y)) {
Y = i;
}
}
int res = dist(X, Y);
for (int i = 0; i < N; i++) {
int extra = (dist(X, i) + dist(Y, i) - dist(X, Y)) / 2;
res = min(res, max(dist(X, i) - extra, dist(Y, i) - extra));
}
return res;
}
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... |