제출 #891717

#제출 시각아이디문제언어결과실행 시간메모리
891717Mr_EllCommuter Pass (JOI18_commuter_pass)C++17
100 / 100
301 ms35836 KiB
#ifdef LOCAL #define _GLIBCXX_DEBUG #endif #include <bits/stdc++.h> using namespace std; using ll = long long; using ld = long double; const ll INF = 1e18, MOD = 1e9 + 7, P = 239; const ld PI = 3.1415926535897938462643383279502, EPS = 1e-7; template <typename T> inline ll sz(const T &a) { return a.size(); } template <typename T, typename C> istream &operator >> (istream &in, pair<T, C> &a) { return in >> a.first >> a.second; } template <typename T, typename C> ostream &operator << (ostream &out, pair<T, C> a) { return out << a.first << ' ' << a.second; } template <typename T> istream & operator >> (istream &in, vector<T> &a) { for (auto &i : a) { in >> i; } return in; } template <typename T> ostream &operator << (ostream &out, vector<T> a) { for (auto i : a) { out << i << ' '; } return out; } template <typename T> void prnt(vector<T> a, string c = "\n") { for (T i : a) { cout << i << c; } } const ll MAXN = 2e5 + 1; vector<pair<ll, ll>> g[MAXN]; ll dp[MAXN][2]; void dijkstra(vector<ll> &d, ll start) { fill(d.begin(), d.end(), INF); set<pair<ll, ll>> q; q.insert({0, start}); d[start] = 0; while (!q.empty()) { auto [dist, v] = *q.begin(); q.erase(q.begin()); if (dist > d[v]) { continue; } for (auto [u, w] : g[v]) { if (d[u] > d[v] + w) { d[u] = d[v] + w; q.insert({d[u], u}); } } } } vector<ll> g2[MAXN], order; bitset<MAXN> used, good; vector<ll> du, dv; void dfs(ll v) { used[v] = 1; dp[v][0] = du[v]; dp[v][1] = dv[v]; for (auto u : g2[v]) { if (!used[u]) { dfs(u); } dp[v][0] = min(dp[u][0], dp[v][0]); dp[v][1] = min(dp[u][1], dp[v][1]); } order.push_back(v); } void solve() { ll n, m, s, t, u, v; cin >> n >> m >> s >> t >> u >> v; for (ll i = 0; i < m; ++i) { ll a, b, w; cin >> a >> b >> w; g[a].push_back({b, w}); g[b].push_back({a, w}); } vector<ll> ds(n + 1), dt(n + 1); du.resize(n + 1); dv.resize(n + 1); dijkstra(du, u); dijkstra(dv, v); dijkstra(ds, s); dijkstra(dt, t); for (ll i = 1; i <= n; ++i) { if (ds[i] + dt[i] == ds[t]) { good[i] = 1; } } for (ll i = 1; i <= n; ++i) { if (!good[i]) { continue; } for (auto [j, w] : g[i]) { if (good[j] && ds[i] + w + dt[j] == ds[t]) { g2[i].push_back(j); } } } fill(dp[0], dp[0] + MAXN * 2, INF); dfs(s); // std::reverse(order.begin(), order.end()); // // dp[s][0] = ds[u]; // dp[s][1] = ds[v]; // for (auto i : order) { // for (auto j : g2[i]) { // dp[j][0] = min(dp[i][0], du[j]); // dp[j][1] = min(dp[i][1], dv[j]); // } // } ll ans = dv[u]; for (ll i = 1; i <= n; ++i) { ans = min(ans, min(dp[i][0] + dv[i], dp[i][1] + du[i])); } cout << ans; } signed main() { #ifdef LOCAL freopen("inp.txt", "r", stdin); freopen("out.txt", "w", stdout); freopen("err.txt", "w", stderr); auto start_time = clock(); #endif ios_base::sync_with_stdio(false); cin.tie(nullptr); ll times = 1; // cin >> times; while (times--) solve(), cout << '\n'; #ifdef LOCAL auto end_time = clock(); cerr << setprecision(3) << fixed << "Execution time: " << (end_time - start_time) * (ll) 1e3 / CLOCKS_PER_SEC << " ms\n"; #endif 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...