제출 #1167714

#제출 시각아이디문제언어결과실행 시간메모리
1167714madtCommuter Pass (JOI18_commuter_pass)C++20
24 / 100
351 ms327680 KiB
#include <bits/stdc++.h>

using namespace std;

long long gr[10000][10000];

int main()
{
    int n=0, m=0;
    int s=0, t=0;
    int u=0, v=0;
    cin>>n>>m>>s>>t>>u>>v;
    for(int i=1; i<=n; i++)
    {
        for(int j=1; j<=n; j++)
        {
            gr[i][j]=LLONG_MAX;
            if(i==j)
                gr[i][j]=0;
        }
    }
    for(int i=0; i<m; i++)
    {
        int a=0, b=0;
        long long c=0;
        cin>>a>>b>>c;
        gr[a][b]=c;
        gr[b][a]=c;
    }


    for(int i=1; i <= n; i++)
    {
        for(int j=1; j<=n; j++)
        {
            for(int p=1; p<=n; p++)
            {
                if(gr[j][i]!=LLONG_MAX && gr[p][i]!= LLONG_MAX)
                {
                    gr[j][p]=min(gr[p][j], gr[i][p] + gr[i][j]);
                    gr[p][j]=gr[j][p];
                    //cout<<j<<"-->"<<p<<" "<<gr[j][p]<<endl;
                }
            }
        }
    }
    //cout<<gr[u][v]<<' '<<gr[s][t]<<endl;
    long long mn=gr[u][v];
    for(int i=1; i<=n; i++)
        for(int j=1; j<=n; j++)
            if(gr[s][t]==(gr[s][i]+gr[i][j]+gr[j][t]) || gr[s][t]==(gr[s][j]+gr[i][j]+gr[i][t]))
            {
                mn=min(mn, min(gr[u][i] + gr[v][j], gr[u][j] + gr[v][i]));
            }

    cout<<mn<<endl;
    return 0;
}
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...