Submission #1093788

#TimeUsernameProblemLanguageResultExecution timeMemory
1093788vjudge1Commuter Pass (JOI18_commuter_pass)C++17
100 / 100
411 ms29536 KiB
#include<bits/stdc++.h> #define int long long #define fi first #define se second #define pb push_back #define ii pair<int, int> #define sz(v) (int)v.size() #define all(v) v.begin(), v.end() using namespace std; const int N=1e5+5, mod = 1e9+7, inf = 1e18; int n, m, s, t, u, v; vector<ii> adj[N]; vector<int> du, dv, ds; int mxu[N], mxv[N], ans; bool vis[N]; void cal(int src, vector<int>& d) { for (int i=1; i<=n; i++) vis[i] = 0; priority_queue<ii, vector<ii>, greater<ii>> pq; pq.push({0, src}); while(!pq.empty()) { int dist = pq.top().fi, tmp = pq.top().se; pq.pop(); if(!vis[tmp]) { d[tmp] = dist; vis[tmp] = 1; for (ii i: adj[tmp]) pq.push({dist+i.se, i.fi}); } } } void cal_(int src, int des) { for (int i=0; i<=n; i++) { vis[i] = 0; mxu[i] = mxv[i] = inf; } priority_queue<pair<int, ii>> pq; pq.push({0, {src, 0}}); while(!pq.empty()) { int dist = pq.top().fi, tmp = pq.top().se.fi, p = pq.top().se.se; pq.pop(); if(!vis[tmp]) { vis[tmp] = 1; ds[tmp] = -dist; mxu[tmp] = min(du[tmp], mxu[p]); mxv[tmp] = min(dv[tmp], mxv[p]); for (ii i : adj[tmp]) pq.push({dist-i.second, {i.first, tmp}}); } else if(-dist == ds[tmp]) { if(min(du[tmp], mxu[p])+min(dv[tmp], mxv[p])<=mxu[tmp]+mxv[tmp]) { mxu[tmp] = min(du[tmp], mxu[p]); mxv[tmp] = min(dv[tmp], mxv[p]); } } } ans = min(ans, mxu[des] + mxv[des]); } signed main() { // freopen("tmp.inp", "r", stdin); // freopen("tmp.out", "w", stdout); ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); cin >> n >> m >> s >> t >> u >> v; while(m--) { int a, b, c; cin >> a >> b >> c; adj[a].pb({b, c}); adj[b].pb({a, c}); } du.resize(n+1); dv.resize(n+1); ds.resize(n+1); cal(u, du); cal(v, dv); ans = du[v]; cal_(s, t); swap(s, t); cal_(s, t); cout << ans; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...