Submission #372501

#TimeUsernameProblemLanguageResultExecution timeMemory
372501iliccmarkoCommuter Pass (JOI18_commuter_pass)C++14
31 / 100
478 ms29588 KiB
#include <bits/stdc++.h> using namespace std; #define ll long long #define endl "\n" #define INF 1000000000 #define LINF 10000000000000000LL #define pb push_back #define all(x) x.begin(), x.end() #define len(s) (int)s.size() #define test_case { int t; cin>>t; while(t--)solve(); } #define single_case solve(); #define line cerr<<"----------"<<endl; #define ios { ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); cerr.tie(NULL); } #define mod 1000000007LL const int N = 2e5 + 5; vector<pair<ll, ll> > g[N]; ll ds[N], dt[N], du[N], dv[N]; ll n, m, s, t, u, v; int vidjen[N]; ll d[N]; void dijkstra(ll src, ll dis[]) { for(int i = 0;i<N;i++) dis[i] = LINF, vidjen[i] = 0; priority_queue<pair<ll, ll>, vector<pair<ll, ll> >, greater<pair<ll, ll> > > pq; dis[src] = 0; pq.push(make_pair(0, src)); while(len(pq)) { ll u = pq.top().second; pq.pop(); if(vidjen[u]) continue; vidjen[u] = 1; for(auto x : g[u]) { ll v = x.first; ll c = x.second; if(dis[v]>dis[u]+c) { dis[v] = dis[u] + c; pq.push(make_pair(dis[v], v)); } } } } void dijkstra2(ll src, ll dis[]) { for(int i = 0;i<N;i++) dis[i] = LINF, vidjen[i] = 0; priority_queue<pair<ll, ll>, vector<pair<ll, ll> >, greater<pair<ll, ll> > > pq; dis[src] = 0; pq.push(make_pair(0, src)); while(len(pq)) { ll u = pq.top().second; pq.pop(); if(vidjen[u]) continue; vidjen[u] = 1; for(auto x : g[u]) { ll v = x.first; ll c = x.second; ll k = 0; if(ds[u]+dt[u]!=ds[t]) k = c; if(dis[v]>dis[u]+k) { dis[v] = dis[u] + k; if(ds[v]+dt[v]==ds[t]) continue; pq.push(make_pair(dis[v], v)); } } } } bool cmp(int a, int b) { return du[a] < du[b]; } void dfs(ll u, ll x) { vidjen[u] = 1; du[u] = min(du[u], x); for(auto W : g[u]) { if(vidjen[W.first]==1||ds[W.first]+dt[W.first]!=ds[t]) continue; dfs(W.first, x); } } int main() { ios cin>>n>>m>>s>>t>>u>>v; for(int i = 0;i<m;i++) { ll a, b, c; cin>>a>>b>>c; g[a].pb(make_pair(b, c)); g[b].pb(make_pair(a, c)); } dijkstra(s, ds); dijkstra(t, dt); dijkstra2(u, du); dijkstra2(v, dv); vector<ll> w; for(ll i = 1;i<=n;i++) { if(ds[i]+dt[i]==ds[t]) w.pb(i); } for(ll i = 0;i<N;i++) vidjen[i] = 0; sort(all(w), cmp); vector<ll> q; for(ll i = 1;i<=n;i++) if(ds[i]+dt[i]==ds[t]) q.pb(i); for(ll x : w) { if(vidjen[x]) continue; dfs(x, du[x]); } dijkstra(v, d); ll res = d[u]; for(int i = 1;i<=n;i++) if(ds[i]+dt[i]==ds[t]) res = min(res, dv[i]+du[i]); cout<<res; 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...