제출 #1046459

#제출 시각아이디문제언어결과실행 시간메모리
1046459inkvizytorCommuter Pass (JOI18_commuter_pass)C++17
0 / 100
172 ms22616 KiB
#include <bits/stdc++.h> using namespace std; #define ll long long #define pli pair<ll, int> #define fi first #define se second ll MAX = 1e18; int main() { //ios_base::sync_with_stdio(0); //cin.tie(0); int n, m, s, t, u, v; cin >> n >> m >> s >> t >> u >> v; vector<vector<pli>> g (n+1); for (int i = 0; i < m; i++) { int a, b; ll c; cin >> a >> b >> c; g[a].push_back({c, b}); g[b].push_back({c, a}); } vector<ll> lu(n+1, -1), lv(n+1, -1), ls(n+1, -1); lu[u] = 0; lv[v] = 0; ls[s] = 0; priority_queue<pli, vector<pli>, greater<pli>> pq; pq.push({0, u}); while (!pq.empty()) { pli x = pq.top(); pq.pop(); for (pli y : g[x.se]) { if (lu[y.se] == -1) { lu[y.se] = x.fi+y.fi; pq.push({lu[y.se], y.se}); } } } pq.push({0, v}); while (!pq.empty()) { pli x = pq.top(); pq.pop(); for (pli y : g[x.se]) { if (lv[y.se] == -1) { lv[y.se] = x.fi+y.fi; pq.push({lv[y.se], y.se}); } } } vector<ll> mu(n+1, MAX), mv(n+1, MAX); mu[s] = lu[s]; mv[s] = lv[s]; pq.push({0, s}); vector<ll> score(n+1, MAX); while (!pq.empty()) { pli x = pq.top(); pq.pop(); score[x.se] = min(score[x.se], min(mv[x.se]+lu[x.se], mu[x.se]+lv[x.se])); for (pli y : g[x.se]) { if (ls[y.se] == -1) { ls[y.se] = x.fi+y.fi; mu[y.se] = min(mu[x.se], lu[y.se]); mv[y.se] = min(mv[x.se], lv[y.se]); score[y.se] = min(score[x.se], min(mu[y.se]+lv[y.se], mv[y.se]+lu[y.se])); pq.push({ls[y.se], y.se}); } else if (x.fi+y.fi == ls[y.se]) { mu[y.se] = min(mu[x.se], mu[y.se]); mv[y.se] = min(mv[x.se], mv[y.se]); score[y.se] = min(mu[y.se]+lv[y.se], mv[y.se]+lu[y.se]); } } } cout << min(score[t], lu[v]) << '\n'; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...