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 <bits/stdc++.h>
using namespace std;
#include "towns.h"
const int N = 110;
int dist_0[N], dist_u[N], x[N], y[N], color[N];
int hubDistance(int n, int subtask) {
for (int i = 1; i < n; ++i) {
dist_0[i] = getDistance(0, i);
}
map<int, vector<int>> groups;
int u = max_element(dist_0, dist_0 + n) - dist_0;
dist_u[0] = dist_0[u];
for (int i = 1; i < n; ++i) {
if (i != u) {
dist_u[i] = getDistance(u, i);
x[i] = (dist_u[i] - dist_0[i] + dist_0[u]) / 2;
groups[x[i]].push_back(i);
y[i] = dist_u[i] - x[i];
}
}
int ans = INT_MAX;
int diameter = *max_element(dist_u, dist_u + n);
for (auto &[dist, nodes] : groups) {
ans = min(ans, max(dist, diameter - dist));
}
int left = 1, right = n - 1;
for (auto &[dist, nodes] : groups) {
right -= nodes.size();
if (max(dist, diameter - dist) == ans) {
if (left <= n / 2 && right <= n / 2) {
int i = -1, balance = 0;
for (auto j : nodes) {
if (balance == 0) {
i = j;
}
if (i == j || getDistance(i, j) < y[i] + y[j]) {
color[j] = i, ++balance;
} else {
color[j] = j, --balance;
}
}
int k = -1, size = 0;
for (auto j : nodes) {
if (color[j] == j && getDistance(i, j) < y[i] + y[j]) {
k = j;
}
size += color[j] == k;
}
return size <= n / 2 ? ans : -ans;
}
}
left += nodes.size();
}
return -ans;
}
Compilation message (stderr)
towns.cpp: In function 'int hubDistance(int, int)':
towns.cpp:16:45: warning: conversion from 'long int' to 'int' may change value [-Wconversion]
16 | int u = max_element(dist_0, dist_0 + n) - dist_0;
| ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^~~~~~~~
towns.cpp:35:29: warning: conversion from 'std::vector<int>::size_type' {aka 'long unsigned int'} to 'int' may change value [-Wconversion]
35 | right -= nodes.size();
| ^
towns.cpp:61:28: warning: conversion from 'std::vector<int>::size_type' {aka 'long unsigned int'} to 'int' may change value [-Wconversion]
61 | left += nodes.size();
| ^
towns.cpp:10:28: warning: unused parameter 'subtask' [-Wunused-parameter]
10 | int hubDistance(int n, int subtask) {
| ~~~~^~~~~~~
# | 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... |