This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
// clangformat off
#include "towns.h"
#include <bits/stdc++.h>
template <typename T> bool setmax(T &v, const T a) {
if (v < a) {
v = a;
return true;
} else {
return false;
}
}
template <typename T> bool setmin(T &v, const T a) {
if (v > a) {
v = a;
return true;
} else {
return false;
}
}
constexpr int max_d = 1000010;
int hubDistance(int N, int sub) {
if (sub == 1 or sub == 2) {
std::vector<int> dist;
auto find_maxdist = [&](const int v, std::vector<int> &d) {
int max = 0, pos = 0;
for (int i = 0; i < N; ++i) {
d[i] = getDistance(v, i);
if (setmax(max, d[i])) {
pos = i;
}
}
return std::make_pair(pos, max);
};
std::vector<int> memo(N);
const auto [p1, v1] = find_maxdist(0, memo);
const auto [p2, diameter] = find_maxdist(p1, memo);
int res = max_d;
for (int i = 0; i < N; ++i) {
if (i == p1 or i == p2) continue;
const int d1 = memo[i], d2 = getDistance(p2, i);
const int r = ((d1 + d2) - diameter) / 2;
setmin(res, std::max(d1 - r, d2 - r));
}
return res;
} else {
return 0;
}
}
# | 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... |