Submission #897914

#TimeUsernameProblemLanguageResultExecution timeMemory
897914avighnaOlympic Bus (JOI20_ho_t4)C++17
0 / 100
1047 ms5456 KiB
#include <bits/stdc++.h> using namespace std; #define ll long long const ll N = 201, M = 50001; ll n, m; multiset<pair<ll, ll>> adj[N]; ll c[M], d[M]; pair<ll, ll> edges[M]; vector<ll> sssp(ll source) { vector<ll> dist(n + 1, 1e15); dist[source] = 0; priority_queue<pair<ll, ll>> pq; pq.push({0, source}); while (!pq.empty()) { ll node = pq.top().second, _dist = -pq.top().first; pq.pop(); for (auto &nb : adj[node]) { if (dist[nb.first] > _dist + c[nb.second]) { dist[nb.first] = _dist + c[nb.second]; pq.push({-dist[nb.first], nb.first}); } } } return dist; } int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); cin >> n >> m; for (ll i = 1; i <= n; ++i) { adj[i].clear(); } vector<vector<ll>> dist(n + 1, vector<ll>(n + 1, 1e15)); for (ll i = 1; i <= n; ++i) { dist[i][i] = 0; } for (ll i = 0, u, v; i < m; ++i) { cin >> u >> v >> c[i] >> d[i]; adj[u].insert({v, i}); edges[i] = {u, v}; dist[u][v] = min(dist[u][v], c[i]); } for (ll a = 1; a <= n; ++a) { for (ll b = 1; b <= n; ++b) { for (ll c = 1; c <= n; ++c) { dist[a][c] = min(dist[a][c], dist[a][b] + dist[b][c]); } } } ll ans = min((ll)1e15, dist[1][n] + dist[n][1]); for (ll i = 0; i < m; ++i) { ll u = edges[i].first, v = edges[i].second; if (min(dist[1][n], dist[1][v] + c[i] + dist[u][n]) + min(dist[n][1], dist[n][v] + c[i] + dist[u][1]) + d[i] < ans || true) { adj[u].erase(adj[u].find({v, i})); adj[v].insert({u, i}); ans = min(ans, sssp(1)[n] + sssp(n)[1] + d[i]); adj[v].erase(adj[v].find({u, i})); adj[u].insert({v, i}); } } if (ans == (ll)1e15) { 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...