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>
#define Loop(x,l,r) for (ll x = (l); x < (r); ++x)
#define LoopR(x,l,r) for (ll x = (r)-1; x >= (l); --x)
typedef std::pair<int,int> pii;
typedef long long ll;
using namespace std;
const int N = 120;
int dis0[N], disa[N], disb[N];
int dis[N][N];
int get(int i, int j)
{
if (i == j)
return 0;
if (i > j)
swap(i, j);
if (!dis[i][j])
dis[i][j] = getDistance(i, j);
return dis[i][j];
}
int hubDistance(int n, int sub) {
memset(dis, 0, sizeof(dis));
Loop (i,0,n)
dis0[i] = get(0, i);
int a = max_element(dis0, dis0+n) - dis0;
Loop (i,0,n)
disa[i] = get(a, i);
int b = max_element(disa, disa+n) - disa;
Loop (i,0,n)
disb[i] = get(b, i);
int ans = 1e9;
Loop (i,0,n) {
int x = (disa[i] + disa[b] - disb[i])/2;
int y = (disb[i] + disb[a] - disa[i])/2;
ans = min(ans, max(x, y));
}
return ans;
}
Compilation message (stderr)
towns.cpp: In function 'int hubDistance(int, int)':
towns.cpp:28:20: warning: conversion from 'll' {aka 'long long int'} to 'int' may change value [-Wconversion]
28 | dis0[i] = get(0, i);
| ^
towns.cpp:29:36: warning: conversion from 'long int' to 'int' may change value [-Wconversion]
29 | int a = max_element(dis0, dis0+n) - dis0;
| ~~~~~~~~~~~~~~~~~~~~~~~~~~^~~~~~
towns.cpp:31:20: warning: conversion from 'll' {aka 'long long int'} to 'int' may change value [-Wconversion]
31 | disa[i] = get(a, i);
| ^
towns.cpp:32:36: warning: conversion from 'long int' to 'int' may change value [-Wconversion]
32 | int b = max_element(disa, disa+n) - disa;
| ~~~~~~~~~~~~~~~~~~~~~~~~~~^~~~~~
towns.cpp:34:20: warning: conversion from 'll' {aka 'long long int'} to 'int' may change value [-Wconversion]
34 | disb[i] = get(b, i);
| ^
towns.cpp:25:28: warning: unused parameter 'sub' [-Wunused-parameter]
25 | 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... |