Submission #897915

#TimeUsernameProblemLanguageResultExecution timeMemory
897915avighnaOlympic Bus (JOI20_ho_t4)C++17
5 / 100
1074 ms5468 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 = 1e15; ans = min(ans, sssp(1)[n] + sssp(n)[1]); for (ll i = 0; i < m; ++i) { adj[edges[i].first].erase(adj[edges[i].first].find({edges[i].second, i})); adj[edges[i].second].insert({edges[i].first, i}); ans = min(ans, d[i] + sssp(1)[n] + sssp(n)[1]); adj[edges[i].second].erase(adj[edges[i].second].find({edges[i].first, i})); adj[edges[i].first].insert({edges[i].second, 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...