Submission #306423

#TimeUsernameProblemLanguageResultExecution timeMemory
306423vipghn2003Commuter Pass (JOI18_commuter_pass)C++14
0 / 100
358 ms19320 KiB
#include<bits/stdc++.h> #define fi first #define se second #define pii pair<int,int> #define mp make_pair using namespace std; const int N=1e5+5; int n,m,s,t,u,v,deg[N]; long long d[3][N],dp[N]; vector<int>g[N],topolist,rg[N]; vector<pii>adj[N]; bool vis[N]; void dijkstra(int i,int u) { priority_queue<pair<long long,int>,vector<pair<long long,int>>,greater<pair<long long,int>>>pq; d[i][u]=0; pq.push(mp(0,u)); while(!pq.empty()) { int x=pq.top().se; long long dist=pq.top().fi; pq.pop(); if(d[i][x]!=dist) continue; for(auto&to:adj[x]) { if(d[i][to.fi]==-1||d[i][to.fi]>dist+to.se) { d[i][to.fi]=dist+to.se; pq.push(mp(d[i][to.fi],to.fi)); } } } } void topo() { queue<int>pq; pq.push(s); while(!pq.empty()) { int x=pq.front(); pq.pop(); topolist.push_back(x); for(auto&to:g[x]) { deg[to]--; if(deg[to]==0) pq.push(to); } } } int main() { ios_base::sync_with_stdio(false); cin.tie(nullptr); cin>>n>>m>>s>>t>>u>>v; while(m--) { int u,v,w; cin>>u>>v>>w; adj[u].push_back(mp(v,w)); adj[v].push_back(mp(u,w)); } memset(d,-1,sizeof d); dijkstra(0,u); dijkstra(1,v); dijkstra(2,s); queue<int>cur; cur.push(t); while(!cur.empty()) { int x=cur.front(); cur.pop(); vis[x]=true; for(auto&to:adj[x]) { if(vis[to.fi]) continue; if(d[2][x]==d[2][to.fi]+to.se) { g[to.fi].push_back(x); rg[x].push_back(to.fi); deg[x]++; cur.push(to.fi); } } } topo(); long long res=d[0][v]; for(auto&x:topolist) { dp[x]=d[0][x]; for(auto&pre:rg[x]) dp[x]=min(dp[x],dp[pre]); res=min(res,d[1][x]+dp[x]); } cout<<res; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...