제출 #1332187

#제출 시각아이디문제언어결과실행 시간메모리
1332187AndreyCommuter Pass (JOI18_commuter_pass)C++20
100 / 100
443 ms24940 KiB
#include<bits/stdc++.h>
using namespace std;

vector<pair<long long,long long>> haha[100001];
long long n;

void dek(vector<long long>&ans, long long s) {
    ans[s] = 0;
    priority_queue<pair<long long,long long>> idk;
    idk.push({0,s});
    while(!idk.empty()) {
        long long x = -idk.top().first,u = idk.top().second;
        idk.pop();
        if(x > ans[u]) {
            continue;
        }
        for(pair<long long,long long> v: haha[u]) {
            long long w = x+v.second;
            if(w < ans[v.first]) {
                ans[v.first] = w;
                idk.push({-w,v.first});
            }
        }
    }
}

long long calc(vector<long long> d1, vector<long long> d2, long long s, long long t, long long cu, long long cv) {
    vector<long long> banana(n+1,LLONG_MAX);
    dek(banana,t);
    vector<pair<long long,long long>> ans(n+1,{LLONG_MAX,0});
    ans[s] = {0,d1[s]};
    priority_queue<pair<pair<long long,long long>,long long>> idk;
    idk.push({{0,d1[s]},s});
    while(!idk.empty()) {
        pair<long long,long long> x = idk.top().first;
        x = {-x.first,x.second};
        long long u = idk.top().second;
        idk.pop();
        if(x > ans[u]) {
            continue;
        }
        for(pair<long long,long long> v: haha[u]) {
            long long w = x.first+v.second;
            long long y = min(x.second,d1[v.first]);
            if(w < ans[v.first].first || (w == ans[v.first].first && y < ans[v.first].second)) {
                ans[v.first] = {w,y};
                idk.push({{-w,y},v.first});
            }
        }
    }
    long long sm = d1[cv];
    for(long long i = 1; i <= n; i++) {
        if(banana[i]+ans[i].first == ans[t].first) {
            sm = min(sm,ans[i].second+d2[i]);
        }
    }
    return sm;
}

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    long long m,a,b,c;
    cin >> n >> m;
    long long s,t,cu,cv;
    cin >> s >> t >> cu >> cv;
    for(long long i = 0; i < m; i++) {
        cin >> a >> b >> c;
        haha[a].push_back({b,c});
        haha[b].push_back({a,c});
    }
    vector<long long> d1(n+1,LLONG_MAX);
    vector<long long> d2(n+1,LLONG_MAX);
    dek(d1,cu);
    dek(d2,cv);
    cout << min(calc(d1,d2,s,t,cu,cv),calc(d1,d2,t,s,cu,cv));
    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...