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 ds[MAXN][MAXN];
int getDistance(int a, int b) {
return ds[a][b];
}*/
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 = 1; i < n; i++) {
int d = gd(1, i);
if(d > mx) {
mx = d; mx1 = i;
}
}
a = mx1; mx = 0;
for(int i = 0; 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 = 0; 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;
}
/*
int main() {
int n;
scanf("%d", &n);
for(int i = 0; i < n; i++) {
for(int j = 0; j < n; j++) {
scanf("%d", &ds[i][j]);
}
}
printf("%d\n", hubDistance(n, 0));
return 0;
}*/
Compilation message (stderr)
towns.cpp: In function 'int hubDistance(int, int)':
towns.cpp:20:28: warning: unused parameter 'sub' [-Wunused-parameter]
20 | 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... |