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 hubDistance(int n, int sub) {
sub--; // suppress unused warning
vector<int> d0(n), du(n);
for(int i = 1; i < n; i++) d0[i] = getDistance(0, i);
int u = int(max_element(d0.begin(), d0.end())-d0.begin());
for(int i = 0; i < n; i++) if(u!=i) du[i] = getDistance(u, i);
int v = int(max_element(du.begin(), du.end())-du.begin());
int dia = du[v];
int maxB = 0, maxC = 0;
for(int i = 0; i < n; i++){
int b = (d0[u]+d0[i]-du[i])/2;
int c = d0[u]-b;
if(b <= dia-(d0[u]+d0[v]+1)/2) maxB = max(maxB, b);
if(c <= dia/2) maxC = max(maxC, c);
}
int R = min(d0[u]-maxB, dia-maxC);
return R;
}
# | 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... |