Submission #98606

#TimeUsernameProblemLanguageResultExecution timeMemory
98606WLZCommuter Pass (JOI18_commuter_pass)C++17
0 / 100
561 ms21184 KiB
#include <bits/stdc++.h> using namespace std; const long long INF = (long long) 1e18; template<typename T> struct edge { int from, to; T cost; }; void calc(int s, vector<long long>& dist, vector<long long>& dp, const vector<long long>& dist2, const vector< vector< edge<long long> > >& g) { dp.assign((int) g.size(), INF); dp[s] = dist2[s]; priority_queue< pair<long long, int>, vector< pair<long long, int> >, greater< pair<long long, int> > > pq; pq.push({0, s}); dist.assign((int) g.size(), INF); dist[s] = 0; while (!pq.empty()) { long long d = pq.top().first; int u = pq.top().second; pq.pop(); if (d > dist[u]) { continue; } for (auto& v : g[u]) { if (d + v.cost < dist[v.to]) { dist[v.to] = d + v.cost; pq.push({dist[v.to], v.to}); dp[v.to] = min({dp[v.to], dp[u], dist2[v.to]}); } } } } int main() { ios::sync_with_stdio(false); cin.tie(0); int n, m, s, t, u, v; cin >> n >> m >> s >> t >> u >> v; vector< vector< edge<long long> > > g(n + 1); for (int i = 0; i < m; i++) { int a, b; long long c; cin >> a >> b >> c; g[a].push_back({a, b, c}); g[b].push_back({b, a, c}); } vector<long long> dist1(n + 1), dist2, dist3, dist4; vector<long long> dp1, dp2; calc(u, dist1, dp1, dist1, g); calc(v, dist2, dp1, dist1, g); calc(s, dist3, dp1, dist2, g); calc(t, dist4, dp2, dist2, g); long long ans = INF; for (int i = 1; i <= n; i++) { if (dist3[i] + dist4[i] == dist3[t]) { ans = min(ans, dist1[i] + min(dp1[i], dp2[i])); } } cout << min(ans, dist1[v]) << '\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...