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;
using ar2 = array<int,2>;
int n;
int mem[120][120];
map<int,int> M;
int dis(int a, int b){
if(a==b) return 0;
if(mem[a][b]) return mem[a][b];
if(mem[b][a]) return mem[b][a];
return mem[a][b]=mem[b][a]=getDistance(a,b);
}
int hubDistance(int N, int sub) {
n = N; ar2 mx = {0,0};
int a = 0, b = 0; M.clear();
for(int i = 0; i < n; i++)
mx=max(mx,{dis(a,i),i});
a = mx[1]; mx = {0,0};
for(int i = 0; i < n; i++)
mx=max(mx,{dis(a,i),i});
b = mx[1];
int R = dis(a,b);
for(int i = 0; i < n; i++){
if(i==a or i==b)continue;
int branch = dis(a,i)+dis(b,i)-dis(a,b);
int pos = dis(a,i)-branch;
M[pos]=max(M[pos],branch+max(dis(a,i),dis(b,i)));
}
for(auto u : M) R=min(R,u.second);
return R;
}
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... |