제출 #502472

#제출 시각아이디문제언어결과실행 시간메모리
502472zoriankaCommuter Pass (JOI18_commuter_pass)C++17
100 / 100
716 ms36632 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<int> flex(dist.size(), false); vector<int> parent(dist.size(), -1); parent[s] = s; while (!q.empty()) { int v = q.begin()->second; q.erase(q.begin()); if (flex[v] == 0 && flex[parent[v]] != 0) flex[v] = 2; for (auto[u, c] : g[v]) { if (ds[v] < ds[u] && flex[v] != 2) 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; parent[u] = v; 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...