Submission #1035021

#TimeUsernameProblemLanguageResultExecution timeMemory
1035021_Nhm207_Commuter Pass (JOI18_commuter_pass)C++14
0 / 100
276 ms31232 KiB
#include<bits/stdc++.h> #define int long long #define Task "bus" using namespace std; const int N = 1e5 + 5; vector<int> ds , dt , du , dv; int n , m , u , v , s , t , ok[N]; int res; vector<pair<int , int>> g[N]; void dijkstra(int u , vector<int> &d){ d . resize(n + 1); for(int i = 1 ; i <= n ; i++) d[i] = 1e18; d[u] = 0; priority_queue<pair<int , int> , vector<pair<int , int>> , greater<pair<int , int>>> pq; pq . push({d[u] , u}); while(pq . size()){ int u = pq . top() . second; int du = pq . top() . first; pq . pop(); if(d[u] != du) continue; for(pair<int , int> nex : g[u]){ if(d[nex . first] > d[u] + nex . second){ d[nex . first] = d[u] + nex . second; pq . push({d[nex . first] , nex . first}); } } } } void Get(int s , int t){ vector<int> dp[2] , ds; dp[0] . resize(n + 1); dp[1] . resize(n + 1); ds . resize(n + 1); for(int i = 0 ; i <= n ; i++) ds[i] = 1e18 , dp[0][i] = 1e18 , dp[1][i] = 1e18; ds[s] = 0; memset(ok , false , sizeof(ok)); priority_queue<pair<int , pair<int , int>> , vector<pair<int , pair<int , int>>> , greater<pair<int , pair<int , int>>>> pq; pq . push({0 , {s , 0}}); while(pq . size()){ int node , par; node = pq . top() . second . first; par = pq . top() . second . second; pq . pop(); if(!ok[node]){ ds[node] = pq . top() . first; dp[0][node] = min(dp[0][par] , du[node]); dp[1][node] = min(dp[1][par] , dv[node]); ok[node] = true; for(pair<int , int> nex : g[node]){ pq . push({ds[node] + nex . second , {nex . first , node}}); } } else if(pq . top() . first == ds[node] && min(dp[0][par] , du[node]) + min(dp[1][par] , dv[node]) <= dp[0][node] + dp[1][node]){ dp[0][node] = min(dp[0][par] , du[node]); dp[1][node] = min(dp[1][par] , dv[node]); } } res = min(res , dp[0][t] + dp[1][t]); } int32_t main(){ ios_base::sync_with_stdio(0); cin.tie(0);cout.tie(0); // if(fopen(Task".inp","r")){ // freopen(Task".inp","r",stdin); // freopen(Task".out","w",stdout); // } cin >> n >> m; cin >> s >> t; cin >> u >> v; for(int i = 1 ; i <= m ; i++){ int u , v , c; cin >> u >> v >> c; g[u] . push_back({v , c}); g[v] . push_back({u , c}); } dijkstra(u , du); dijkstra(v , dv); res = du[v]; Get(s , t); Get(t , s); cout << res; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...