Submission #1323820

#TimeUsernameProblemLanguageResultExecution timeMemory
1323820reyleighCommuter Pass (JOI18_commuter_pass)C++17
0 / 100
223 ms15944 KiB
#include<bits/stdc++.h>
using namespace std;

const int MAX = INT_MAX;
const int N = 1e5 + 1;
vector<pair<int,int>>graph[N];
int n,m,s,t,u,v;
bool vis[N];
int store[N] = {MAX};
map<pair<int, int>, bool> mp;

void dijkstra(int source){
    priority_queue<pair<int,int>, vector<pair<int,int>>, greater<pair<int,int>>> pq;
    pq.push({0,source});
    for(int i=0; i<N; i++){
        store[i] = MAX;
    }
    store[source] = 0;
    vector<int>path(n+1);

    while(!pq.empty()){
        auto top = pq.top();
        pq.pop();
        vis[top.second] = true;

        for(auto i: graph[top.second]){
            if(!vis[i.first]){
                if(store[i.first] == MAX){
                    pq.push({top.first + i.second, i.first});
                    path[i.first] = top.second;
                }
                if(store[i.first] > top.first + i.second){
                    store[i.first] = top.first + i.second;
                    path[i.first] = top.second;
                }
            }
        }
    }

    path[source] = -1;
    int i = t;
    while(path[i] != -1){
        mp[{i, path[i]}] = 1;
        mp[{path[i], i}] = 1;
        i = path[i];
    }

}


int main () {
    cin>>n>>m>>s>>t>>u>>v;
    for(int i = 0; i < m; i++){
        int a,b,c;
        cin>>a>>b>>c;
        graph[a].push_back({b,c});
        graph[b].push_back({a,c});
    }

    dijkstra(s);
    for(int i=1; i <= n; i++){
        store[i]=0;
        vis[i]= 0;

    }

    priority_queue<pair<int,int>, vector<pair<int,int>>, greater<pair<int,int>>> pq;
    pq.push({0,u});
    for(int i=0; i<N; i++){
        store[i] = MAX;
    }
    store[u] = 0;

    while(!pq.empty()){
        auto top = pq.top();
        pq.pop();
        for(auto i: graph[top.second]){
            if(store[i.first] == MAX){
                pq.push({(mp[{top.second, i.first}] ? 0 : top.first + i.second), i.first});
            }
            if(store[i.first] > top.first + i.second){
                store[i.first] = top.first + i.second;
            }
        }
    }
    cout<<store[v]<<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...