Submission #820016

#TimeUsernameProblemLanguageResultExecution timeMemory
820016vjudge1Olympic Bus (JOI20_ho_t4)C++17
11 / 100
19 ms4116 KiB
#include<bits/stdc++.h> using namespace std; using ll = long long; const int N = 1000; const int M = 100000; const ll INF = 1e18; int n, m; vector<pair<int, int>> g[N], g0[N]; ll C[M], D[M]; pair<int, int> edges[M]; vector<ll> dijkstra(int s, vector<pair<int, int>> g[]) { vector<ll> dist(n + 1, INF); dist[s] = 0; set<pair<ll, int>> st; for(int i = 1; i <= n; i++) st.insert({dist[i], i}); while(!st.empty()) { s = st.begin()->second; st.erase(st.begin()); for(auto [to, i] : g[s]) { if(dist[to] > dist[s] + C[i]) { st.erase({dist[to], to}); dist[to] = dist[s] + C[i]; st.insert({dist[to], to}); } } } return dist; } int main() { ios::sync_with_stdio(0); cin.tie(0);cout.tie(0); cin >> n >> m; for(int i = 0; i < m; i++) { int u, v; cin >> u >> v; edges[i] = {u, v}; cin >> C[i] >> D[i]; g[u].push_back({v, i}); g0[v].push_back({u, i}); } auto d1 = dijkstra(1, g); auto dn = dijkstra(n, g); auto e1 = dijkstra(1, g0); auto en = dijkstra(n, g0); ll res = d1[n] + dn[1]; for(int i = 0; i < m; i++) { auto [u, v] = edges[i]; res = min(res, d1[v] + en[u] + dn[1] + C[i] + D[i]); res = min(res, dn[v] + e1[u] + d1[n] + C[i] + D[i]); res = min(res, d1[v] + en[u] + dn[v] + e1[u] + 2 * C[i] + D[i]); } if(res >= INF) res = -1; cout << res; 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...