Submission #998597

#TimeUsernameProblemLanguageResultExecution timeMemory
998597pannenkoekCommuter Pass (JOI18_commuter_pass)C++17
31 / 100
180 ms22236 KiB
#include <bits/stdc++.h> using namespace std; #define rep(i, a, b) for(int i = (a); i < (b); i++) #define pb push_back #define fi first #define se second using ll = long long; using ld = long double; using pii = pair<ll, ll>; const int MAXN = 1e5 + 5; const ll inf = 1e18 + 5; int n, m, s, t, u, v; vector<pii> adj[MAXN]; set<pii> marked; bool vis[MAXN]; ll dis1[MAXN], dis2[MAXN], dis3[MAXN], dis4[MAXN]; int main(){ ios_base::sync_with_stdio(false); cin.tie(0); cin >> n >> m >> s >> t >> u >> v; s--; t--; u--; v--; rep(i, 0, m){ int a, b, c; cin >> a >> b >> c; a--; b--; adj[a].pb({b, c}); adj[b].pb({a, c}); } priority_queue<pii, vector<pii>, greater<pii>> pq; fill(dis1, dis1 + n, inf); dis1[s] = 0; pq.push({0, s}); while(!pq.empty()){ auto [d, cur] = pq.top(); pq.pop(); if(d > dis1[cur]) continue; for(auto [i, d2]: adj[cur]){ if(d + d2 < dis1[i]){ pq.push({d + d2, i}); dis1[i] = d + d2; } } } fill(dis2, dis2 + n, inf); dis2[t] = 0; pq.push({0, t}); while(!pq.empty()){ auto [d, cur] = pq.top(); pq.pop(); if(d > dis2[cur]) continue; for(auto [i, d2]: adj[cur]){ if(d + d2 < dis2[i]){ pq.push({d + d2, i}); dis2[i] = d + d2; } } } fill(dis3, dis3 + n, inf); dis3[u] = 0; pq.push({0, u}); while(!pq.empty()){ auto [d, cur] = pq.top(); pq.pop(); if(d > dis3[cur]) continue; for(auto [i, d2]: adj[cur]){ if(dis1[cur] + dis2[i] + d2 == dis1[t]) d2 = 0; if(d + d2 < dis3[i]){ pq.push({d + d2, i}); dis3[i] = d + d2; } } } fill(dis4, dis4 + n, inf); dis4[u] = 0; pq.push({0, u}); while(!pq.empty()){ auto [d, cur] = pq.top(); pq.pop(); if(d > dis4[cur]) continue; for(auto [i, d2]: adj[cur]){ if(dis2[cur] + dis1[i] + d2 == dis1[t]) d2 = 0; if(d + d2 < dis4[i]){ pq.push({d + d2, i}); dis4[i] = d + d2; } } } cout << min(dis3[v], dis4[v]) << "\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...