제출 #331578

#제출 시각아이디문제언어결과실행 시간메모리
331578syyOlympic Bus (JOI20_ho_t4)C++17
0 / 100
83 ms6764 KiB
#include <bits/stdc++.h> using namespace std; typedef long long ll; typedef long double ld; #define FOR(i, a, b) for(ll i = (ll)a; i <= (ll)b; i++) #define DEC(i, a, b) for(ll i = (ll)a; i >= (ll)b; i--) typedef pair<ll, ll> pi; typedef pair<pi, ll> pii; typedef pair<ll, pi> ipi; typedef pair<pi, pi> pipi; #define f first #define s second typedef vector<ll> vi; typedef vector<pi> vpi; typedef vector<pii> vpii; #define pb push_back #define pf push_front #define all(v) v.begin(), v.end() #define size(v) (ll) v.size() #define disc(v) sort(all(v)); v.resize(unique(all(v)) - v.begin()); #define INF (ll) 1e9 + 100 #define LLINF (ll) 1e15 #define fastio ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0) #define sandybridge __attribute__((optimize("Ofast"), target("arch=sandybridge"))) mt19937 rng(chrono::steady_clock::now().time_since_epoch().count()); //can be used by calling rng() or shuffle(A, A+n, rng) inline ll rand(ll x, ll y) { ++y; return (rng() % (y-x)) + x; } //inclusivesss ll n, m, a, b, c, d, dist[2][205], ndist[2][205], ans, path[2][205]; pipi edge[50005]; vpii adj[205], radj[205]; priority_queue<pi, vpi, greater<pi>> pq; void setpath() { FOR(i, 1, n) dist[0][i] = LLINF; dist[0][1] = 0; pq.push(pi(0, 1)); while (!pq.empty()) { auto [d, x] = pq.top(); pq.pop(); if (d > dist[0][x]) continue; for (auto [t, idx]:adj[x]) { auto [it, nd] = t; if (dist[0][it] > d + nd) { dist[0][it] = d + nd; path[0][it] = idx; pq.push(pi(d + nd, it)); } } } FOR(i, 1, n) dist[1][i] = LLINF; dist[1][n] = 0; pq.push(pi(0, n)); while (!pq.empty()) { auto [d, x] = pq.top(); pq.pop(); if (d > dist[1][x]) continue; for (auto [t, idx]:adj[x]) { auto [it, nd] = t; if (dist[1][it] > d + nd) { dist[1][it] = d + nd; path[1][it] = idx; pq.push(pi(d + nd, it)); } } } } void dijkstra(bool b, ll flip) { FOR(i, 1, n) ndist[b][i] = LLINF; dist[b][(b ? n : 1)] = 0; pq.push(pi(0, (b ? n : 1))); while (!pq.empty()) { auto [d, x] = pq.top(); pq.pop(); if (d > ndist[b][x]) continue; for (auto [t, idx]:adj[x]) { auto [it, nd] = t; if (idx == flip) continue; if (ndist[b][it] > d + nd) { ndist[b][it] = d + nd; pq.push(pi(d + nd, it)); } } if (x == edge[flip].f.s) { ll it = edge[flip].f.f, nd = edge[flip].s.f; if (ndist[b][it] > d + nd) { ndist[b][it] = d + nd; pq.push(pi(d + nd, it)); } } } } int main() { fastio; cin >> n >> m; FOR(i, 1, m) { cin >> a >> b >> c >> d; adj[a].pb(pii(pi(b, c), i)); radj[b].pb(pii(pi(a, c), i)); edge[i] = pipi(pi(a, b), pi(c, d)); } setpath(); ans = dist[0][n] + dist[1][1]; FOR(i, 1, m) { auto [t, tt] = edge[i]; auto [a, b] = t; auto [c, d] = tt; ll res = d; if (path[0][b] == i) { dijkstra(0, i); res += ndist[0][n]; } else res += min(dist[0][n], dist[0][b] + c + dist[1][a]); if (path[1][b] == i) { dijkstra(1, i); res += ndist[1][1]; } else res += min(dist[1][1], dist[1][b] + c + dist[0][a]); ans = min(ans, res); } cout << (ans >= LLINF ? -1 : ans); }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...