Submission #1082693

#TimeUsernameProblemLanguageResultExecution timeMemory
1082693lftroqCommuter Pass (JOI18_commuter_pass)C++14
100 / 100
323 ms52168 KiB
#include<bits/stdc++.h> #define endl '\n' #define fi first #define se second using namespace std; typedef long long ll; const int N=1e5+5; const ll INF=1e15; int n,m,s,t,x,y; vector<pair<int,int>> graph[N],g[4*N]; ll d[2][N],d1[4*N]; void dijkstra(int s,int k) { for(int i=1;i<=n;i++) d[k][i]=INF; d[k][s]=0; priority_queue<pair<ll,pair<int,int>>,vector<pair<ll,pair<int,int>>>,greater<pair<ll,pair<int,int>>>> pq; pq.push({d[k][s],{k,s}}); while((int)pq.size()) { ll temp=pq.top().fi; int k=pq.top().se.fi,u=pq.top().se.se; pq.pop(); if(temp!=d[k][u]) continue; for(int i=0;i<(int)graph[u].size();i++) { int v=graph[u][i].fi,w=graph[u][i].se; if(d[k][v]>d[k][u]+w) { d[k][v]=d[k][u]+w; pq.push({d[k][v],{k,v}}); } } } } void solve() { cin >> n >> m >> s >> t >> x >> y; for(int i=1;i<=m;i++) { int u,v,w; cin >> u >> v >> w; graph[u].push_back({v,w}); graph[v].push_back({u,w}); } dijkstra(s,0);dijkstra(t,1); for(int u=1;u<=n;u++) { g[u].push_back({n+u,0}); g[u].push_back({2*n+u,0}); g[n+u].push_back({3*n+u,0}); g[2*n+u].push_back({3*n+u,0}); for(int i=0;i<(int)graph[u].size();i++) { int v=graph[u][i].fi,w=graph[u][i].se; if(d[0][u]+w+d[1][v]==d[0][t]) { g[n+u].push_back({n+v,0}); g[2*n+v].push_back({2*n+u,0}); } g[u].push_back({v,w});g[3*n+u].push_back({3*n+v,w}); } } priority_queue<pair<ll,int>,vector<pair<ll,int>>,greater<pair<ll,int>>> pq; for(int i=1;i<=4*n;i++) d1[i]=INF; d1[x]=0; pq.push({d1[x],x}); while((int)pq.size()) { ll temp=pq.top().fi; int u=pq.top().se; pq.pop(); if(temp!=d1[u]) continue; for(int i=0;i<(int)g[u].size();i++) { int v=g[u][i].fi,w=g[u][i].se; if(d1[v]>d1[u]+w) { d1[v]=d1[u]+w; pq.push({d1[v],v}); } } } cout << d1[3*n+y] << endl; } int main() { ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0); //freopen("hanhhhh.inp","r",stdin); //freopen("hanhhhh.out","w",stdout); int t=1; //cin >> t; while(t--) solve(); 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...