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;
const long long oo=1e18;
const int N=500;
long long c[N][N];
int n,m,a,b,s,t;
int main()
{
//freopen("i.inp","r",stdin);
cin>>n>>m>>a>>b>>s>>t;
for(int i=1;i<=n;i++)
for(int j=1;j<=n;j++)
if(i!=j) c[i][j]=oo;
for(int i=1;i<=m;i++)
{
long long u,v,w;
cin>>u>>v>>w;
c[u][v]=c[v][u]=min(c[u][v],w);
}
for(int k=1;k<=n;k++)
for(int u=1;u<=n;u++)
for(int v=1;v<=n;v++)
if(c[u][k] && c[k][v]) c[u][v]=min(c[u][v],c[u][k]+c[k][v]);
long long ans=c[s][t];
for(int x=1;x<=n;x++)
for(int y=1;y<=n;y++)
if(c[a][x] + c[x][y]+ c[y][b] ==c[a][b]) ans=min(ans,c[x][s]+c[y][t]);
swap(a,b);
for(int x=1;x<=n;x++)
for(int y=1;y<=n;y++)
if(c[a][x] + c[x][y]+ c[y][b] ==c[a][b]) ans=min(ans,c[x][s]+c[y][t]);
cout<<ans;
}
# | 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... |