Submission #213060

#TimeUsernameProblemLanguageResultExecution timeMemory
213060DS007Commuter Pass (JOI18_commuter_pass)C++14
100 / 100
617 ms24308 KiB
#include <bits/stdc++.h> using namespace std; #define int long long const int N = 1e5; int n, m, s, t, u, v; vector<pair<int, int>> adj[N]; int du[N], dv[N], ds[N], dt[N]; void dijkstra(int src, int dist[]) { fill(dist, dist + N, 1e18); dist[src] = 0; priority_queue<pair<int, int>, vector<pair<int, int>>, decltype(greater<>())> pq; bool done[N] = {}; pq.push({0, src}); while (!pq.empty()) { int temp = pq.top().second; pq.pop(); if (done[temp]) continue; done[temp] = true; for (auto i : adj[temp]) { if (dist[i.first] > dist[temp] + i.second) { dist[i.first] = dist[temp] + i.second; pq.push({dist[i.first], i.first}); } } } } int solve() { dijkstra(u, du); dijkstra(v, dv); dijkstra(t, dt); int mv[N]; fill(mv, mv + N, 1e18); mv[s] = du[s]; fill(ds, ds + N, 1e18); ds[s] = 0; priority_queue<pair<int, int>, vector<pair<int, int>>, decltype(greater<>())> pq; bool done[N] = {}; pq.push({0, s}); int ans = du[v]; while (!pq.empty()) { int temp = pq.top().second; pq.pop(); if (done[temp]) continue; done[temp] = true; mv[temp] = min(mv[temp], du[temp]); if (ds[temp] + dt[temp] == dt[s]) ans = min(ans, mv[temp] + dv[temp]); for (auto i : adj[temp]) { if (ds[i.first] > ds[temp] + i.second) { ds[i.first] = ds[temp] + i.second; pq.push({ds[i.first], i.first}); mv[i.first] = mv[temp]; } else if (ds[i.first] == ds[temp] + i.second) { mv[i.first] = min(mv[i.first], mv[temp]); } } } return ans; } void solveTestCase() { cin >> n >> m >> s >> t >> u >> v; s--, t--, u--, v--; for (int i = 0; i < m; i++) { int a, b, c; cin >> a >> b >> c; a--, b--; adj[a].emplace_back(b, c); adj[b].emplace_back(a, c); } int ans = solve(); swap(u, v); cout << min(ans, solve()); } signed main() { ios::sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr); int test = 1; // cin >> test; while (test--) solveTestCase(); }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...