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>
#define N 200
using namespace std;
int dist[N][N];
int get(int i,int j){
if(i > j)swap(i,j);
if(i == j)return 0;
if(dist[i][j])return dist[i][j];
return dist[i][j] = getDistance(i,j);
}
int hubDistance(int n, int sub) {
for(int i = 0;i<n;i++){
for(int j = 0;j<n;j++){
dist[i][j] = 0;
}
}
int root = 0;
for(int i = 1;i<n;i++){
if(get(0,i) > get(0,root))
root = i;
}
int deepest = 0;
for(int i = 1;i<n;i++){
if(get(root,i) > get(root,deepest))
deepest = i;
}
set<int> depths;
for(int i = 0;i<n;i++){
depths.insert( (get(root,deepest) + get(root,i) -get(deepest,i) )/2);
}
int mini = 1e9;
for(auto u:depths){
mini = min(mini,max(u,get(root,deepest)-u));
}
return mini;
}
Compilation message (stderr)
towns.cpp: In function 'int hubDistance(int, int)':
towns.cpp:12:28: warning: unused parameter 'sub' [-Wunused-parameter]
12 | 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... |