Submission #869682

#TimeUsernameProblemLanguageResultExecution timeMemory
869682sleepntsheepCommuter Pass (JOI18_commuter_pass)C++17
15 / 100
366 ms35156 KiB
#include <iostream> #include <stack> #include <cstring> #include <vector> #include <algorithm> #include <deque> #include <set> #include <utility> #include <array> #pragma GCC optimize("Ofast,unroll-loops") #pragma GCC target("avx2,tune=native") using namespace std; #define ALL(x) x.begin(), x.end() #define ShinLena cin.tie(nullptr)->sync_with_stdio(false); using ll = long long; #define N 200005 int n, m, s, t, cs, ct, head[N], e, se, shead[N], is[N]; struct edge { int w, v, next; } g[N<<1], sg[N<<1]; ll dp_s[N], dp_t[N], dp_cs[N], dp_ct[N], dp_art[N], ans = 1e18; void add_edge(int u, int v, int w, struct edge *g, int *e, int *h) { int p = (*e)++; g[p] = {w, v, h[u]}; h[u] = p; } void add_biedge(int u, int v, int w, struct edge *g, int *e, int *h) { add_edge(u, v, w, g, e, h), add_edge(v, u, w, g, e, h); } void dijkstra(ll *d, int s) { set<pair<ll, int>> h; for (h.emplace(d[s] = 0, s); h.size(); ) { auto [c, u] = *h.begin(); h.erase(h.begin()); for (auto i = head[u]; i != -1; i = g[i].next) { auto [w, v, _] = g[i]; if (c + w < d[v]) h.erase({d[v], v}), h.emplace(d[v] = c + w, v); } } } void dijkstra(ll *d) { set<pair<ll, int>> h; for (int u = 1; u <= n; ++u) if (d[u] == 0) h.emplace(d[u] = 0, u); for (; h.size(); ) { auto [c, u] = *h.begin(); h.erase(h.begin()); for (auto i = head[u]; i != -1; i = g[i].next) { auto [w, v, _] = g[i]; if (c + w < d[v]) h.erase({d[v], v}), h.emplace(d[v] = c + w, v); } } } void init() { memset(dp_s, 63, sizeof dp_s); memset(dp_t, 63, sizeof dp_t); memset(dp_cs, 63, sizeof dp_cs); memset(dp_ct, 63, sizeof dp_ct); memset(dp_art, 63, sizeof dp_art); memset(head, -1, sizeof head); memset(shead, -1, sizeof shead); ShinLena; cin >> n >> m >> s >> t >> cs >> ct; for (int u, v, w, i = 0; i < m; ++i) cin >> u >> v >> w, add_biedge(u, v, w, g, &e, head); } void build_shortest_path_graph() { dijkstra(dp_s, s); dijkstra(dp_t, t); for (int u = 1; u <= n; ++u) { for (int j = head[u]; j != -1; j = g[j].next) { auto [w, v, _] = g[j]; if (dp_s[u] + dp_t[v] + w == dp_s[t] || w + dp_s[v] + dp_t[u] == dp_s[t]) add_biedge(u, v, w, sg, &se, shead), is[u] = is[v] = 1; } } } int low[N], tin[N], timer = 1, art[N<<1], as; void dfs(int u, int p) { low[u] = tin[u] = timer++; for (auto j = shead[u]; j != -1; j = sg[j].next) { auto [w, v, _] = sg[j]; if (v == p) continue; if (tin[v]) low[u] = min(low[u], tin[v]); else { dfs(v, u), low[u] = min(low[u], low[v]); if (low[v] == tin[u] + 1) dp_art[v] = 0; } } } void find_path() { dijkstra(dp_cs, cs); dijkstra(dp_ct, ct); dijkstra(dp_art); ll d1 = 1e18, d2 = 1e18; for (int u = 1; u <= n; ++u) if (is[u]) d1 = min(d1, dp_cs[u]), d2 = min(d2, dp_ct[u]); if (dp_s[cs] + dp_t[ct] + dp_cs[ct] == dp_s[t] || dp_s[ct] + dp_t[cs] + dp_cs[ct] == dp_s[t]) ans = 0; ans = min(ans, dp_cs[ct]); for (int u = 1; u <= n; ++u) ans = min(ans, min(dp_art[u] + dp_cs[u] + d2, dp_art[u] + dp_ct[u] + d1)); } int main() { init(); build_shortest_path_graph(); dfs(s, s); find_path(); cout << ans; 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...