제출 #891236

#제출 시각아이디문제언어결과실행 시간메모리
891236Mr_EllCommuter Pass (JOI18_commuter_pass)C++17
0 / 100
123 ms16464 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 = LLONG_MAX, 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 = 1e5 + 1; vector<pair<ll, ll>> g[MAXN]; ll dp[MAXN][2]; void dijkstra(vector<ll> &d, int 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}); } } } } void solve() { int n, m, s, t, u, v; cin >> n >> m >> s >> t >> u >> v; for (int i = 0; i < n; ++i) { int a, b, w; cin >> a >> b >> w; g[a].push_back({b, w}); g[b].push_back({a, w}); } vector<ll> du(n + 1), dv(n + 1), ds(n + 1), dt(n + 1); dijkstra(du, u); dijkstra(dv, v); dijkstra(ds, s); dijkstra(dt, t); vector<ll> flex(n); iota(flex.begin(), flex.end(), 1ll); sort(flex.begin(), flex.end(), [&](int a, int b) { return ds[a] < ds[b]; }); fill(dp[0], dp[0] + MAXN * 2, INF); dp[s][0] = ds[u]; dp[s][1] = ds[v]; for (int i = 0; i < n; ++i) { int a = flex[i]; if (dp[a][0] == INF) { continue; } for (auto [b, w] : g[a]) { if (dt[b] + w + ds[a] == ds[t]) { dp[b][0] = min(dp[a][0], du[b]); dp[b][1] = min(dp[a][1], dv[b]); } } } ll ans = dv[u]; for (int i = 1; i <= n; ++i) { if (dp[i][0] == INF) { continue; } 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); int 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) * (int) 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...