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 = 110;
int dist[maxn][maxn];
int hubDistance(int N, int sub) {
for (int i = 0; i < N; i++)
for (int j = 0; j < N; j++) dist[i][j] = -1;
for (int i = 1; i < N; i++) {
int x = getDistance(0, i);
dist[i][0] = x, dist[0][i] = x;
}
int r1 = 1, r2;
for (int i = 1; i < N; i++)
if (dist[0][r1] < dist[0][i]) r1 = i;
for (int i = 0; i < N; i++) {
int x = getDistance(r1, i);
dist[r1][i] = x, dist[i][r1] = x;
}
r2 = r1;
for (int i = 0; i < N; i++)
if (dist[r1][r2] < dist[r1][i]) {
// cout << dist[r1][r2] << " " << dist[r1][i] << " " << i << "\n";
r2 = i;
}
for (int i = 0; i < N; i++) {
int x = getDistance(i, r2);
dist[i][r2] = x, dist[r2][i] = x;
}
// cerr << r1 << " " << r2 << "\n";
map<int, int> mii;
for (int i = 0; i < N; i++)
if (i != r1 && i != r2) {
int sumall = (dist[i][r1] + dist[r1][r2] + dist[i][r2]) / 2;
int tor1 = sumall - dist[i][r2], toi = sumall - dist[r1][r2],
tor2 = sumall - dist[i][r1];
mii[tor1] = max({mii[tor1], tor1, tor2, toi});
}
int maxi = INT_MAX;
for (auto a : mii) maxi = min(maxi, a.second);
return maxi;
}
Compilation message (stderr)
towns.cpp: In function 'int hubDistance(int, int)':
towns.cpp:8:28: warning: unused parameter 'sub' [-Wunused-parameter]
8 | 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... |