#include "towns.h"
#include <bits/stdc++.h>
#pragma GCC optimize ("O3")
#pragma GCC target ("sse4")
using namespace std;
#define X first
#define Y second
#define pb push_back
typedef pair<int, int> ii;
typedef long long ll;
const int maxn = 120;
int m, n;
int dist0[maxn];
int distu[maxn];
int add[maxn], bran[maxn];
map<int, int> cnt;
int hubDistance(int N, int sub)
{
cnt.clear();
if(sub > 2 && sub != 4) return 0;
n = N;
int best = 0, dat = -1;
for(int i = 1; i< N; i++)
{
dist0[i] = getDistance(0, i);
if(dist0[i]> best)
{
best = dist0[i];
dat = i;
}
}
int U = dat;
best = 0; dat = -1;
for(int i = 0; i< N; i++)
{
if(i == U || i == 0) continue;
distu[i] = getDistance(U, i);
if(distu[i]> best)
{
best = distu[i];
dat = i;
}
}
int diam = best;
int V = dat;
// printf("(%d->%d) %d\n", U, V, dist[V]);
for(int i = 0; i< N; i++)
{
if(i == U || i == 0) continue;
int br = dist0[i]+distu[i]-dist0[U];
br /= 2;
int pos = dist0[i]-br;
add[i] = pos;
bran[i] = br;
cnt[pos]++;
}
if(!V)
{
add[V] = bran[V] = 0;
}
int rad = 1e9;
int cm = 1;
bool good = false;
for(auto kk : cnt)
{
int x = kk.X, y = kk.Y;
// printf("%d: %d\n", x, cnt[x]);
if(x< add[V]) continue;
rad = min(rad, max(x-add[V]+bran[V], dist0[U]-x));
}
return rad;
}
Compilation message
towns.cpp: In function 'int hubDistance(int, int)':
towns.cpp:71:17: warning: unused variable 'y' [-Wunused-variable]
int x = kk.X, y = kk.Y;
^
towns.cpp:49:6: warning: unused variable 'diam' [-Wunused-variable]
int diam = best;
^~~~
towns.cpp:67:6: warning: unused variable 'cm' [-Wunused-variable]
int cm = 1;
^~
towns.cpp:68:7: warning: unused variable 'good' [-Wunused-variable]
bool good = false;
^~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
16 ms |
384 KB |
Output is correct |
2 |
Correct |
13 ms |
384 KB |
Output is correct |
3 |
Correct |
2 ms |
256 KB |
Output is correct |
4 |
Incorrect |
18 ms |
384 KB |
Output isn't correct |
5 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
16 ms |
384 KB |
Output is correct |
2 |
Correct |
14 ms |
452 KB |
Output is correct |
3 |
Incorrect |
18 ms |
384 KB |
Output isn't correct |
4 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
14 ms |
384 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
18 ms |
384 KB |
Output isn't correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
15 ms |
384 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
14 ms |
384 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |