제출 #844993

#제출 시각아이디문제언어결과실행 시간메모리
844993gtm7Commuter Pass (JOI18_commuter_pass)C++17
100 / 100
197 ms20404 KiB
#include <bits/stdc++.h> using namespace std; const long long mx = 100000000000000000; void dijkstra(int ss, vector<pair<int, int>> adj[], vector<int> &arr, vector<long long> &d) { using T = pair<long long, int>; priority_queue<T, vector<T>, greater<T>> q; q.push({0, ss}); d[ss] = 0; long long s, cd; while (!q.empty()) { s = q.top().second; cd = q.top().first; q.pop(); if (cd > d[s]) continue; arr.push_back(s); for (auto x : adj[s]) { if (d[x.first] > d[s] + x.second) { d[x.first] = d[s] + x.second; q.push({d[x.first], x.first}); } } } } int main() { ios_base::sync_with_stdio(false); cin.tie(nullptr); int n, m, ss, tt, u, v; cin >> n >> m >> ss >> tt >> u >> v; ss--, tt--, u--, v--; int a, b, c; vector<pair<int, int>> adj[n]; for (int i = 0; i < m; i++) { cin >> a >> b >> c; adj[a - 1].push_back({b - 1, c}); adj[b - 1].push_back({a - 1, c}); } long long vd, ud; vector<long long> du(n, mx); vector<long long> dv(n, mx); vector<long long> dsum(n); vector<long long> d(n, mx); vector<int> brr; vector<int> arr; dijkstra(u, adj, brr, du); dijkstra(v, adj, brr, dv); dijkstra(ss, adj, arr, d); for (int i = 0; i < n; i++) { dsum[i] = du[i] + dv[i]; } long long ans = dsum[v]; for (auto i : arr) { vd = dv[i]; ud = du[i]; for (auto x : adj[i]) { if (d[i] == d[x.first] + x.second) { du[i] = min(du[i], du[x.first]); dv[i] = min(dv[i], dv[x.first]); } } dsum[i] = min(du[i] + vd, dv[i] + ud); for (auto x : adj[i]) { if (d[i] == d[x.first] + x.second) { dsum[i] = min(dsum[i], dsum[x.first]); } } } ans = min(ans, dsum[tt]); cout << ans << "\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...