Submission #884746

#TimeUsernameProblemLanguageResultExecution timeMemory
884746tosivanmakCommuter Pass (JOI18_commuter_pass)C++17
0 / 100
205 ms34072 KiB
#include<bits/stdc++.h> using namespace std; #define ll long long vector<pair<ll,ll> >adj[200005]; ll dist[200005]; ll fromu[200005],fromv[200005],cop[200005]; bool visited[200005]; priority_queue<pair<ll,ll> >q; ll ans[200005]; ll stdist,uvdist; void D(ll s){ dist[s]=0; q.push({0,s}); while(!q.empty()){ pair<ll,ll>lol=q.top(); q.pop(); if(visited[lol.second]){ continue; } visited[lol.second]=true; for(auto u: adj[lol.second]){ if(dist[lol.second]+u.second<dist[u.first]){ dist[u.first]=dist[lol.second]+u.second; q.push({-dist[u.first],u.first}); } } } } void D2(ll s){ dist[s]=0; q.push({0,s}); while(!q.empty()){ pair<ll,ll>lol=q.top(); q.pop(); if(visited[lol.second]){ continue; } visited[lol.second]=true; for(auto u: adj[lol.second]){ if(dist[lol.second]+u.second==dist[u.first]){ ans[u.first]=min(ans[u.first],ans[lol.second]); } else if(dist[lol.second]+u.second<dist[u.first]){ dist[u.first]=dist[lol.second]+u.second; ans[u.first]=ans[lol.second]; q.push({-dist[u.first],u.first}); } } } } int main(){ ios::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); ll n,m,s,t,u,v; cin>>n>>m>>s>>t>>u>>v; ll a[m+5],b[m+5],c[m+5]; for(int i=1;i<=m;i++){ cin>>a[i]>>b[i]>>c[i]; adj[a[i]].push_back({b[i],c[i]}); adj[b[i]].push_back({a[i],c[i]}); } for(int i=1;i<=n;i++){ dist[i]=1e10; visited[i]=false; } D(u); uvdist=dist[v]; for(int i=1;i<=n;i++){ fromu[i]=dist[i]; dist[i]=1e10; visited[i]=false; } D(v); for(int i=1;i<=n;i++){ fromv[i]=dist[i]; dist[i]=1e10; visited[i]=false; } for(int i=1;i<=n;i++){ ans[i]=fromu[i]; } D2(s); stdist=dist[t]; for(int i=1;i<=n;i++){ cop[i]=dist[i]; dist[i]=1e10; visited[i]=false; } D2(t); // cout<<uvdist<<'\n'; for(int i=1;i<=n;i++){ if(cop[i]+dist[i]==stdist){ uvdist=min(uvdist,ans[i]+fromv[i]); } } cout<<uvdist<<'\n'; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...