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>
#ifndef SKY
#include<towns.h>
#endif
using namespace std;
#define ll long long
#define fs first
#define sc second
#define N 210
#define pb push_back
#define ii pair<ll,ll>
int dis[N][N],c[N][N];
#ifdef SKY
int getDistance(int i, int j)
{
return dis[i][j];
}
#endif // SKY
int hubDistance(int n, int sub)
{
for(int i=1;i<n;i++)
c[0][i]=c[i][0]=getDistance(0,i);
int S=1;
for(int i=1;i<n;i++)
if(c[0][i]>c[0][S])
S=i;
// da tinh 0
for(int i=1;i<n;i++)
if(i!=S)
c[S][i]=c[i][S]=getDistance(S,i);
int T=0;
for(int i=0;i<n;i++)
if(c[S][i]>c[S][T])
T=i;
//cout<<S<<" "<<T<<endl;
int L=(dis[S][T]+dis[0][S]+dis[0][T])/2-dis[0][T],
R=(dis[S][T]+dis[0][S]+dis[0][T])/2-dis[0][S],
K=(dis[S][T]+dis[0][S]+dis[0][T])/2-dis[S][T];
int res=max(L,R);
// cout<<L<<" "<<R<<" "<<K<<endl;
for(int i=1;i<n;i++)
if(!(dis[S][i]-dis[0][i]>=L-K))
//if(i==0)
{
int length=(dis[S][i]+dis[0][i]+dis[0][S])/2-dis[0][i];
//cout<<length<<endl;
// cout<<i<<" "<<length<<" "<<dis[S][T]-length<<endl;
res=min(res,max(length,dis[S][T]-length));
}
return res;
}
#ifdef SKY
int main()
{
freopen("A.inp","r",stdin);
freopen("A.out","w",stdout);
int n;
int q;
cin>>q;
while(q--)
{
int n,sub;
cin>>sub>>n;
//cout<<n<<endl;
for(int i=0;i<n;i++)
for(int j=0;j<n;j++)
cin>>dis[i][j];
cout<<hubDistance(n, sub)<<endl;
}
return 0;
}
#endif // SKY
Compilation message (stderr)
towns.cpp: In function 'int hubDistance(int, int)':
towns.cpp:26:28: warning: unused parameter 'sub' [-Wunused-parameter]
26 | int hubDistance(int n, int sub)
| ~~~~^~~
# | 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... |