Submission #1324234

#TimeUsernameProblemLanguageResultExecution timeMemory
1324234riafhasan2010Commuter Pass (JOI18_commuter_pass)C++20
0 / 100
78 ms11324 KiB
#include <bits/stdc++.h> using namespace std; typedef long long ll; const ll inf = 1e17; int main() { ios::sync_with_stdio(0); cin.tie(0); int n, m; cin >> n >> m; int s, t, u, v; cin >> s >> t >> u >> v; vector<pair<int, int>> g[n + 1]; for (int i = 1; i <= m; i++) { int a, b, c; cin >> a >> b >> c; g[a].push_back({b, c}); g[b].push_back({a, c}); } vector<int> path(n + 1, 0); vector<ll> st(n + 1, inf); priority_queue<pair<ll, int>, vector<pair<ll, int>>, greater<pair<ll, int>>> pq; pq.push({0, s}); st[s] = 0; while (!pq.empty()) { auto [w, a] = pq.top(); pq.pop(); for (auto [b, c] : g[a]) { if (st[b] == inf) { pq.push({1ll * w + c, b}); } if (1ll * w + c < st[b]) { st[b] = 1ll * w + c; path[b] = a; } } } map<pair<int, int>, bool> mp; for (int i = t; path[i]; i = path[i]) { mp[{i, path[i]}] = 1; mp[{path[i], i}] = 1; } for (int i = 1; i <= n; i++) st[i] = inf; pq.push({0, u}); st[u] = 0; while (!pq.empty()) { auto [w, a] = pq.top(); pq.pop(); for (auto [b, c] : g[a]) { if (mp[{a, b}] or mp[{b, a}]) c = 0; if (1ll * w + c < st[b]) { st[b] = 1ll * w + c; } } } cout << st[v] << '\n'; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...