Submission #858870

#TimeUsernameProblemLanguageResultExecution timeMemory
858870themaver1cksCommuter Pass (JOI18_commuter_pass)C++14
100 / 100
392 ms15752 KiB
#include <bits/stdc++.h> using namespace std; int main() { cin.tie(nullptr)->sync_with_stdio(false); int n, m; cin >> n >> m; int S, T, U, V; cin >> S >> T >> U >> V, S--, T--, U--, V--; vector<vector<pair<int, int>>> g(n); for (int i = 0; i < m; ++i) { int u, v, w; cin >> u >> v >> w, u--, v--; g[u].emplace_back(v, w); g[v].emplace_back(u, w); } auto dijkstra = [&](int s) { vector<long long> dist(n, 1e18); priority_queue<pair<long long, int>> pq; dist[s] = 0; pq.emplace(0, s); while (pq.size()) { auto d = -pq.top().first; auto u = pq.top().second; pq.pop(); if (d > dist[u]) continue; for (auto [v, w] : g[u]) { if (dist[v] > dist[u] + w) { dist[v] = dist[u] + w; pq.emplace(-dist[v], v); } } } return dist; }; auto solve = [&](int S, int T) { auto fromS = dijkstra(S); auto fromT = dijkstra(T); auto fromU = dijkstra(U); auto fromV = dijkstra(V); vector<long long> f(n, 1e18); // thứ tự quy hoạch động? // f[y] cập nhật cho f[x] // fromS[y] < fromS[x] vector<int> order(n); iota(order.begin(), order.end(), 0); sort(order.begin(), order.end(), [&](int x, int y) { return fromS[x] < fromS[y]; }); long long ans = fromU[V]; for (auto u : order) { f[u] = min(f[u], fromU[u]); for (auto [v, w] : g[u]) { if (fromS[u] + w == fromS[v] && fromS[u] + w + fromT[v] == fromS[T]) { f[v] = min(f[v], f[u]); } } if (fromS[u] + fromT[u] == fromS[T]) { ans = min(ans, f[u] + fromV[u]); } } return ans; }; cout << min(solve(S, T), solve(T, S)) << endl; return 0; }

Compilation message (stderr)

commuter_pass.cpp: In lambda function:
commuter_pass.cpp:29:17: warning: structured bindings only available with '-std=c++17' or '-std=gnu++17'
   29 |       for (auto [v, w] : g[u]) {
      |                 ^
commuter_pass.cpp: In lambda function:
commuter_pass.cpp:56:17: warning: structured bindings only available with '-std=c++17' or '-std=gnu++17'
   56 |       for (auto [v, w] : g[u]) {
      |                 ^
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...