제출 #203845

#제출 시각아이디문제언어결과실행 시간메모리
203845staniewzkiOlympic Bus (JOI20_ho_t4)C++17
0 / 100
1095 ms2040 KiB
#include<bits/stdc++.h> using namespace std; ostream& operator<<(ostream &out, string str) { for(char c : str) out << c; return out; } template<class L, class R> ostream& operator<<(ostream &out, pair<L, R> p) { return out << "(" << p.first << ", " << p.second << ")"; } template<class T> auto operator<<(ostream &out, T a) -> decltype(a.begin(), out) { out << "{"; for(auto it = a.begin(); it != a.end(); it = next(it)) out << (it != a.begin() ? ", " : "") << *it; return out << "}"; } void dump() { cerr << "\n"; } template<class T, class... Ts> void dump(T a, Ts... x) { cerr << a << ", "; dump(x...); } #ifdef DEBUG # define debug(...) cerr << "[" #__VA_ARGS__ "]: ", dump(__VA_ARGS__) #else # define debug(...) false #endif #define REP(i, n) for(int i = 0; i < n; i++) #define FOR(i, a, b) for(int i = a; i <= b; i++) #define ST first #define ND second template<class T> int size(T && a) { return a.size(); } using LL = long long; using PII = pair<int, int>; int main() { ios_base::sync_with_stdio(0); cin.tie(0); int n, m; cin >> n >> m; vector<int> a(m), b(m), c(m), d(m); vector<vector<int>> g(n), r(n); REP(i, m) { cin >> a[i] >> b[i] >> c[i] >> d[i]; a[i]--, b[i]--; g[a[i]].emplace_back(i); r[b[i]].emplace_back(i); } vector<bool> on_path(m); auto dijkstra = [&](vector<vector<int>> &adj, int source, int banned) { vector<int> dst(n, 1e9); priority_queue<PII> Q; dst[source] = 0; Q.emplace(0, source); while(!Q.empty()) { int d, v; tie(d, v) = Q.top(); Q.pop(); if(-d != dst[v]) continue; for(int e : adj[v]) { if(banned == e) continue; int u = (a[e] == v ? b[e] : a[e]); if(dst[u] > dst[v] + c[e]) { dst[u] = dst[v] + c[e]; Q.emplace(-dst[u], u); } } } return dst; }; auto add_edge = [&](int i) { g[b[i]].emplace_back(size(a)); r[a[i]].emplace_back(size(a)); a.emplace_back(b[i]); b.emplace_back(a[i]); c.emplace_back(c[i]); }; auto pop_edge = [&](int i) { g[b[i]].pop_back(); r[a[i]].pop_back(); a.pop_back(); b.pop_back(); c.pop_back(); }; int ans = dijkstra(g, 0, -1)[n - 1] + dijkstra(g, n - 1, -1)[0]; REP(i, m) { add_edge(i); auto source = dijkstra(g, 0, i); auto sink = dijkstra(g, n - 1, i); ans = min(ans, source[n - 1] + sink[0] + d[i]); pop_edge(i); } if(ans >= 1e9) ans = -1; cout << ans << "\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...