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 <bits/stdc++.h>
int getDistance(int i, int j);
int hubDistance(int N, int sub);
typedef std::pair<int,int> pii;
pii MaisDistante(int N,int x){
int best=-1,alvo=0;
for(int i=0;i!=N;++i){
if(i==x)continue;
int d = getDistance(i,x);
if(d>best){
best=d;
alvo=i;
}
}
return {best,alvo};
}
int hubDistance(int N, int sub) {
pii alpha = MaisDistante(N,0);
pii beta = MaisDistante(N,alpha.second);
int d = beta.first;
int ans=1e9;
for(int i=0;i!=N;++i){
if(i==alpha.second||i==beta.second)continue;
int a = getDistance(i,alpha.second);
int b = getDistance(i,beta.second);
int soma = a+b;
int subt = soma-d;
int base = subt/2;
ans=std::min(ans,std::max(a,b)-base);
}
return ans;
}
Compilation message (stderr)
towns.cpp: In function 'int hubDistance(int, int)':
towns.cpp:18:28: warning: unused parameter 'sub' [-Wunused-parameter]
18 | 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... |