Submission #369300

#TimeUsernameProblemLanguageResultExecution timeMemory
369300Lam_lai_cuoc_doiCommuter Pass (JOI18_commuter_pass)C++17
100 / 100
347 ms23020 KiB
#include <bits/stdc++.h> using namespace std; using ll = long long; using ld = long double; using ull = unsigned long long; const bool typetest = 0; const int N = 1e5 + 5; const ll Inf = 1e17; int n, m, s, t, u, v, id[N]; vector<pair<int, ll>> adj[N]; ll d[4][N], dp[N][3]; void Read() { cin >> n >> m >> s >> t >> u >> v; for (int i = 1; i <= m; ++i) { int x, y, w; cin >> x >> y >> w; adj[x].push_back({y, w}); adj[y].push_back({x, w}); } } void Dijkstra(int x, ll d[N]) { fill_n(d, N, Inf); d[x] = 0; struct Tque { int v; ll w; Tque(const int &v, const ll &w) : v(v), w(w) { } bool operator<(const Tque &a) const { return w > a.w; } }; priority_queue<Tque> s; s.push({x, 0}); while (s.size()) { Tque c = s.top(); s.pop(); if (d[c.v] != c.w) continue; for (auto i : adj[c.v]) if (d[i.first] > c.w + i.second) { d[i.first] = c.w + i.second; s.push({i.first, d[i.first]}); } } } void Solve() { Dijkstra(s, d[1]); Dijkstra(u, d[2]); Dijkstra(v, d[3]); for (int i = 1; i <= n; ++i) id[i] = i; sort(id + 1, id + n + 1, [&](const int &x, const int &y) { return d[1][x] < d[1][y]; }); fill_n(&dp[0][0], N * 3, Inf); for (int i = 1; i <= n; ++i) { dp[id[i]][0] = d[2][id[i]]; dp[id[i]][1] = d[3][id[i]]; for (auto j : adj[id[i]]) if (d[1][j.first] + j.second == d[1][id[i]]) { dp[id[i]][0] = min(dp[j.first][0], dp[id[i]][0]); dp[id[i]][1] = min(dp[j.first][1], dp[id[i]][1]); dp[id[i]][2] = min(dp[j.first][2], dp[id[i]][2]); } dp[id[i]][2] = min(dp[id[i]][2], min(dp[id[i]][0] + d[3][id[i]], dp[id[i]][1] + d[2][id[i]])); } cout << min(dp[t][2], d[2][v]); } int32_t main() { ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); int t(1); if (typetest) cin >> t; for (int _ = 1; _ <= t; ++_) { Read(); Solve(); } }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...