Submission #43803

#TimeUsernameProblemLanguageResultExecution timeMemory
43803wzyCommuter Pass (JOI18_commuter_pass)C++11
100 / 100
599 ms146920 KiB
#include <bits/stdc++.h> using namespace std; #define pii pair<long long,long long> #define pb push_back #define ppi pair<pii , pii> #define piii pair<long long,ppi > #define F first #define S second long long f1[100005] , f2[100005] , f3[100005] ; int n , m ; vector<pii> adj[100005]; int s, t , u , v; int main(){ cin>>n>>m; cin>>s>>t>>u>>v; for(int i = 0 ; i < m ; i ++){ int x , y , z; cin>>x>>y>>z; adj[x].pb(pii(z,y)); adj[y].pb(pii(z,x)); } for(int i = 1 ; i <= n; i++){ f1[i] = (long long) 1e18 , f2[i] = (long long) 1e18 , f3[i] = (long long) 1e18; } priority_queue<pii , vector<pii> , greater<pii> > pq; pq.push(pii(0 , u)); while(!pq.empty()){ pii u = pq.top(); pq.pop(); if(u.F >= f1[u.S]) continue; f1[u.S] = u.F; for(auto p : adj[u.S]){ if(f1[p.S] > p.F + u.F){ pq.push(pii(p.F + u.F , p.S)); } } } pq.push(pii(0 , v)); while(!pq.empty()){ pii u = pq.top(); pq.pop(); if(u.F >= f2[u.S]) continue; f2[u.S] = u.F; for(auto p : adj[u.S]){ if(f2[p.S] > p.F + u.F){ pq.push(pii(p.F + u.F , p.S)); } } } long long ans = f2[u]; priority_queue< piii , vector<piii> , greater<piii> > pqq; pqq.push(piii(0 , ppi(pii(f1[s] + f2[s] , s) , pii(f1[s] , f2[s])))); while(!pqq.empty()){ piii u = pqq.top(); pqq.pop(); if(f3[u.S.F.S] <= u.F) continue; if(u.S.F.S == t){ ans = min(ans , u.S.F.F); break; } f3[u.S.F.S] = u.F; for(auto p : adj[u.S.F.S]){ if(f3[p.S] > u.F + p.F){ pii w = u.S.S; w.F = min(w.F , f1[p.S]) , w.S = min(w.S , f2[p.S]); pqq.push(piii(u.F + p.F , ppi(pii(w.F + w.S, p.S) , w ))); } } } cout<<ans<<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...