# | TimeUTC-0 | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
119520 | PeppaPig | Towns (IOI15_towns) | C++14 | 25 ms | 664 KiB |
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;
const int N = 205;
int hubDistance(int n, int sub) {
vector<vector<int> > d(N, vector<int>(N, 0));
auto get_dist = [&](int a, int b) {
if(a == b) return 0;
else if(d[a][b]) return d[a][b];
else return d[a][b] = d[b][a] = getDistance(a, b);
};
int a, b;
for(int i = 0, mx = -1; i < n; i++) if(get_dist(0, i) > mx) a = i, mx = get_dist(0, i);
for(int i = 0, mx = -1; i < n; i++) if(get_dist(a, i) > mx) b = i, mx = get_dist(a, i);
int root1 = -1, root2 = -1, ans = INT_MAX;
for(int i = 0; i < n; i++) {
int pos = (get_dist(a, i) + get_dist(a, 0) - get_dist(i, 0)) / 2;
int now = max(pos, get_dist(a, b) - pos);
if(now <= ans) {
if(now < ans) root1 = pos, root2 = -1;
else {
if(root1 == -1) root1 = pos;
else if(pos != root1) root2 = pos;
}
ans = now;
Compilation message (stderr)
# | 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... |