제출 #298774

#제출 시각아이디문제언어결과실행 시간메모리
298774HynDufCommuter Pass (JOI18_commuter_pass)C++14
100 / 100
457 ms21844 KiB
#include <bits/stdc++.h> #define task "C" #define all(v) (v).begin(), (v).end() #define rep(i, l, r) for (int i = (l); i <= (r); ++i) #define Rep(i, r, l) for (int i = (r); i >= (l); --i) #define DB(X) { cerr << #X << " = " << (X) << '\n'; } #define DB1(A, _) { cerr << #A << "[" << _ << "] = " << (A[_]) << '\n'; } #define DB2(A, _, __) { cerr << #A << "[" << _ << "][" << __ << "] = " << (A[_][__]) << '\n'; } #define DB3(A, _, __, ___) { cerr << #A << "[" << _ << "][" << __ << "][" << ___ << "] = " << (A[_][__][___]) << '\n'; } #define PR(A, l, r) { cerr << '\n'; rep(_, l, r) DB1(A, _); cerr << '\n';} #define SZ(x) ((int)(x).size()) #define pb push_back #define eb emplace_back #define pf push_front #define F first #define S second #define by(x) [](const auto& a, const auto& b) { return a.x < b.x; } // sort(arr, arr + N, by(a)); #define next ___next #define prev ___prev #define y1 ___y1 #define left ___left #define right ___right #define y0 ___y0 #define div ___div #define j0 ___j0 #define jn ___jn using ll = long long; using ld = long double; using ull = unsigned long long; using namespace std; typedef pair<ll, int> ii; typedef pair<ii, int> iii; typedef vector<int> vi; typedef vector<ii> vii; typedef vector<ll> vl; const int N = 1e5 + 2; const ll INF = 1e18; int n, m, S, T, U, V; ll dp[N], ans; vii g[N]; vl dS, dT, dU, dV; void dij(int r, vl &d) { d.assign(n + 1, INF); d[r] = 0; priority_queue<ii, vii, greater<ii> > pq; pq.push({0, r}); while (!pq.empty()) { int u = pq.top().S; ll du = pq.top().F; pq.pop(); if (du != d[u]) continue; for (ii v : g[u]) if (d[v.F] > du + v.S) { d[v.F] = du + v.S; pq.push({d[v.F], v.F}); } } } bool in[N]; void updDP1(int u) { in[u] = 1; dp[u] = dV[u]; for (ii v : g[u]) if (dS[u] + v.S + dT[v.F] == dS[T]) { if (!in[v.F]) updDP1(v.F); dp[u] = min(dp[u], dp[v.F]); } ans = min(ans, dU[u] + dp[u]); } void updDP(int u) { in[u] = 1; dp[u] = dV[u]; for (ii v : g[u]) if (dT[u] + v.S + dS[v.F] == dS[T]) { if (!in[v.F]) updDP(v.F); dp[u] = min(dp[u], dp[v.F]); } ans = min(ans, dU[u] + dp[u]); } int main() { #ifdef HynDuf freopen(task".in", "r", stdin); //freopen(task".out", "w", stdout); #else ios_base::sync_with_stdio(false); cin.tie(nullptr); #endif cin >> n >> m >> S >> T >> U >> V; rep(i, 1, m) { int u, v, w; cin >> u >> v >> w; g[u].eb(v, w); g[v].eb(u, w); } dij(S, dS); dij(T, dT); dij(U, dU); dij(V, dV); ans = dU[V]; updDP(T); fill(in + 1, in + 1 + n, 0); updDP1(S); 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...