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>
using namespace std;
#define pb push_back
#define int long long
const int N=1e5+50;
const int inf=1e18;
vector<pair<int,int> >E[N];
signed main()
{
int n,m;cin>>n>>m;
int A,B;cin>>A>>B;
int U,V;cin>>U>>V;
int edges[n+1][n+1];
memset(edges,-1,sizeof(edges));
int dp[n+1][n+1];
for(int i=1;i<=n;i++) for(int j=1;j<=n;j++) dp[i][j]=inf;
for(int i=1;i<=m;i++)
{
int u,v,w;cin>>u>>v>>w;
E[u].pb({v,w});
E[v].pb({u,w});
edges[u][v]=w;
edges[v][u]=w;
dp[u][v]=dp[v][u]=w;
}
for(int i=1;i<=n;i++)
{
dp[i][i]=0;
for(int j=1;j<i;j++)
{
for(int k=1;k<i;k++)
{
if(edges[i][k]==-1) continue;
dp[i][j]=min(dp[i][j],edges[i][k]+dp[k][j]);
}
dp[j][i]=dp[i][j];
}
}
//for(int i=1;i<=n;i++) for(int j=1;j<=n;j++) cout<<i<<" "<<j<<": "<<dp[i][j]<<endl;
int res=dp[U][V];
for(int i=1;i<=n;i++)
{
for(int j=1;j<=n;j++)
{
//if(dp[A][i]+dp[i][j]+dp[j][B]==dp[A][B] && (dp[U][i]+dp[i][j]+dp[j][V]==dp[U][V] || dp[V][i]+dp[i][j]+dp[j][U]==dp[U][V]))
if(dp[A][i]+dp[i][j]+dp[j][B]==dp[A][B])
{
res=min(res,min(dp[U][i]+dp[j][V],dp[V][i]+dp[U][j]));
//cout<<i<<" "<<j<<endl;
}
//if(dp[A][i]+dp[i][j]+dp[j][B]==dp[A][B] && dp[V][i]+dp[i][j]+dp[j][U]==dp[U][V]) res=max(res,dp[i][j]);
//if(dp[B][i]+dp[i][j]+dp[j][A]==dp[A][B] && dp[U][i]+dp[i][j]+dp[j][V]==dp[U][V]) res=max(res,dp[i][j]);
//if(dp[B][i]+dp[i][j]+dp[j][A]==dp[A][B] && dp[V][i]+dp[i][j]+dp[j][U]==dp[U][V]) res=max(res,dp[i][j]);
}
}
//res=dp[U][V]-res;
cout<<res<<endl;
return 0;
}
# | 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... |