Submission #48436

#TimeUsernameProblemLanguageResultExecution timeMemory
48436aleksamiCommuter Pass (JOI18_commuter_pass)C++14
100 / 100
548 ms75916 KiB
#include <bits/stdc++.h> using namespace std; typedef long long ll; #define MAXN 100005 #define INF 1000000000000000 typedef pair<ll,ll> pii; vector <pii> g[MAXN]; bool gotov[MAXN]; priority_queue <pii> pq; int n,m; void dijkstra(ll *d,int source) { for(int i = 0; i < MAXN; i++)d[i]=INF,gotov[i]=false; d[source]=0; pq.push({-d[source],source}); while(!pq.empty()) { int v = pq.top().second; pq.pop(); if(gotov[v])continue; gotov[v]=1; for(auto x:g[v]) { int u = x.first; int c = x.second; if(d[u]>d[v]+c)d[u]=d[v]+c,pq.push({-d[u],u}); } } } ll ds[MAXN]; ll dt[MAXN]; ll du[MAXN]; ll dv[MAXN]; ll d1[MAXN]; ll d2[MAXN]; int s,t; void dijkstraa(ll *d,ll *dd) { for(int i = 0; i < MAXN; i++)gotov[i]=false,dd[i]=d[i],pq.push({-dd[i],i}); while(!pq.empty()) { int v = pq.top().second; pq.pop(); if(gotov[v])continue; gotov[v]=1; for(auto x:g[v]) { int u = x.first; int c = x.second; if( ds[u]+c+dt[v]==ds[t] && dd[u]>dd[v])dd[u]=dd[v],pq.push({-dd[u],u}); } } } int main() { ios_base::sync_with_stdio(false); int u,v; cin >> n >> m >> s >> t >> u >> v; for(int i = 0; i < m; i++) { int x,y,c; cin >> x >> y >> c; g[x].push_back({y,c}); g[y].push_back({x,c}); } dijkstra(ds,s); dijkstra(dt,t); dijkstra(du,u); dijkstra(dv,v); dijkstraa(dv,d1); dijkstraa(du,d2); ll ans = INF; for(int i = 1; i <= n; i++) { ans=min(ans,du[i]+d1[i]); ans=min(ans,dv[i]+d2[i]); } cout << ans; 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...