제출 #48434

#제출 시각아이디문제언어결과실행 시간메모리
48434aleksamiCommuter Pass (JOI18_commuter_pass)C++14
0 / 100
487 ms81376 KiB
#include <bits/stdc++.h> using namespace std; #define MAXN 100005 #define INF 1000000000 typedef pair<int,int> pii; vector <pii> g[MAXN]; bool gotov[MAXN]; priority_queue <pii> pq; int n,m; void dijkstra(int *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}); } } } int ds[MAXN]; int dt[MAXN]; int du[MAXN]; int dv[MAXN]; int d1[MAXN]; int d2[MAXN]; int s,t; void dijkstraa(int *d,int *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); int 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...