Submission #544911

#TimeUsernameProblemLanguageResultExecution timeMemory
544911pokmui9909Commuter Pass (JOI18_commuter_pass)C++17
100 / 100
389 ms23200 KiB
#include <bits/stdc++.h> using namespace std; using ll = long long; #define x first #define y second ll N, M, S, T, U, V; vector<pair<ll, ll>> G[100005]; ll dpU[100005], dpV[100005]; vector<ll> insp; vector<ll> dS, dT, dU, dV; const ll INF = 1e18; vector<ll> dijkstra(ll s){ vector<ll> d(N, INF); priority_queue<pair<ll, ll>> PQ; d[s] = 0; PQ.push({0, s}); while(!PQ.empty()){ ll c = -PQ.top().x, u = PQ.top().y; PQ.pop(); for(auto i : G[u]){ ll v = i.x, nc = c + i.y; if(d[v] <= nc) continue; d[v] = nc; PQ.push({-nc, v}); } } return d; } int main(){ cin.tie(0) -> sync_with_stdio(false); cin >> N >> M >> S >> T >> U >> V; S--, T--, U--, V--; for(int i = 0; i < M; i++){ ll u, v, c; cin >> u >> v >> c; u--, v--; G[u].push_back({v, c}); G[v].push_back({u, c}); } dS = dijkstra(S), dT = dijkstra(T), dU = dijkstra(U), dV = dijkstra(V); for(int i = 0; i < N; i++){ if(dS[i] + dT[i] == dS[T]){ insp.push_back(i); } } sort(insp.begin(), insp.end(), [&](ll a, ll b) -> bool{return dS[a] < dS[b];}); fill(dpU, dpU + N, INF); for(auto u : insp) dpU[u] = dU[u]; for(auto u : insp){ for(auto i : G[u]){ ll v = i.x; if(dS[v] + dT[v] != dS[T] || dS[u] > dS[v]) continue; dpU[v] = min(dpU[v], dpU[u]); } } fill(dpV, dpV + N, INF); for(auto u : insp) dpV[u] = dV[u]; for(auto u : insp){ for(auto i : G[u]){ ll v = i.x; if(dS[v] + dT[v] != dS[T] || dS[u] > dS[v]) continue; dpV[v] = min(dpV[v], dpV[u]); } } ll ans = dU[V]; for(auto i : insp){ ans = min({ans, dpU[i] + dV[i], dpV[i] + dU[i]}); } cout << ans; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...