Submission #956253

#TimeUsernameProblemLanguageResultExecution timeMemory
956253samvar_0907Olympic Bus (JOI20_ho_t4)C++17
0 / 100
38 ms9804 KiB
#include<bits/stdc++.h> using namespace std; #define int long long const int N = 201, M = 40001; int n, m; multiset<pair<int, int>> adj[N]; int c[M], d[M]; pair<int, int> edges[M]; vector<int> dijkstra(int source){ vector<int> dist(n + 1, 1e15); priority_queue<pair<int, int>, vector<pair<int, int>>, greater<pair<int, int>>> pq; pq.push({0, source}); dist[source] = 0; while (!pq.empty()) { int u = pq.top().second; int d = pq.top().first; pq.pop(); for (auto &n : adj[u]){ if (dist[n.first] > d + c[n.second]){ dist[n.first] = d + c[n.second]; pq.push({dist[n.first], n.first}); } } } return dist; } signed main(){ cin >> n >> m; for (int i = 1; i <= n; ++i) { adj[i].clear(); } vector<vector<int>> dist(n + 1, vector<int>(n + 1, 1e15)); for (int i = 1; i <= n; ++i) { dist[i][i] = 0; } for (int i = 0; i < m; ++i){ int u, v; 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]); } // Floyd Warshall for (int k = 1; k <= n; ++k) { for (int i = 1; i <= n; ++i) { for (int j = 1; j <= n; ++j) { dist[i][j] = min(dist[i][j], dist[i][k] + dist[k][j]); } } } int ans = min(ans, dist[1][n] + dist[n][1]); for (int i = 0; i < m; ++i) { int 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) { adj[u].erase(adj[u].find({v, i})); adj[v].insert({u, i}); ans = min(ans, d[i] + dijkstra(1)[n] + dijkstra(n)[1]); adj[v].erase(adj[v].find({edges[i].first, i})); adj[u].insert({v, i}); } } if (ans == (int)(1e15)) { ans = -1; } cout << ans; }

Compilation message (stderr)

ho_t4.cpp: In function 'int main()':
ho_t4.cpp:60:9: warning: 'ans' may be used uninitialized in this function [-Wmaybe-uninitialized]
   60 |     int ans = min(ans, dist[1][n] + dist[n][1]);
      |         ^~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...