Submission #548387

#TimeUsernameProblemLanguageResultExecution timeMemory
548387FEDIKUSCommuter Pass (JOI18_commuter_pass)C++17
100 / 100
387 ms33092 KiB
#include <bits/stdc++.h> #define mp make_pair #define pb push_back #define pf push_front #define popb pop_back #define popf pop_front #define xx first #define yy second #define srt(a) sort(a.begin(),a.end()); #define srtg(a,ll) sort(a.begin(),a.end(),greater<ll>()) #define lb(a,x) lower_bound(a.begin(),a.end(),x) #define up(a,x) upper_bound(a.begin(),a.end(),x) #define fnd(a,x) find(a.begin(),a.end(),x) #define vstart auto startt=chrono::system_clock::now() #define vend auto endd=chrono::system_clock::now() #define vvreme chrono::duration<double> vremee=endd-startt #define ios ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0) using namespace std; typedef long long ll; typedef pair<ll,ll> pii; typedef pair<ll,ll> pll; typedef string str; const ll maxn=1e5+10; vector<pair<ll,ll> > g[maxn]; vector<ll> ng[maxn]; ll dists[maxn],distu[maxn],distv[maxn]; ll n,m,s,t,u,v; ll res=LLONG_MAX; bool bio[maxn]; pii naj[maxn]; void dijkstra(ll poc,ll* dist){ priority_queue<pii,vector<pii>,greater<pii> > pq; for(ll i=1;i<=n;i++) dist[i]=LLONG_MAX; dist[poc]=0; pq.push(mp(0,poc)); while(!pq.empty()){ auto tren=pq.top(); pq.pop(); if(dist[tren.yy]<tren.xx) continue; for(pii i:g[tren.yy]){ if(dist[i.xx]>dist[tren.yy]+i.yy){ dist[i.xx]=dist[tren.yy]+i.yy; pq.push(mp(dist[i.xx],i.xx)); } } } } void dfs(ll cvor){ if(bio[cvor]) return; bio[cvor]=true; naj[cvor]={LLONG_MAX,LLONG_MAX}; if(cvor==t) naj[cvor]={distu[cvor],distv[cvor]}; for(ll i:ng[cvor]){ dfs(i); naj[cvor].xx=min(naj[cvor].xx,naj[i].xx); naj[cvor].yy=min(naj[cvor].yy,naj[i].yy); } if(naj[cvor].xx!=LLONG_MAX){ naj[cvor].xx=min(naj[cvor].xx,distu[cvor]); naj[cvor].yy=min(naj[cvor].yy,distv[cvor]); res=min(res,min(distu[cvor]+naj[cvor].yy,distv[cvor]+naj[cvor].xx)); } } void solve(){ cin>>n>>m; cin>>s>>t; cin>>u>>v; for(ll i=0;i<m;i++){ ll a,b,c; cin>>a>>b>>c; g[a].pb(mp(b,c)); g[b].pb(mp(a,c)); } dijkstra(s,dists); dijkstra(u,distu); dijkstra(v,distv); for(ll i=1;i<=n;i++){ for(pii j:g[i]){ if(dists[i]+j.yy==dists[j.xx]){ ng[i].pb(j.xx); } } } dfs(s); cout<<min(res,distu[v]); } int main(){ //ios; ll 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...