Submission #833457

#TimeUsernameProblemLanguageResultExecution timeMemory
833457vjudge1Commuter Pass (JOI18_commuter_pass)C++17
0 / 100
485 ms27704 KiB
#include <bits/stdc++.h> using namespace std; #define ll long long #define pll pair<long long, long long> const ll inf = 1e18; const int maxn = 100005; // const int maxn = 50; int n, m, s, t, u, v; pll dist[maxn]; // <parent, dist> priority_queue<pll, vector<pll>, greater<pll>> pq; map<int, int> adj[maxn]; int main() { for (int i = 0; i < maxn; i++) { dist[i] = {-1, inf}; } cin >> n >> m >> s >> t >> u >> v; for (int i = 0; i < m; i++) { ll a, b, c; cin >> a >> b >> c; adj[a][b] = c; adj[b][a] = c; } pq.push({0, s}); dist[s] = {s, 0}; while (!pq.empty()) { auto [currdist, idx] = pq.top(); for (auto [b, c] : adj[idx]) { if (currdist + c < dist[b].second) { // potential? dist[b] = {idx, currdist + c}; pq.push({currdist+c, b}); } } pq.pop(); } int x = t; while (x != s) { adj[x][dist[x].first] = 0; adj[dist[x].first][x] = 0; x = dist[x].first; } for (int i = 0; i < maxn; i++) { dist[i] = {-1, inf}; } pq.push({0, u}); dist[u] = {u, 0}; while (!pq.empty()) { auto [currdist, idx] = pq.top(); for (auto [b, c] : adj[idx]) { if (currdist + c < dist[b].second) { // potential? dist[b] = {idx, currdist + c}; pq.push({currdist+c, b}); } } pq.pop(); } cout << dist[v].second << 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...