Submission #207828

#TimeUsernameProblemLanguageResultExecution timeMemory
207828opukittpceno_hhrCommuter Pass (JOI18_commuter_pass)C++17
31 / 100
638 ms32364 KiB
#include <iostream> #include <vector> #include <map> #include <set> #include <queue> #include <algorithm> #include <string> #include <cmath> #include <cstdio> #include <iomanip> #include <fstream> #include <cassert> #include <cstring> #include <unordered_set> #include <unordered_map> #include <numeric> #include <ctime> #include <bitset> #include <complex> #include <random> using namespace std; #define int long long const int N = 1e5 + 7; const int INF = 1e18 + 239; int n; vector<pair<int, int>> g[N]; vector<int> dj(int st) { vector<int> d(n, INF); set<pair<int, int>> s; d[st] = 0; s.insert({d[st], st}); while (!s.empty()) { int v = s.begin()->second; s.erase(s.begin()); for (auto [u, w] : g[v]) { if (d[u] > d[v] + w) { s.erase({d[u], u}); d[u] = d[v] + w; s.insert({d[u], u}); } } } return d; } vector<pair<int, int>> ng[N]; vector<int> dj2(int st) { vector<int> d(n, INF); set<pair<int, int>> s; d[st] = 0; s.insert({d[st], st}); while (!s.empty()) { int v = s.begin()->second; s.erase(s.begin()); for (auto [u, w] : ng[v]) { if (d[u] > d[v] + w) { s.erase({d[u], u}); d[u] = d[v] + w; s.insert({d[u], u}); } } } return d; } vector<int> ds; vector<int> dt; int s, t; void init() { ds = dj(s); dt = dj(t); // cout << ds[t] << endl; for (int i = 0; i < n; i++) { for (auto [u, w] : g[i]) { if (ds[i] + w + dt[u] == ds[t]) { ng[i].push_back({u, 0}); } else { ng[i].push_back({u, w}); } } } } int solve(int u, int v) { vector<int> du = dj2(u); return du[v]; } signed main() { ios_base::sync_with_stdio(false); cin.tie(0); int m; cin >> n >> m; int u, v; cin >> s >> t >> u >> v; s--; t--; u--; v--; while (m--) { int a, b, c; cin >> a >> b >> c; a--; b--; g[a].push_back({b, c}); g[b].push_back({a, c}); } init(); int ans = min(solve(u, v), solve(v, u)); cout << ans << endl; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...