Submission #519423

#TimeUsernameProblemLanguageResultExecution timeMemory
519423Jarif_RahmanCommuter Pass (JOI18_commuter_pass)C++17
0 / 100
2092 ms55980 KiB
#include <bits/stdc++.h> #define pb push_back #define f first #define sc second using namespace std; typedef long long int ll; typedef string str; const ll inf = 1e17; vector<ll> dijsktra(vector<vector<pair<int, ll>>> v, int s){ int n = v.size(); vector<ll> dis(n, inf); vector<bool> bl(n, 0); priority_queue<pair<ll, int>> pq; dis[s] = 0; pq.push({0, s}); while(!pq.empty()){ int nd = pq.top().sc; pq.pop(); if(bl[nd]) continue; bl[nd] = 1; for(auto [x, w]: v[nd]) if(dis[nd]+w < dis[x]){ dis[x] = dis[nd]+w; pq.push({-dis[x], x}); } } return dis; } int main(){ ios_base::sync_with_stdio(0); cin.tie(0); int n, m; cin >> n >> m; int S, T, U, V; cin >> S >> T >> U >> V; S--, T--, U--, V--; vector<vector<pair<int, ll>>> v(n); for(int i = 0; i < m; i++){ int a, b; ll w; cin >> a >> b >> w; a--, b--; v[a].pb({b, w}); v[b].pb({a, w}); } vector<ll> ds = dijsktra(v, S), dt = dijsktra(v, T), du = dijsktra(v, U), dv = dijsktra(v, V); ll ans = du[V]; vector<vector<ll>> d(n); for(int i = 0; i < n; i++) d[i] = dijsktra(v, i); for(int i = 0; i < n; i++) for(int j = i; j < n; j++){ if(ds[i]+d[i][j]+dt[j] == ds[T]) ans = min(ans, min(du[i]+dv[j], du[j]+dv[i])); } cout << ans << "\n"; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...