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;
map<pair<int,int>,int>m;
int getD(int x,int y) {
return getDistance(x,y);
if(x==y)return 0;
if(m[{x,y}]!=0)return m[{x,y}];
m[{x,y}]=m[{y,x}]=getDistance(x,y);
return m[{x,y}];
}
int getmindist(int f,int s,int t) {
int d1=getD(f,s);
int d2=getD(s,t);
int d3=getD(f,t);
int dd=(d1+d2-d3)/2;
int d=(d1+d3-d2)/2;
int ddd=(d2+d3-d1)/2;
return max(max(d,dd),ddd);
}
int hubDistance(int n,int sub) {
int maxd=0,maxind=0;
int md=0;
for(int i=1;i<n;i++) {
int p=getD(0,i);
if(maxd<p) {
maxd=p;
maxind=i;
}
}
md=maxind;
maxd=0;
maxind=0;
for(int i=0;i<n;i++) {
if(i==md)continue;
int p=getD(md,i);
if(maxd<p) {
maxd=p;
maxind=i;
}
}
int minr=1e12;
for(int i=0;i<n;i++) {
minr=min(minr,getmindist(i,md,maxind));
}
return minr;
}
Compilation message (stderr)
towns.cpp: In function 'int hubDistance(int, int)':
towns.cpp:42:14: warning: overflow in conversion from 'double' to 'int' changes value from '1.0e+12' to '2147483647' [-Woverflow]
42 | int minr=1e12;
| ^~~~
towns.cpp:21:27: warning: unused parameter 'sub' [-Wunused-parameter]
21 | 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... |