#include "towns.h"
#include <bits/stdc++.h>
using namespace std;
int hubDistance(int N, int sub) {
pair<int, int > best = make_pair(-1,-1);
//first is dist, second is ind
for(int i = 1; i<N; i++){
pair<int, int> now = make_pair(getDistance(0,i),i);
best = max(best,now);
}
int first = best.second;
best = make_pair(-1,-1);
int A[N];
int B[N];
for(int i = 0; i<N; i++){
if(i==first){
continue;
}
pair<int, int> now = make_pair(getDistance(first,i),i);
A[i] = now.first;
best = max(best,now);
}
int second = best.second;
int diameter = getDistance(first,second);
int inf = 100000000;
int ans = inf;
for(int i = 0; i<N; i++){
if(i==first || i==second){
continue;
}
B[i] = getDistance(i,second);
int x = (A[i]+B[i]-diameter)/2;
int a = A[i]-x;
int b = B[i]-x;
ans = min(ans,max(a,b));
}
return ans;
}
Compilation message
towns.cpp: In function 'int hubDistance(int, int)':
towns.cpp:4:28: warning: unused parameter 'sub' [-Wunused-parameter]
int hubDistance(int N, int sub) {
^~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
20 ms |
376 KB |
Output is correct |
2 |
Correct |
28 ms |
464 KB |
Output is correct |
3 |
Correct |
2 ms |
564 KB |
Output is correct |
4 |
Correct |
24 ms |
612 KB |
Output is correct |
5 |
Correct |
22 ms |
612 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
20 ms |
612 KB |
Output is correct |
2 |
Correct |
17 ms |
612 KB |
Output is correct |
3 |
Correct |
20 ms |
612 KB |
Output is correct |
4 |
Correct |
21 ms |
612 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
16 ms |
612 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
20 ms |
612 KB |
Output isn't correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
17 ms |
644 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
19 ms |
644 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |