Submission #1167693

#TimeUsernameProblemLanguageResultExecution timeMemory
1167693kitijakCommuter Pass (JOI18_commuter_pass)C++20
24 / 100
25 ms1344 KiB
#include <bits/stdc++.h>
#pragma GCC optimize("O3,unroll-loops")
#pragma GCC target("avx2,bmi,bmi2,popcnt,lzcnt")
#define pii pair<long long, long long>
#define fi first
#define se second
#define pb push_back
#define ll long long
using namespace std;
    ll n, m, s, t, u, v, a, b, c, d[305][305];
int main()
{
    ios_base::sync_with_stdio(0); cin.tie(0);
    cin >> n >> m  >> s >> t >> u >> v;
    for(int i=1; i<=n; i++){
        for(int j=1; j<=n; j++){
            if(i==j)
                d[i][j]=0;
            else{
                d[i][j]=LLONG_MAX;
                d[j][i]=LLONG_MAX;
            }
        }
    }
    for(int i=0; i<m; i++){
        cin >> a >> b >> c;
        d[a][b]=c;
        d[b][a]=c;
    }
    for(int caur=1; caur<=n; caur++){
        for(int no=1; no<=n; no++){
            for(int uz=1; uz<=n; uz++){
                if(d[no][caur]!=LLONG_MAX && d[caur][uz]!=LLONG_MAX)
                    d[no][uz]=min(d[no][caur]+d[caur][uz], d[no][uz]);
            }
        }
    }
    ll ans=d[u][v];
    for(int i=1; i<=n; i++){
        for(int j=1; j<=n; j++){
            if(d[s][i]+d[i][j]+d[j][t]==d[s][t])
                ans=min({ans, d[u][i]+d[v][j], d[u][j]+d[v][i]});
        }
    }
    cout << max((long long)0, ans) << '\n';
    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...