Submission #915942

#TimeUsernameProblemLanguageResultExecution timeMemory
915942GithubCommuter Pass (JOI18_commuter_pass)C++17
31 / 100
347 ms25312 KiB
#include <iostream> #include <vector> #include <queue> #include <cstring> #include <map> #include <climits> #include <cmath> #include <set> #include <algorithm> #include <stack> using namespace std; #define speedup ios_base::sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr); #define ll long long vector<ll> distU, distV; vector<vector<pair<int, ll>>> graph; int n, m; int s, t; int u, v; vector<ll> dijstra(int st){ vector<ll> dist(n, 1e15); dist[st] = 0; priority_queue<pair<ll, int>, vector<pair<ll, int>>, greater<pair<ll, int>>> pq; pq.push({0, st}); vector<bool> vis(n, false); while (!pq.empty()){ int c = pq.top().second; pq.pop(); vis[c] = true; for (pair<int, ll> p: graph[c]){ if (!vis[p.first] && dist[p.first] > dist[c]+p.second){ dist[p.first] = dist[c]+p.second; pq.push({dist[p.first], p.first}); } } } return dist; } ll dijstra2(int start, int end){ vector<ll> dU(n, 1e15), dV(n, 1e15); vector<ll> dist(n, 1e15); priority_queue<pair<ll, pair<int, int>>, vector<pair<ll, pair<int, int>>>, greater<pair<ll, pair<int, int>>>> pq; pq.push({0, {start, 0}}); dist[start] = 0; vector<bool> vis(n, false); while (!pq.empty()){ ll cdist = pq.top().first; int cur = pq.top().second.first, par = pq.top().second.second; pq.pop(); if (!vis[cur]){ vis[cur] = true; dist[cur] = cdist; dU[cur] = min(distU[cur], dU[par]); dV[cur] = min(distV[cur], dV[par]); for (pair<int, ll> p: graph[cur]){ pq.push({cdist+p.second, {p.first, cur}}); } }else if (cdist == dist[cur] && min(dU[par], distU[cur])+min(dV[par], distV[cur]) <= dU[cur]+dV[cur]){ dU[cur] = min(dU[cur], dU[par]); dV[cur] = min(dV[cur], dV[par]); } } return dU[end]+dV[end]; } int main(){ speedup cin >> n >> m; cin >> s >> t; cin >> u >> v; graph.resize(n); s--, t--, u--, v--; for (int i = 0; i < m; i++){ ll a, b, w; cin >> a >> b >> w; a--, b--; graph[a].push_back({b, w}); graph[b].push_back({a, w}); } distU = dijstra(u); distV = dijstra(v); ll a1 = dijstra2(s, t); ll a2 = dijstra2(t, s); cout << min(distU[v], min(a1, a2)) << endl; 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...