제출 #41162

#제출 시각아이디문제언어결과실행 시간메모리
41162ngkan146Commuter Pass (JOI18_commuter_pass)C++11
15 / 100
2043 ms67704 KiB
#include <bits/stdc++.h> #define ll long long using namespace std; struct edge{ int v, w; edge(int v=0,int w=0): v(v), w(w) {} }; int n,m,s,t,u,v; vector <edge> G[100005]; vector <int> dag[100005]; ll dis[100005], disS[100005], disU[100005], disV[100005]; bool visited[100005]; priority_queue <pair<long long,int>, vector<pair<long long,int> >, greater<pair<long long, int> > > pq; void dijkstra(int root){ fill(dis+1,dis+n+1, (ll) 1e18); fill(visited,visited+n+1,0); dis[root] = 0; pq.push(pair<ll,int>(0, root)); while(pq.size()){ int u = pq.top().second; pq.pop(); if (visited[u]) continue; visited[u] = 1; for(auto v: G[u]){ if (dis[v.v] > dis[u] + v.w) dis[v.v] = dis[u] + v.w, pq.push(pair<ll,int>(dis[v.v], v.v)); } } } void trailBack(int u){ for(auto v: G[u]){ if (disS[v.v] == disS[u] - v.w) dag[v.v].push_back(u), trailBack(v.v); } } ll ans = (ll) 1e18; ll dfs(int u){ ll mini = (ll) disV[u]; for(int v: dag[u]){ mini = min(mini, dfs(v)); } ans = min(ans, disU[u] + mini); return mini; } int main(){ iostream::sync_with_stdio(0); cin >> n >> m >> s >> t >> u >> v; for(int i=1;i<=m;i++){ int a,b,c; cin >> a >> b >> c; G[a].push_back(edge(b, c)); G[b].push_back(edge(a, c)); } dijkstra(s); for(int i=1;i<=n;i++) disS[i] = dis[i]; trailBack(t); dijkstra(u); for(int i=1;i<=n;i++) disU[i] = dis[i]; ans = disU[v]; dijkstra(v); for(int i=1;i<=n;i++) disV[i] = dis[i]; dfs(s); swap(disU, disV); dfs(s); cout << ans; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...