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 ll long long
#define pii pair<int, int>
#define f first
#define s second
#ifdef BALBIT
#define bug(...) cerr<<"#"<<__LINE__<<": "<<#__VA_ARGS__<<"- ", _do(__VA_ARGS__)
template<typename T> void _do( T && x) {cerr<<x<<endl;}
template<typename T, typename ...S> void _do( T && x, S && ...y) {cerr<<x<<", "; _do(y...);}
#else
#define bug(...)
#endif // BALBIT
#define ALL(x) (x).begin(), (x).end()
#define SZ(x) (int )((x).size())
#define pb push_back
#define REP(i,n) for (int i = 0; i<n; ++i)
#define REP1(i,n) for (int i = 1; i<=n; ++i)
#define MX(a,b) a = max(a,b)
#define MN(a,b) a = min(a,b)
map<pii, int> mp;
int getd(int a, int b){
if (a==b) return 0;
if (a>b) swap(a,b);
if (!mp.count({a,b})) mp[{a,b}] = getDistance(a,b);
return mp[{a,b}];
}
int hubDistance(int n, int sub) {
mp.clear();
int p1=-1, p2=-1;
vector<int> C(n);
{
int far = 0;
REP(i,n) {
if (i != 0) {
C[i] = getd(0,i);
if (getd(0,i) > far) {
far = getd(0,i);
p1 = i;
}
}
}
}
vector<int> A(n);
vector<int> B(n);
{
int far = 0;
REP(i,n) {
if (i!=p1) {
A[i] = getd(p1, i);
if (getd(p1,i) > far) {
far = getd(p1,i);
p2 = i;
}
}
}
}
assert(p1 != -1 && p2 != -1);
bug(p1, p2);
int dia = A[p2];
int P = (C[p1] + C[p2] - dia) / 2;
int R = max(C[p1], C[p2]) - P;
bug(P);
int L = C[p1] - P;
REP(i,n) {
// B[i] = getd(p2,i);
if (A[i] - C[i] == L-P) {
bug("hI",i); continue;
}
B[i] = C[p2] + C[i] - P - P;
int hi = (dia + abs(A[i] - B[i]));
// int pp = (A[i] + B[i] - dia) / 2;
assert(hi % 2 == 0);
MN(R, hi / 2);
}
bug(dia, R);
return R;
}
Compilation message (stderr)
towns.cpp: In function 'int hubDistance(int, int)':
towns.cpp:40:28: warning: unused parameter 'sub' [-Wunused-parameter]
40 | 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... |