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;
int n;
int dist[200][200];
int query(int i,int j){
if(j<i)swap(i,j);
if(!dist[i][j])dist[i][j]=getDistance(i,j);
return dist[i][j];
}
int hubDistance(int N, int sub) {
n=N;
int past=-1,point1=-1;
for(int i=1;i<n;i++){
if(past<query(0,i)){
point1=i;
past=query(0,i);
}
}
past=-1;
int point2=-1;
for(int i=0;i<n;i++){
if(i==point1)continue;
if(past<query(point1,i)){
point2=i;
past=query(point1,i);
}
}
int ds=query(point1,point2);
int ans=1e9;
for(int i=0;i<n;i++){
if(i==point1||i==point2)continue;
int tem=(query(point1,i)+query(point2,i)-ds)/2;
int val1=query(point1,i)-tem;
int val2=query(point2,i)-tem;
ans=min(ans,max({tem,val1,val2}));
}
return ans;
}
Compilation message (stderr)
towns.cpp: In function 'int hubDistance(int, int)':
towns.cpp:16:28: warning: unused parameter 'sub' [-Wunused-parameter]
16 | 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... |