제출 #749190

#제출 시각아이디문제언어결과실행 시간메모리
749190hafoCommuter Pass (JOI18_commuter_pass)C++14
0 / 100
291 ms29408 KiB
#include <bits/stdc++.h> #define ll long long #define ull unsigned ll #define pb push_back #define pa pair<int, int> #define pall pair<ll, int> #define fi first #define se second #define TASK "test" #define all(x) x.begin(), x.end() using namespace std; template<typename T1, typename T2> bool mini (T1 &a, T2 b) {if(a > b) a = b; else return 0; return 1;} template<typename T1, typename T2> bool maxi (T1 &a, T2 b) {if(a < b) a = b; else return 0; return 1;} const int MOD = 1e9 + 7; const int LOG = 20; const int maxn = 2e5 + 7; const ll oo = 1e18 + 69; int n, m, u, v, w, s, t, a, b; ll f[4][maxn], ans, dp[2][maxn]; vector<pa> g[maxn]; vector<int> adj[2][maxn]; void dijkstra(int s, int id) { fill_n(f[id], n + 1, oo); f[id][s] = 0; priority_queue<pall, vector<pall>, greater<pall>> q; q.push({0, s}); while(!q.empty()) { int u = q.top().se; ll fu = q.top().fi; q.pop(); if(f[id][u] != fu) continue; for(auto e:g[u]) { int v = e.fi, w = e.se; if(mini(f[id][v], fu + w)) { q.push({fu + w, v}); } } } } void dfs(int u, int id) { dp[id][u] = f[2][u]; for(auto v:adj[id][u]) { if(dp[id][v] == -1) dfs(v, id); mini(dp[id][u], dp[id][v]); } } int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); //freopen(TASK".inp", "r", stdin); //freopen(TASK".out", "w", stdout); cin>>n>>m>>s>>t>>a>>b; while(m--) { cin>>u>>v>>w; g[u].pb({v, w}); g[v].pb({u, w}); } dijkstra(s, 0); dijkstra(a, 1); dijkstra(b, 2); dijkstra(t, 3); ans = f[1][b]; for(int u = 1; u <= n; u++) { for(auto e:g[u]) { int v = e.fi, w = e.se; if(f[0][u] + w + f[3][v] == f[0][t]) { adj[0][u].pb(v); adj[1][v].pb(u); } } } for(int i = 0; i < 2; i++) for(int j = 1; j <= n; j++) dp[i][j] = -1; dfs(s, 0); dfs(t, 1); for(int i = 1; i <= n; i++) { if(dp[0][u] == -1) continue; mini(ans, f[1][i] + min(dp[0][i], dp[1][i])); } 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...