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;
#define REP(i,n) for(int i = 0; i < n; i ++)
#define FOR(i,a,b) for(int i = a; i < b; i ++)
#define vi vector<int>
#define pb push_back
#define F first
#define S second
int d0[1005],dA[1005];
int n,A,B;
int hubDistance(int N, int sub){
n = N;
A = B = 0;
d0[0] = 0;
FOR(i,1,n){
d0[i] = getDistance(0,i);
if(d0[i] > d0[A]) A = i;
}
dA[0] = d0[A];
dA[A] = 0;
FOR(i,1,n){
if(i == A) continue;
dA[i] = getDistance(A,i);
if(dA[i] > dA[B]) B = i;
}
int R = 1000000000;
map<int,int> gg; // dist from A from path A-0
REP(i,n){
int lol = (dA[0]+dA[i]-d0[i])/2;
gg[lol]++;
R = min(R,max(dA[B]-lol,lol));
}
int cur = 0;
int hub = -1;
for(auto x:gg){
if(cur > n/2) break;
if(max(dA[B]-x.F,x.F) != R){
cur += x.S;
continue;
}
int p1 = x.S,p2 = n-cur-x.S;
if(p2 > n/2) continue;
if(p1 <= n/2) return R;
hub = x.F;
}
if(hub == -1) return -R;
vi elig;
REP(i,n){
if((dA[0]+dA[i]-d0[i])/2 == hub) elig.pb(i);
}
REP(i,(int)elig.size()){
int cnt = 0;
for(auto x:elig) cnt += (getDistance(elig[i],x) == (dA[x]+dA[elig[i]]-2*hub));
if(cnt > n/2) return -R;
}
return R;
}
Compilation message (stderr)
towns.cpp: In function 'int hubDistance(int, int)':
towns.cpp:15:28: warning: unused parameter 'sub' [-Wunused-parameter]
15 | 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... |