제출 #1115632

#제출 시각아이디문제언어결과실행 시간메모리
1115632staszic_ojuzCommuter Pass (JOI18_commuter_pass)C++17
15 / 100
159 ms23092 KiB
#include <bits/stdc++.h>

using namespace std;

using ll=long long;

const int MAX=1e5+7;

vector<pair<int, ll>> G[MAX];
bool odw[MAX];
int skad[MAX];

void usun(int v, int u){
    int akt=u;
    while (akt!=v){
        //cout << akt << " " << skad[akt] << endl;
        for (int i=0; i<(int)G[akt].size(); i++){
            if (G[akt][i].first == skad[akt]) G[akt][i].second = 0;
        }
        for (int i=0; i<(int)G[skad[akt]].size(); i++){
            if (G[skad[akt]][i].first == akt) G[skad[akt]][i].second = 0;
        }
        akt = skad[akt];
    }
}

ll dijkstra(int v, int u){
    priority_queue<pair<pair<ll, int>, int>> Q;
    Q.push({{0, v}, v});

    for (int i=0; i<MAX; i++) odw[i] = false;

    while (!Q.empty()){
        auto w=Q.top();
        Q.pop();
        //cout << w.first.first << " " << w.first.second << "skibidi " << w.second << endl;
        if (odw[w.first.second]) continue;
        odw[w.first.second] = true;
        skad[w.first.second] = w.second;

        if (w.first.second==u){
            usun(v, u);
            return -w.first.first;
        }

        for (auto k:G[w.first.second]){
            if (odw[k.first]) continue;
            Q.push({{w.first.first-k.second, k.first}, w.first.second});
        }
    }

    return -1e15;
}

int main(){
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    
    int n, m, s, t, u, v, a, b;
    cin >> n >> m >> s >> t >> u >> v;

    ll c;

    for (int i=0; i<m; i++){
        cin >> a >> b >> c;
        G[a].push_back({b, c});
        G[b].push_back({a, c});
    }

    dijkstra(s, t);
    cout << dijkstra(u, v) << "\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...