Submission #1043796

#TimeUsernameProblemLanguageResultExecution timeMemory
1043796fauzCommuter Pass (JOI18_commuter_pass)C++14
31 / 100
209 ms33728 KiB
#include <bits/stdc++.h> #define fi first #define se second #define int long long using namespace std; const int MAXN = 200005; typedef pair<int, int> II; int n, m, s, t, u, v, w[MAXN]; long long d[MAXN]; vector<II> g[MAXN], prv[MAXN]; set<II> q; void dijk(int a, int b) { fill(d + 1, d + n + 1, LLONG_MAX); q.clear(); q.insert(II(0, a)); d[a] = 0; while (!q.empty()) { int x = q.begin()->se; q.erase(q.begin()); for (II node : g[x]) { int y = node.fi, id = node.se; if (d[y] > d[x] + w[id]) { if (d[y] < LLONG_MAX) q.erase(II(d[y], y)); prv[y].clear(); prv[y].push_back(II(x, id)); d[y] = d[x] + w[id]; q.insert(II(d[y], y)); } else if (d[y] == d[x] + w[id]) prv[y].push_back(II(x, id)); } } } bool clear[MAXN]; int32_t main() { ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); cin >> n >> m >> s >> t >> u >> v; for (int i = 1; i <= m; ++i) { int a, b, c; cin >> a >> b >> c; w[i] = c; g[a].push_back(II(b, i)); g[b].push_back(II(a, i)); } dijk(s, t); vector<int> T; T.push_back(t); fill(clear + 1, clear + n + 1, false); while (!T.empty()) { int i = T.back(); T.pop_back(); if (clear[i]) continue; clear[i] = true; for (II node : prv[i]) { w[node.se] = 0; T.push_back(node.fi); } } dijk(u, v); cout << d[v]; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...