Submission #546774

#TimeUsernameProblemLanguageResultExecution timeMemory
546774ertoCommuter Pass (JOI18_commuter_pass)C++17
15 / 100
2095 ms262144 KiB
#include <bits/stdc++.h> typedef long long int ll; #define INF ll(1e18 + 7) #define N (ll)1e5 + 5 using namespace std; #define int ll int n, m, s, t, u2, v, g, h, z, g2, h2; vector<pair<int, int>> v2[N]; bool used[N]; int ds[N], du[N], dv[N]; pair<int, int> d1[N], d2[N]; void bfs(){ memset(used, 0, sizeof(used)); priority_queue<pair<int, int>> q; q.push({0, s}); pair<int, int> p; while(!q.empty()){ p = q.top(); q.pop(); if(used[p.second])continue; used[p.second] = 1; for(auto u : v2[p.second]){ if(!used[u.first] && ds[u.first] > ds[p.second] + u.second){ ds[u.first] = ds[p.second] + u.second; q.push({-ds[u.first], u.first}); } } } } void bfs2(){ memset(used, 0, sizeof(used)); priority_queue<pair<int, int>> q; q.push({0, u2}); pair<int, int> p; while(!q.empty()){ p = q.top(); q.pop(); if(used[p.second])continue; used[p.second] = 1; for(auto u : v2[p.second]){ if(!used[u.first] && du[u.first] > du[p.second] + u.second){ du[u.first] = du[p.second] + u.second; q.push({-du[u.first], u.first}); } } } } void bfs3(){ memset(used, 0, sizeof(used)); priority_queue<pair<int, int>> q; q.push({0, v}); pair<int, int> p; while(!q.empty()){ p = q.top(); q.pop(); if(used[p.second])continue; used[p.second] = 1; for(auto u : v2[p.second]){ if(!used[u.first] && dv[u.first] > dv[p.second] + u.second){ dv[u.first] = dv[p.second] + u.second; q.push({-dv[u.first], u.first}); } } } } void solve(){ cin >> n >> m >> s >> t >> u2 >> v; for(int i=0; i<m; i++){ cin >> g >> h >> z; v2[g].push_back({h, z}); v2[h].push_back({g, z}); } fill(ds, ds+n+1, INF); fill(du, du+n+1, INF); fill(dv, dv+n+1, INF); fill(d1, d1 + n + 1, make_pair(INF, INF)); fill(d2, d2 + n + 1, make_pair(INF, INF)); ds[s] = du[u2] = dv[v] = 0; bfs(); bfs2(); bfs3(); for(int i=1; i<=n; i++){ d1[i] = d2[i] = {du[i], dv[i]}; } int t1, t2, t3, t4; memset(used, 0, sizeof(used)); priority_queue<pair<int, int>> q; q.push({0, s}); pair<int, int> p; while(!q.empty()){ p = q.top(); q.pop(); g = d1[p.second].first, g2= d1[p.second].second, h = d2[p.second].first, h2= d2[p.second].second; for(auto u : v2[p.second]){ if(ds[u.first] == ds[p.second] + u.second){ t1 = min(g, du[u.first]); t2 = min(g2, dv[u.first]); t3 = min(h, du[u.first]); t4 = min(h2, dv[u.first]); d1[u.first] = {t1, t2}; d2[u.first] = {t3, t4}; q.push({-ds[u.first], u.first}); } } } cout<< min(min(d1[t].first + d1[t].second, d2[t].first + d2[t].second), du[v]); } signed main(){ //freopen("shortcut.in", "r", stdin); //freopen("shortcut.out", "w", stdout); ios_base::sync_with_stdio(0); cin.tie(0); int T = 1; //cin>>T; while (T--){ solve(); } }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...