This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
// In the name of Allah
#include <bits/stdc++.h>
#include "towns.h"
using namespace std;
typedef long long int ll;
typedef long double ld;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef complex<ld> cld;
#define all(x) (x).begin(),(x).end()
#define len(x) ((ll) (x).size())
#define F first
#define S second
#define pb push_back
#define sep ' '
#define endl '\n'
#define Mp make_pair
#define kill(x) cout << x << '\n', exit(0)
#define set_dec(x) cout << fixed << setprecision(x);
#define file_io(x,y) freopen(x, "r", stdin); freopen(y, "w", stdout);
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
int n;
const int maxn = 110 + 4;
ll dis[maxn][maxn], R, ans;
int p[maxn], sz[maxn];
int get(int a) {
return (p[a] == a) ? a : p[a] = get(p[a]);
}
void merge(int a, int b) {
a = get(a); b = get(b);
if (a == b) return ;
if (sz[a] > sz[b]) swap(a, b);
p[a] = b; sz[b] += sz[a]; sz[a] = 0;
}
ll get_dis(int u, int v) {
if (dis[u][v] == -1) {
dis[u][v] = dis[v][u] = getDistance(u, v);
}
return dis[u][v];
}
int hubDistance(int N, int sub) {
n = N;
iota(p, p + n, 0); fill(sz, sz + n, 1);
for (int i = 0; i < n; i++) {
for (int j = 0; j < n; j++) {
if (i == j) dis[i][j] = 0;
else dis[i][j] = -1;
}
}
int v1 = 0, u1 = v1;
for (int i = 0; i < n; i++) {
if (get_dis(v1, i) > get_dis(v1, u1)) u1 = i;
}
int v2 = u1, u2 = v2;
for (int i = 0; i < n; i++) {
if (get_dis(v2, i) > get_dis(v2, u2)) u2 = i;
}
ll dx = get_dis(v1, v2);
ll D = get_dis(u1, u2); R = D;
for (int i = 0; i < n; i++) {
ll d1 = get_dis(v1, i), d2 = get_dis(v2, i);
ll x = (d1 + d2 - dx) / 2;
R = min(R, max(d1 - x, D - (d1 - x)));
R = min(R, max(d2 - x, D - (d2 - x)));
}
ans = R;
return ans;
}
Compilation message (stderr)
towns.cpp: In function 'int hubDistance(int, int)':
towns.cpp:80:9: warning: conversion from 'll' {aka 'long long int'} to 'int' may change value [-Wconversion]
80 | return ans;
| ^~~
towns.cpp:49:28: warning: unused parameter 'sub' [-Wunused-parameter]
49 | 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... |