#include "towns.h"
#include <bits/stdc++.h>
using namespace std;
int dist[111][111],C[111];
int d(int u, int v){
if (u==v)
return 0;
if (u>v)
swap(u,v);
if (dist[u][v])
return dist[u][v];
return dist[u][v]=getDistance(u,v);
}
int hubDistance(int N, int sub){
memset(dist,0,sizeof(dist));
pair <int, int> mx={0,-1};
for (int i=0;i<N;i++)
mx=max(mx,{d(0,i),i});
int u=mx.second;
mx={0,-1};
for (int i=0;i<N;i++)
mx=max(mx,{d(u,i),i});
int v=mx.second;
int R=1e9,cnt[2]={0,0};
for (int i=0;i<N;i++)
R=min(R,abs(d(i,u)-d(i,v)));
R=(R+d(u,v))/2;
vector <int> a,b,tmp;
for (int i=0;i<N;i++){
int val=d(i,u)-d(i,v);
if (val<-R)
cnt[0]++;
if (val==-R)
a.push_back(i);
if (val==R)
b.push_back(i);
if (val>R)
cnt[1]++;
}
if (max(cnt[0],cnt[1])>N/2||a.size()>N/2||b.size()>N/2)
return -R;
return R;
}
Compilation message
towns.cpp: In function 'int hubDistance(int, int)':
towns.cpp:40:41: warning: comparison of integer expressions of different signedness: 'std::vector<int>::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
40 | if (max(cnt[0],cnt[1])>N/2||a.size()>N/2||b.size()>N/2)
| ~~~~~~~~^~~~
towns.cpp:40:55: warning: comparison of integer expressions of different signedness: 'std::vector<int>::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
40 | if (max(cnt[0],cnt[1])>N/2||a.size()>N/2||b.size()>N/2)
| ~~~~~~~~^~~~
towns.cpp:40:5: warning: this 'if' clause does not guard... [-Wmisleading-indentation]
40 | if (max(cnt[0],cnt[1])>N/2||a.size()>N/2||b.size()>N/2)
| ^~
towns.cpp:42:5: note: ...this statement, but the latter is misleadingly indented as if it were guarded by the 'if'
42 | return R;
| ^~~~~~
towns.cpp:14:28: warning: unused parameter 'sub' [-Wunused-parameter]
14 | int hubDistance(int N, int sub){
| ~~~~^~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
10 ms |
344 KB |
Output is correct |
2 |
Correct |
9 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
11 ms |
348 KB |
Output is correct |
5 |
Correct |
12 ms |
528 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
10 ms |
344 KB |
Output is correct |
2 |
Correct |
11 ms |
348 KB |
Output is correct |
3 |
Correct |
12 ms |
348 KB |
Output is correct |
4 |
Correct |
12 ms |
528 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
8 ms |
348 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
11 ms |
344 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
10 ms |
348 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
9 ms |
348 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |