//#define TEST
#ifndef TEST
#include "towns.h"
#endif
#include <bits/stdc++.h>
using namespace std;
const int len = 115;
int dis[2][len];
int hubDistance(int n, int sub){
int mx = 0, u, v;
for (int i = 0; i < n; i++){
if (i == 0) continue;
int temp = getDistance(0, i);
if (temp > mx)
mx = temp, u = i;
}
mx = 0;
for (int i = 0; i < n; i++){
dis[0][i] = getDistance(u, i);
if (dis[0][i] > mx)
mx = dis[0][i], v = i;
}
for (int i = 0; i < n; i++)
dis[1][i] = getDistance(v, i);
int ans = 0;
for (int i = 0; i < n; i++){
int a = dis[0][i], b = dis[1][i], d = dis[0][v], c = (a+b-d)/2;
ans = min(ans, max(a-c, b-c));
}
return ans;
}
#ifdef TEST
int main() {
FILE *f;
f = freopen("towns.in","r",stdin);
assert(f != NULL);
f = freopen("towns.out","w",stdout);
assert(f != NULL);
int ncase, R, N;
int subtask;
int ret;
ret = scanf("%d%d",&subtask,&ncase);
assert(ret == 2);
for (int i = 0; i < ncase; i++) {
ret = scanf("%d",&N);
assert(ret == 1);
_ini_query(N,subtask);
R=hubDistance(N,subtask);
printf("%d\n",R);
}
return 0;
}
#endif // TEST
Compilation message
towns.cpp: In function 'int hubDistance(int, int)':
towns.cpp:12:28: warning: unused parameter 'sub' [-Wunused-parameter]
int hubDistance(int n, int sub){
^~~
towns.cpp:29:32: warning: 'v' may be used uninitialized in this function [-Wmaybe-uninitialized]
dis[1][i] = getDistance(v, i);
~~~~~~~~~~~^~~~~~
towns.cpp:24:32: warning: 'u' may be used uninitialized in this function [-Wmaybe-uninitialized]
dis[0][i] = getDistance(u, i);
~~~~~~~~~~~^~~~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
39 ms |
1020 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
39 ms |
1596 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
31 ms |
2168 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
36 ms |
3128 KB |
Output isn't correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
18 ms |
3492 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
22 ms |
3948 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |