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 <vector>
#include <iostream>
using namespace std;
const int MAX_DIST = 1e6+5;
vector< vector<int> > mat;
int get_dist(int a, int b) {
if (mat[a][b] == -1)
return mat[a][b] = mat[b][a] = getDistance(a, b);
else
return mat[a][b];
}
int hubDistance(int N, int sub) {
mat.assign(N, vector<int>(N, -1));
int u = -1;
int mx = -1;
for (int i = 0; i < N; ++i) {
if (get_dist(0, i) > mx) {
u = i;
mx = get_dist(0, i);
}
}
int v = -1;
mx = -1;
for (int i = 0; i < N; ++i) {
if (get_dist(u, i) > mx) {
v = i;
mx = get_dist(u, v);
}
}
vector<int> freq(mx+1, 0);
for (int i = 0; i < N; ++i) {
int k = get_dist(i, u);
int l = get_dist(i, v);
++freq[mx-(l-(k+l-mx)/2)];
}
int ans = 0;
for (int i = 0; i < mx; ++i) {
ans = max(ans, max(i, mx-i));
}
return ans;
}
Compilation message (stderr)
towns.cpp: In function 'int hubDistance(int, int)':
towns.cpp:18:28: warning: unused parameter 'sub' [-Wunused-parameter]
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... |