Submission #502466

#TimeUsernameProblemLanguageResultExecution timeMemory
502466zoriankaCommuter Pass (JOI18_commuter_pass)C++17
16 / 100
609 ms30828 KiB
//#pragma GCC optimize("O3") #include <bits/stdc++.h> using namespace std; #define MAXN 100005 #define MAXM 100005 #define mix(a, b) a = min(a,b) using ll = long long; const ll mod = 1e9 + 7; vector<pair<int, ll>> g[MAXN]; vector<pair<int, ll>> gc[MAXN]; vector<ll> ds, dt; ll st; void dijkstra(vector<ll> &dist, int s) { dist[s] = 0; set<pair<ll, int>> q; q.insert({0, s}); while (!q.empty()) { int v = q.begin()->second; q.erase(q.begin()); for (auto[u, c] : g[v]) { if (dist[v] + c < dist[u]) { q.erase({dist[u], u}); dist[u] = dist[v] + c; q.insert({dist[u], u}); } } } } void spec(vector<ll> &dist, int s) { dist[s] = 0; set<pair<ll, int>> q; q.insert({0, s}); vector<bool> flex(dist.size(), false); flex[s] = true; while (!q.empty()) { int v = q.begin()->second; q.erase(q.begin()); for (auto[u, c] : g[v]) { if (ds[v] < ds[u] && flex[v]) if (ds[v] + c + dt[u] == st) c = 0; if (dist[v] + c < dist[u]) { q.erase({dist[u], u}); dist[u] = dist[v] + c; if (c == 0) flex[u] = true; q.insert({dist[u], u}); } } } } void solve() { int n, m; cin >> n >> m; int s, t; cin >> s >> t; int u, v; cin >> u >> v; for (int i = 0; i < m; i++) { int a, b, c; cin >> a >> b >> c; g[a].emplace_back(b, c); g[b].emplace_back(a, c); gc[a].emplace_back(b, c); gc[b].emplace_back(a, c); } ds.resize(n + 1, 1e18), dt.resize(n + 1, 1e18); dijkstra(ds, s); dijkstra(dt, t); st = ds[t]; vector<ll> bebra(n + 1, 1e18); spec(bebra, u); ll ans = bebra[v]; bebra.assign(n + 1, 1e18); spec(bebra, v); ans = min(ans, bebra[u]); cout << ans; } signed main() { #ifdef LOCAL freopen("input.txt", "r", stdin); #endif ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); int t = 1; // cin >> t; while (t--) solve(); 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...