Submission #237045

#TimeUsernameProblemLanguageResultExecution timeMemory
237045anubhavdharCommuter Pass (JOI18_commuter_pass)C++14
100 / 100
1396 ms27108 KiB
#include<bits/stdc++.h> #define ll long long int #define pb push_back #define mp make_pair #define FOR(i,n) for(i=0;i<(n);++i) #define FORe(i,n) for(i=1;i<=(n);++i) #define FORr(i,a,b) for(i=(a);i<(b);++i) #define FORrev(i,n) for(i=(n);i>=0;--i) #define F0R(i,n) for(int i=0;i<(n);++i) #define F0Re(i,n) for(int i=1;i<=(n);++i) #define F0Rr(i,a,b) for(ll i=(a);i<(b);++i) #define F0Rrev(i,n) for(int i=(n);i>=0;--i) #define ii pair<ll,ll> #define vi vector<ll> #define vii vector<ii> #define ff first #define ss second #define cd complex<double> #define vcd vector<cd> #define ldd long double #define dbgLine cout<<"Line : "<<__LINE__<<'\n' #define all(x) (x).begin(),(x).end() using namespace std; const short int __PRECISION = 10; const ll MOD = 1e9+7; const ll INF = 1e17 + 1101; const ll LOGN = 17; const ll MAXN = 1e5+5; const ll ROOTN = 320; const ldd PI = acos(-1); const ldd EPS = 1e-7; int N, M, U, V, S, T; ll d[2][MAXN], ans; ii dis[2][MAXN]; vii g[MAXN]; inline void Dijkstra(int s) { int m = (s == U ? 0 : 1); set<ii> x; F0Re(i, N) d[m][i] = INF; d[m][s] = 0; x.insert(mp(0, s)); while(!x.empty()) { int a = (*x.begin()).ss; x.erase(x.begin()); for(ii p : g[a]) { if(d[m][p.ff] > d[m][a] + p.ss) { x.erase(mp(d[m][p.ff], p.ff)); d[m][p.ff] = d[m][a] + p.ss; x.insert(mp(d[m][p.ff], p.ff)); } } } } inline void SuperDijstra(int s) { int m = (s == S ? 0 : 1); set<pair<ii,ll>> x; F0Re(i, N) dis[m][i] = mp(INF, INF); dis[m][s] = mp(0, d[m][s]); x.insert(mp(dis[m][s], s)); while(!x.empty()) { int a = (*x.begin()).ss; x.erase(x.begin()); for(ii p : g[a]) { if(dis[m][p.ff] > mp(dis[m][a].ff + p.ss, min(d[m][p.ff],dis[m][a].ss))) { x.erase(mp(dis[m][p.ff], p.ff)); dis[m][p.ff] = mp(dis[m][a].ff + p.ss, min(d[m][p.ff],dis[m][a].ss)); x.insert(mp(dis[m][p.ff], p.ff)); } } } } inline void solve() { ii tmp = mp(INF, INF); F0Re(i, N) tmp = min(tmp, mp(dis[0][i].ff + dis[1][i].ff, dis[0][i].ss + dis[1][i].ss)); ans = min(ans, min(tmp.ss, d[0][V])); } int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); ll i, j, k; ans = INF; cin>>N>>M>>S>>T>>U>>V; while(M--) { cin>>i>>j>>k; g[i].pb(mp(j,k)); g[j].pb(mp(i,k)); } Dijkstra(U); Dijkstra(V); SuperDijstra(S); SuperDijstra(T); solve(); swap(U, V); Dijkstra(U); Dijkstra(V); SuperDijstra(S); SuperDijstra(T); solve(); cout<<ans; 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...