제출 #557656

#제출 시각아이디문제언어결과실행 시간메모리
557656Quan2003Commuter Pass (JOI18_commuter_pass)C++17
31 / 100
454 ms20148 KiB
#include <bits/stdc++.h> #include <iostream> #include<queue> #include<vector> #include<utility> using namespace std; typedef long long ll; const int sz=1e5+1; vector<pair<int,ll>>g[sz]; int s,t,u,v; int n,m; ll ans; ll d0[sz]; ll d1[sz]; ll dx[sz]; ll dpu[sz]; ll dpv[sz]; void dijisktra(int src, ll d[sz]){ using T=pair<ll,int>; priority_queue<T,vector<T>,greater<T>>pq; pq.push({0,src}); d[src]=0; while (pq.size()){ int node;ll val; tie(val,node)=pq.top(); pq.pop(); if (d[node]!=val) continue; for(auto u:g[node]){ int p=u.first; ll dist=u.second+val; if (dist<d[p]){ pq.push({d[p]=dist,p}); } } } } ll dpdijisktra(int src){ using T=pair<ll,int>; priority_queue<T,vector<T>,greater<T>>pq; dx[src]=0; pq.push({0,src}); while(pq.size()){ int node;ll val; tie(val,node)=pq.top(); pq.pop(); if (dx[node]!=val) continue; for (auto u:g[node]){ int z=u.first; ll dist=u.second+val; if (dx[z]==dist){ if (dpu[z]+dpv[z]>=dpu[node]+dpv[node]){ dpu[z]=min(dpu[node],d0[z]); dpv[z]=min(dpv[node],d1[z]); } } if (dx[z]>dist){ dx[z]=dist; pq.push({dx[z],z}); dpu[z]=min(dpu[node],d0[z]); dpv[z]=min(dpv[node],d1[z]); } } } return dpu[t]+dpv[t]; } int main() { cin>>n>>m; cin>>s>>t; cin>>u>>v; for (int i=0;i<m;i++){ int x,y; ll t; cin>>x>>y>>t; g[x].push_back({y,t}); g[y].push_back({x,t}); } for(int i=1;i<=n;i++){ d1[i]=LLONG_MAX; d0[i]=LLONG_MAX; dx[i]=LLONG_MAX; dpu[i]=LLONG_MAX; dpv[i]=LLONG_MAX; } dijisktra(u,d0); dijisktra(v,d1); dpu[u]=0; dpv[v]=0; ll res=d0[v]; res=min(dpdijisktra(s),res); 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...