Submission #898235

#TimeUsernameProblemLanguageResultExecution timeMemory
898235oviyan_gandhiOlympic Bus (JOI20_ho_t4)C++14
0 / 100
2 ms604 KiB
#pragma GCC optimize("Ofast") #include <bits/stdc++.h> using namespace std; const int INF = 1e9; typedef pair<int, int> pii; #define MAXN 200 #define MAXM 50000 struct Edge { int u, v, c, d; }; int n, m; Edge edges[MAXM]; list<int> adj[MAXN]; int dist[MAXN][MAXN]; int dis[MAXN]; int cost(int s, int t, int ri){ fill(dis, dis+n, INF); priority_queue<pii> pq; pq.push({0, s}); dis[s] = 0; while (!pq.empty()){ auto [d, u] = pq.top(); pq.pop(); if (dis[u] != d) continue; if (ri != -1 && edges[ri].v == u){ int v = edges[ri].u, cd = edges[ri].c; if (d + cd < dis[v]){ dis[v] = d + cd; pq.push({dis[v], v}); } } for (int i : adj[u]){ if (i == ri) continue; int v = edges[i].v, cd = edges[i].c; if (d + cd < dis[v]){ dis[v] = d + cd; pq.push({dis[v], v}); } } } return dis[t]; } int cost(int ri = -1){ return cost(0, n-1, ri) + cost(n-1, 0, ri); } int32_t main(){ freopen("sol.in", "r", stdin); ios_base::sync_with_stdio(false); cin.tie(NULL); cin >> n >> m; for (int i = 0; i < n; i++){ for (int j = 0; j < n; j++) dist[i][j] = INF; dist[i][i] = 0; } for (int i = 0; i < m; i++){ auto &[u, v, c, d] = edges[i]; cin >> u >> v >> c >> d; u--, v--; adj[u].push_back(i); dist[u][v] = min(dist[u][v], c); } for (int k = 0; k < n; k++) for (int i = 0; i < n; i++) for (int j = 0; j < n; j++) dist[i][j] = min(dist[i][j], dist[i][k] + dist[k][j]); int ans = cost(); for (int i = 0; i < m; i++){ auto [u, v, c, d] = edges[i]; int fw = min(dist[0][n-1], dist[0][v] + c + dist[u][n-1]), bw = min(dist[n-1][0], dist[n-1][v] + c + dist[u][0]); if (fw < INF && bw < INF && (fw + bw + d) < ans) ans = min(ans, cost(i) + d); } cout << (ans >= INF ? -1 : ans) << '\n'; return 0; }

Compilation message (stderr)

ho_t4.cpp: In function 'int cost(int, int, int)':
ho_t4.cpp:25:14: warning: structured bindings only available with '-std=c++17' or '-std=gnu++17'
   25 |         auto [d, u] = pq.top();
      |              ^
ho_t4.cpp: In function 'int32_t main()':
ho_t4.cpp:60:15: warning: structured bindings only available with '-std=c++17' or '-std=gnu++17'
   60 |         auto &[u, v, c, d] = edges[i];
      |               ^
ho_t4.cpp:72:14: warning: structured bindings only available with '-std=c++17' or '-std=gnu++17'
   72 |         auto [u, v, c, d] = edges[i];
      |              ^
ho_t4.cpp:50:12: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   50 |     freopen("sol.in", "r", stdin);
      |     ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...