Submission #297725

#TimeUsernameProblemLanguageResultExecution timeMemory
297725Leonardo_PaesCommuter Pass (JOI18_commuter_pass)C++17
100 / 100
454 ms27468 KiB
#include <bits/stdc++.h> using namespace std; const int maxn = 1e5+10; #define f first #define s second typedef long long ll; typedef pair<ll,ll> pii; typedef pair<ll,pii> pip; const ll inf = 1e18; int n, m, a, b, s, t; ll d[4][maxn], dp[2][maxn]; // 0 = a, 1 = b, 2 = s, 3 = t vector<pii> grafo[maxn]; void dijkstra(int id, int root){ if(id <=1){ priority_queue<pii, vector<pii>, greater<pii>> fila; fila.push({0, root}); while(!fila.empty()){ ll u = fila.top().s, dist = fila.top().f; fila.pop(); if(d[id][u] != -1) continue; d[id][u] = dist; for(auto vv : grafo[u]){ int v = vv.s, w = vv.f; if(d[id][v] == -1) fila.push({dist + w, v}); } } } else{ priority_queue<pip, vector<pip>, greater<pip>> fila; fila.push({0, {root, d[1][root]}}); while(!fila.empty()){ ll u = fila.top().s.f, dist = fila.top().f, tfg = fila.top().s.s; fila.pop(); if(d[id][u] != -1){ if(d[id][u] == dist) dp[id-2][u] = min(dp[id-2][u], tfg); continue; } d[id][u] = dist; dp[id-2][u] = min(dp[id-2][u], tfg); for(auto vv : grafo[u]){ int v = vv.s, w = vv.f; if(d[id][v] == -1) fila.push({dist + w, {v, min(dp[id-2][u], d[1][v])}}); } } } } int main(){ ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL); cin >> n >> m >> s >> t >> a >> b; for(int i=1; i<=m; i++){ int u, v, w; cin >> u >> v >> w; grafo[u].push_back({w, v}); grafo[v].push_back({w, u}); } memset(d, -1, sizeof d); for(int i=1; i<=n; i++) dp[0][i] = dp[1][i] = inf; dijkstra(0, a), dijkstra(1, b), dijkstra(2, s), dijkstra(3, t); ll ans = inf; for(int i=1; i<=n; i++){ ans = min(ans, d[0][i] + d[1][i]); if(d[2][i] + d[3][i] == d[2][t]){ ans = min(ans, d[0][i] + min(dp[0][i], dp[1][i])); } } cout << ans << "\n"; 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...