Submission #1130414

#TimeUsernameProblemLanguageResultExecution timeMemory
1130414akzytrCommuter Pass (JOI18_commuter_pass)C++20
16 / 100
521 ms25872 KiB
#include <bits/stdc++.h>
#define ve vector
#define ar array 
#define pb push_back
#define ins insert

#define endl '\n'
#define ll long long
using namespace std;

int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);

    int N, M;
    cin >> N >> M;

    int S, T;
    cin >> S >> T;

    int U, V;
    cin >> U >> V;

    ve<pair<int, ll>> adj[N+1];
    for(int i = 0; i < M; i++){
        int a, b, c;
        cin >> a >> b >> c;
        adj[a].pb({b, c});
        adj[b].pb({a, c});
    }

    set<ar<ll, 3>> pq;
    ve<ll> distv(N+1, 1e18);

    // ve<ll> distu(N+1, 1e18);
    // pq.insert({0, -1, U});

    // while(!pq.empty()){
    //     auto [cst, _, sor] = *pq.begin();
    //     pq.erase(pq.begin());

    //     if(cst < distu[sor]){
    //         distu[sor] = cst;
    //         for(auto [x, c] : adj[sor]){
    //             pq.insert({cst + c, _, x});
    //         }
    //     }
    // }

    pq.insert({0, -1, V});
    while(!pq.empty()){
        auto [cst, _, sor] = *pq.begin();
        pq.erase(pq.begin());

        if(cst < distv[sor]){
            distv[sor] = cst;
            for(auto [x, c] : adj[sor]){
                pq.insert({cst + c, _, x});
            }
        }
    }


    ve<ll> dists(N+1, 1e18);
    ve<ll> ans(N+1, distv[S]+1);
    pq.insert({0, distv[S], S});
    while(!pq.empty()){
        auto [cst, rel, sor] = *pq.begin();
        pq.erase(pq.begin());

        if(cst <= dists[sor] && rel < ans[sor]){
            dists[sor] = cst;
            ans[sor] = rel;
            for(auto [x, c] : adj[sor]){
                ll n_rel = min(rel, distv[x]);
                pq.insert({cst + c, n_rel, x});
            }
        }
    }
    cout << ans[T] << endl;
    
}
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...