Submission #600536

#TimeUsernameProblemLanguageResultExecution timeMemory
600536vbeeCommuter Pass (JOI18_commuter_pass)C++14
100 / 100
328 ms20240 KiB
#include <bits/stdc++.h> #define fi first #define se second #define all(r) (r).begin(), (r).end() #define MASK(i) (1 << (i)) #define BIT(x, i) ((x) >> (i) & 1) #define ll long long #define pb push_back #define TASK "task" using namespace std; template <typename T1, typename T2> bool minimize(T1 &a, T2 b){ if (a > b) {a = b; return true;} return false;} template <typename T1, typename T2> bool maximize(T1 &a, T2 b){if (a < b) {a = b; return true;} return false;} const int oo = 1e9 + 7; const ll loo = (ll)1e18 + 7; const int LOG = 18; const int BASE = 323; const int N = 1e5 + 7; int n, m, s, t, u, v; ll du[N], dv[N], ds[N], dp[2][N], ans; vector<pair<int, int> > g[N]; void dijkstra1(int start, ll arr[]){ priority_queue<pair<ll, ll>, vector<pair<ll, ll>>, greater<pair<ll, ll>> > kew; kew.push({0, start}); for (int i = 1; i <= n; i++) arr[i] = loo; arr[start] = 0; while (!kew.empty()){ auto k = kew.top(); kew.pop(); if (arr[k.se] < k.fi) continue; for (auto u : g[k.se]){ if (u.se + k.fi < arr[u.fi]){ arr[u.fi] = u.se + k.fi; kew.push({arr[u.fi], u.fi}); } } } } void dijkstra2(int start, int end){ fill(dp[0], dp[0] + N - 1, loo); fill(dp[1], dp[1] + N - 1, loo); fill(ds, ds + N - 1, loo); priority_queue<pair<ll, ll>, vector<pair<ll, ll> >, greater<pair<ll, ll>> > kew; kew.push({0, start}); dp[0][start] = du[start]; dp[1][start] = dv[start]; while (!kew.empty()){ auto k = kew.top(); kew.pop(); if (ds[k.se] < k.fi) continue; for (auto u : g[k.se]){ if (u.se + k.fi < ds[u.fi]){ ds[u.fi] = u.se + k.fi; dp[0][u.fi] = min(du[u.fi], dp[0][k.se]); dp[1][u.fi] = min(dv[u.fi], dp[1][k.se]); kew.push({ds[u.fi], u.fi}); } else if (u.se + k.fi == ds[u.fi]){ if (min(du[u.fi], dp[0][k.se]) + min(dv[u.fi], dp[1][k.se]) <= dp[0][u.fi] + dp[1][u.fi]){ dp[0][u.fi] = min(du[u.fi], dp[0][k.se]); dp[1][u.fi] = min(dv[u.fi], dp[1][k.se]); } } } } minimize(ans, dp[0][end] + dp[1][end]); } int main(){ ios_base::sync_with_stdio(0); cin.tie(0); // freopen(TASK".inp", "r", stdin); // freopen(TASK".out", "w", stdout); cin >> n >> m >> s >> t >> u >> v; for (int i = 1; i <= m; i++){ int a, b, c; cin >> a >> b >> c; g[a].pb({b, c}); g[b].pb({a, c}); } dijkstra1(u, du); dijkstra1(v, dv); ans = du[v]; dijkstra2(s, t); dijkstra2(t, s); // for (int i = 1; i <= n; i++){ // cout << du[i] << " " << dv[i] << " " << ds[i] << "\n"; // } 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...