Submission #851635

#TimeUsernameProblemLanguageResultExecution timeMemory
851635nguyenneheheCommuter Pass (JOI18_commuter_pass)C++14
0 / 100
2009 ms26984 KiB
#include<bits/stdc++.h> using namespace std; #define isz(x) (int)(x).size() #define all(x) (x).begin(), (x).end() using ll = long long; using ld = long double; const ll inf = 2e18; const int N = 1e5 + 5; int n, m, S, T, U, V; vector<pair<int, int>> g[N]; void sub1() { auto dijkstra = [&](int s) { vector<ll> dist(n + 1, inf); priority_queue<pair<int, int>, vector<pair<int, int>>, greater<>> pq; pq.emplace(s, 0); dist[s] = 0; while (!pq.empty()) { int u, du; tie(u, du) = pq.top(); pq.pop(); if (du > dist[u]) { continue; } for (pair<int, int> it: g[u]) { int v, w; tie(v, w) = it; if (dist[u] + w < dist[v]) { dist[v] = dist[u] + w; pq.emplace(v, dist[v]); } } } return dist; }; vector<ll> distS = dijkstra(S); vector<ll> distT = dijkstra(T); vector<ll> distV = dijkstra(V); ll ans = inf, minPath = distS[T]; for (int i = 1; i <= n; ++i) { if (distS[i] + distT[i] == minPath) { ans = min(ans, distV[i]); } } cout << ans << '\n'; } signed main() { ios::sync_with_stdio(false); cin.tie(NULL); cin >> n >> m >> S >> T >> U >> V; for (int i = 1; i <= m; ++i) { int u, v, w; cin >> u >> v >> w; g[u].emplace_back(v, w); g[v].emplace_back(u, w); } if (S == U) { sub1(); } }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...