Submission #293400

#TimeUsernameProblemLanguageResultExecution timeMemory
293400rama_pangCommuter Pass (JOI18_commuter_pass)C++14
100 / 100
451 ms20724 KiB
#include <bits/stdc++.h> using namespace std; using lint = long long; int main() { ios::sync_with_stdio(0); cin.tie(0), cout.tie(0); int N, M, S, T, U, V; cin >> N >> M >> S >> T >> U >> V; S--, T--, U--, V--; vector<vector<pair<int, int>>> adj(N); for (int i = 0; i < M; i++) { int u, v, w; cin >> u >> v >> w; u--, v--; adj[u].emplace_back(v, w); adj[v].emplace_back(u, w); } auto Dijkstra = [&](int s) { vector<lint> dist(N, -1); priority_queue<pair<lint, int>, vector<pair<lint, int>>, greater<pair<lint, int>>> pq; pq.emplace(0, s); dist[s] = 0; while (!pq.empty()) { int u = pq.top().second; lint d = pq.top().first; pq.pop(); if (dist[u] != d) { continue; } for (auto v : adj[u]) { if (dist[v.first] == -1 || dist[v.first] > dist[u] + v.second) { dist[v.first] = dist[u] + v.second; pq.emplace(dist[v.first], v.first); } } } return dist; }; vector<lint> dS = Dijkstra(S); vector<lint> dT = Dijkstra(T); vector<lint> dU = Dijkstra(U); vector<lint> dV = Dijkstra(V); vector<int> order(N); iota(begin(order), end(order), 0); sort(begin(order), end(order), [&](int i, int j) { return dS[i] < dS[j]; }); auto Calc = [&](int A, int B, vector<lint> dA, vector<lint> dB) { vector<lint> dp(N); lint ans = 1e18; for (auto u : order) { if (dS[u] + dT[u] == dS[T]) { dp[u] = dA[u]; for (auto v : adj[u]) if (dS[v.first] + dT[v.first] == dS[T] && dS[v.first] < dS[u]) { dp[u] = min(dp[u], dp[v.first]); } ans = min(ans, dp[u] + dB[u]); } else { ans = min(ans, dA[u] + dB[u]); } } return ans; }; cout << min(Calc(U, V, dU, dV), Calc(V, U, dV, dU)) << "\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...