제출 #45649

#제출 시각아이디문제언어결과실행 시간메모리
45649realityCommuter Pass (JOI18_commuter_pass)C++17
31 / 100
903 ms91788 KiB
#include "bits/stdc++.h" using namespace std; #define fi first #define se second #define ll long long #define dbg(v) cerr<<#v<<" = "<<v<<'\n' #define vi vector<int> #define vl vector <ll> #define pii pair<int,int> #define mp make_pair #define db long double #define pb push_back #define all(s) s.begin(),s.end() #define int ll template < class T > T smin(T &a,T b) {if (a > b) a = b;return a;} template < class T > T smax(T &a,T b) {if (a < b) a = b;return a;} const int N = (int)(1e6) + 5; ll D1[N]; ll D2[N]; ll D3[N]; ll D4[N]; vector < pii > g[N]; int n; void Go(ll D[],int S) { for (int i = 1;i <= n;++i) D[i] = 1e18; D[S] = 0; priority_queue < pair < ll , int > , vector < pair < ll , int > > , greater < pair < ll , int > > > Q; Q.push(mp(0,S)); while (!Q.empty()) { const ll cost = Q.top().fi; const int node = Q.top().se; Q.pop(); if (cost != D[node]) continue; for (auto it : g[node]) if (D[it.fi] > D[node] + it.se) D[it.fi] = D[node] + it.se,Q.push(mp(D[it.fi],it.fi)); } } ll ans = 1e18; vi G[2][N]; int was[N]; void go(ll d1[],ll d2[],int who,vi order) { static ll D[N]; for (int i = 1;i <= n;++i) D[i] = d1[i]; for (auto u : order) for (auto v : G[who][u]) smin(D[u],D[v]); for (int i = 1;i <= n;++i) smin(ans,D[i] + d2[i]); } ll dist; void Sort(ll d1[],ll d2[],int st,vi &order,int who) { for (int i = 1;i <= n;++i) was[i] = 0; queue < int > q; q.push(st); was[st] = 1; while (!q.empty()) { int node = q.front(); q.pop(); order.pb(node); for (auto it : g[node]) if (d1[node] + it.se + d2[it.fi] == dist) { G[who][node].pb(it.fi); if (!was[it.fi]) was[it.fi] = 1,q.push(it.fi); } } } int32_t main(void) { int m; int S,T,U,V; cin>>n>>m>>S>>T>>U>>V; while (m --) { int a,b,c; cin>>a>>b>>c; g[a].pb(mp(b,c)); g[b].pb(mp(a,c)); } Go(D1,S); Go(D2,T); Go(D3,U); Go(D4,V); dist = D1[T]; vi order1,order2; Sort(D1,D2,S,order1,0); Sort(D2,D1,T,order2,1); ans = D3[V]; for (int cs = 0;cs < 2;++cs) { go(D3,D4,cs,order1); go(D4,D3,cs,order1); go(D3,D4,cs,order2); go(D4,D3,cs,order2); } cout << ans << '\n'; 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...