제출 #531696

#제출 시각아이디문제언어결과실행 시간메모리
531696Sho10Commuter Pass (JOI18_commuter_pass)C++17
100 / 100
1220 ms46200 KiB
#include <bits/stdc++.h> //Andrei Alexandru a.k.a Sho #define ll long long #define double long double #pragma GCC optimize("O3") #pragma GCC optimize("Ofast") #define aint(a) (a).begin(), (a).end() #define f first #define s second #define pb push_back #define mp make_pair #define pi pair #define rc(s) return cout<<s,0 #define endl '\n' #define mod 998244353 #define PI 3.14159265359 #define INF 1000000005 #define LINF 1000000000000000005ll #define CODE_START ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0); using namespace std; ll n,m,s,t,u,v,du[100005],dv[100005],ds[100005],dp[2][100005],ans; map<ll,ll>viz; vector<pair<ll,ll>>g[500005]; void d1(ll start,ll a[]){ viz.clear(); priority_queue<pair<ll,ll>>q; q.push(mp(0,start)); while(!q.empty()){ ll c,node; c=q.top().f; node=q.top().s; q.pop(); if(viz[node]==0){ a[node]=-c; viz[node]=1; for(auto& it : g[node]){ q.push(mp(c-it.s,it.f)); } } } } void d2(ll start,ll endd){ fill(dp[0],dp[0]+100001,LINF); fill(dp[1],dp[1]+100001,LINF); viz.clear(); priority_queue<pair<ll,pair<ll,ll>>>q; q.push(mp(0,mp(start,0))); dp[0][0]=dp[1][0]=LINF; while(!q.empty()){ ll node,c,par; c=q.top().f; node=q.top().s.f; par=q.top().s.s; q.pop(); if(viz[node]==0){ viz[node]=1; ds[node]=-c; dp[0][node]=min(du[node],dp[0][par]); dp[1][node]=min(dv[node],dp[1][par]); for(auto it : g[node]){ q.push(mp(c-it.s,mp(it.f,node))); } }else if(-c==ds[node]){ if(min(du[node],dp[0][par])+min(dv[node],dp[1][par])<=dp[0][node]+dp[1][node]){ dp[0][node]=min(du[node],dp[0][par]); dp[1][node]=min(dv[node],dp[1][par]); } } } ans=min(ans,dp[0][endd]+dp[1][endd]); } int32_t main(){ CODE_START; cin>>n>>m>>s>>t>>u>>v; for(ll i=0;i<m;i++) { ll x,y,z; cin>>x>>y>>z; g[x].pb(mp(y,z)); g[y].pb(mp(x,z)); } d1(u,du); d1(v,dv); ans=du[v]; d2(s,t); d2(t,s); cout<<ans<<endl; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...