Submission #852667

#TimeUsernameProblemLanguageResultExecution timeMemory
852667nghiaaaCommuter Pass (JOI18_commuter_pass)C++17
100 / 100
266 ms29772 KiB
#include <bits/stdc++.h> using namespace std; #define ll long long #define db double #define ii pair<int,int> #define f first #define s second #define mp make_pair #define mt make_tuple #define pb push_back #define ALL(v) v.begin(),v.end() #define BIT(i) ((ll)1<<i) #define endl "\n" #define debug(x) for (auto p: x) cout<<p<<' ';cout<<endl #define forw(i,j,z) for(int i=(int)j;i<=(int)z;i++) #define forw2(i,j,z,k) for(int i=(int)j;i<=(int)z;i+=k) #define ford(i,j,z) for (int i=(int)j;i>=(int)z;i--) #define ford2(i,j,z,k) for (int i=(int)j;i>=(int)z;i-=k) #define sz(a) (int)a.size() const ll inf=BIT(60); const int N=100000; int n,m,s; struct Edge{ int nex;ll cost; Edge(int v1,ll d1) { nex=v1,cost=d1; } }; vector<Edge> a[N+1]; vector<ll> S,U,V,dpU,dpV; vector<vector<int> > traceS; ll ans; bitset<N+1> vis; void dijkstra(int S,vector<ll> &dp,bool TRACE) { dp.assign(n+1,LLONG_MAX); dp[S]=0; priority_queue<pair<ll,int>,vector<pair<ll,int> >,greater<pair<ll,int> > > haha; haha.push(mp(0LL,S)); while(!haha.empty()) { pair<ll,int> temp = haha.top(); haha.pop(); int u=temp.s; if (temp.f>dp[u]) continue; forw(i,0,sz(a[u])-1) { int v=a[u][i].nex,d=a[u][i].cost; if (dp[u]+d<dp[v]) { if (TRACE) { traceS[v].clear(); traceS[v].pb(u); } dp[v]=dp[u]+d; haha.push(mp(dp[v],v)); } else if (TRACE&&dp[u]+d==dp[v]) traceS[v].pb(u); } } } void dfs(int u) { vis[u]=1; if (u==s) { dpU[u]=U[s],dpV[u]=V[s]; ans=min(ans,dpU[u]+dpV[u]); return ; } dpU[u]=U[u],dpV[u]=V[u]; forw(i,0,sz(traceS[u])-1) { int v=traceS[u][i]; if (!vis[v]) dfs(v); dpU[u]=min(dpU[u],dpU[v]); dpV[u]=min(dpV[u],dpV[v]); } ans=min(ans,min(dpU[u]+V[u],dpV[u]+U[u])); } void solve() { int u,v,t; cin>>n>>m; cin>>s>>t>>u>>v; traceS.assign(n+1,vector<int>(0,0)); dpU.assign(n+1,0); dpV.assign(n+1,0); while(m--) { int u,v;ll d; cin>>u>>v>>d; a[u].pb(Edge(v,d)); a[v].pb(Edge(u,d)); } dijkstra(s,S,1); dijkstra(u,U,0); dijkstra(v,V,0); ans=U[v]; dfs(t); cout<<ans; } signed main() { ios_base::sync_with_stdio(false); cin.tie(0); cout<<setprecision(6)<<fixed; int t=1; 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...