Submission #945335

#TimeUsernameProblemLanguageResultExecution timeMemory
945335XiaoyangCommuter Pass (JOI18_commuter_pass)C++17
31 / 100
308 ms26136 KiB
#include <bits/stdc++.h> using namespace std; #pragma GCC optimize("O3,unroll-loops") #pragma GCC target("avx2,bmi,bmi2,lzcnt,popcnt") typedef long long ll; #define fi first #define se second #define pll pair<ll,ll> #define pb push_back #define debug(x) cerr<<#x<<"="<<x<<endl; #define MP make_pair #define rep(i,a,b) for(ll i=a;i<b;i++) #define SZ(x) (ll)x.size() #define ALL(x) x.begin(),x.end() #define endl "\n" const ll inf=1e18; ll lowbit(ll x){return x&(-x);} const ll maxn=1e5+5; vector<pll>alist[maxn]; ll ds[maxn],dt[maxn],du[maxn],dv[maxn]; void dijkstra(ll st,ll dist[]){ rep(i,0,maxn)dist[i]=inf; priority_queue<pll,vector<pll>,greater<pll>>s; s.push(MP(0ll,st)); dist[st]=0; while(!s.empty()){ auto u=s.top(); s.pop(); if(u.fi!=dist[u.se])continue; for(auto x:alist[u.se]){ if(x.fi+u.fi<dist[x.se]){ dist[x.se]=x.fi+u.fi; s.push(MP(dist[x.se],x.se)); } } } } ll f[maxn],ff[maxn]; ll n,m; ll t; void dijk(ll orig[],ll dist[]){ priority_queue<pll,vector<pll>,greater<pll>>s; rep(i,1,n+1){ dist[i]=orig[i]; s.push(MP(orig[i],i)); } while(!s.empty()){ auto u=s.top(); s.pop(); if(u.fi!=dist[u.se])continue; for(auto x:alist[u.se]){ //the edge is on the path from s to t => free if(ds[x.se]+x.fi+dt[u.se]==ds[t] and dist[u.se]<dist[x.se]){ dist[x.se]=dist[u.se]; s.push(MP(dist[x.se],x.se)); } } } } ll s; ll u,v; int main(){ ios::sync_with_stdio(0); cin.tie(0); cin>>n>>m; cin>>s>>t; cin>>u>>v; rep(i,0,m){ ll a,b,c;cin>>a>>b>>c; alist[a].pb(MP(c,b)); alist[b].pb(MP(c,a)); } dijkstra(s,ds); dijkstra(t,dt); dijkstra(u,du); dijkstra(v,dv); dijk(dv,f); dijk(du,ff); ll ans=inf; rep(i,1,n+1){ ans=min(ans,ff[i]+f[i]); } cout<<ans<<endl; 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...