제출 #684501

#제출 시각아이디문제언어결과실행 시간메모리
684501JooDdaeCommuter Pass (JOI18_commuter_pass)C++17
15 / 100
305 ms23736 KiB
#include <bits/stdc++.h> using namespace std; using ll = long long; const ll INF = 1e18; int n, m, S, T, U, V; vector<array<int, 2>> v[100100]; ll d[100100]; bool chk[100100]; priority_queue<array<ll, 2>> pq; ll d2[100100][4]; priority_queue<array<ll, 3>> pq2; void dfs(int u) { assert(!chk[u]); chk[u] = 1; for(auto [x, y] : v[u]) if(d[u]-y == d[x]) dfs(x); } int main(){ cin.tie(0)->sync_with_stdio(0); cin >> n >> m >> S >> T >> U >> V; for(int i=1;i<=m;i++) { int a, b, c; cin >> a >> b >> c; v[a].push_back({b, c}), v[b].push_back({a, c}); } fill(d+1, d+1+n, INF); d[S] = 0, pq.push({0, S}); while(!pq.empty()) { auto [c, u] = pq.top(); pq.pop(); if(-c > d[u]) continue; for(auto [x, y] : v[u]) if(y-c < d[x]) d[x] = y-c, pq.push({c-y, x}); } dfs(T); for(int i=1;i<=n;i++) d2[i][0] = d2[i][1] = d2[i][2] = d2[i][3] = INF; d2[U][0] = 0, pq2.push({0, U, 0}); while(!pq2.empty()) { auto [c, u, t] = pq2.top(); pq2.pop(); if(-c > d2[u][t]) continue; if(u == V) return cout << -c, 0; if(t < 3 && chk[u]) for(auto [x, y] : v[u]) if(chk[x] && abs(d[x]-d[u]) == y){ if(t == 1 && d[x] > d[u]) continue; if(t == 2 && d[x] < d[u]) continue; ll T = d[x] > d[u] ? 2 : 1; if(-c < d2[x][T]) d2[x][T] = -c, pq2.push({c, x, T}); } for(auto [x, y] : v[u]) { ll D = y-c, T = t ? 3 : 0; if(D < d2[x][T]) d2[x][T] = D, pq2.push({-D, x, T}); } } }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...