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) {
int p1=0, p2=0;
{
int far = 0;
REP(i,n) {
if (i != 0) {
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;
}
}
}
}
bug(p1, p2);
ll R = 2000000000;
ll dia = A[p2];
REP(i,n) {
B[i] = getd(p2,i);
MN(R, (dia + abs(A[i] - B[i])) / 2);
}
bug(dia, R);
return R;
}
Compilation message (stderr)
towns.cpp: In function 'int hubDistance(int, int)':
towns.cpp:74:9: warning: conversion from 'long long int' to 'int' may change value [-Wconversion]
74 | return R;
| ^
towns.cpp:38:28: warning: unused parameter 'sub' [-Wunused-parameter]
38 | 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... |