Submission #1049491

#TimeUsernameProblemLanguageResultExecution timeMemory
1049491avighnaRelay Marathon (NOI20_relaymarathon)C++17
5 / 100
6079 ms1048576 KiB
#include <bits/stdc++.h> typedef long long ll; const ll inf = 1e15; int main() { std::ios_base::sync_with_stdio(false); std::cin.tie(nullptr); ll n, m, k; std::cin >> n >> m >> k; std::vector<std::vector<std::pair<ll, ll>>> adj(n + 1); for (ll i = 0, u, v, w; i < m; ++i) { std::cin >> u >> v >> w; adj[u].push_back({v, w}); adj[v].push_back({u, w}); } std::vector<ll> A(k); std::vector<bool> special(n + 1); for (auto &i : A) { std::cin >> i; special[i] = true; } auto sssp = [&](ll x) { std::priority_queue<std::pair<ll, ll>> pq; pq.push({0, x}); std::vector<ll> ans(n + 1, inf); std::vector<bool> vis(n + 1); ans[x] = 0; while (!pq.empty()) { ll node = pq.top().second, d = -pq.top().first; pq.pop(); if (vis[node]) { continue; } vis[node] = true; for (auto &[i, dist] : adj[node]) { if (d + dist < ans[i]) { ans[i] = d + dist; pq.push({-ans[i], i}); } } } return ans; }; std::vector<std::vector<ll>> dist(n + 1); std::vector<std::multiset<ll>> sets(n + 1); for (ll i = 1; i <= n; ++i) { dist[i] = sssp(i); for (ll j = 1; j <= n; ++j) { if (i == j or !special[j]) { continue; } sets[i].insert(dist[i][j]); } } ll ans = inf; for (ll p_a = 0; p_a < k; ++p_a) { for (ll p_b = p_a + 1; p_b < k; ++p_b) { for (ll p_c = p_b + 1; p_c < k; ++p_c) { ll a = A[p_a], b = A[p_b], c = A[p_c]; sets[c].erase(sets[c].find(dist[c][a])); sets[c].erase(sets[c].find(dist[c][b])); if (!sets[c].empty()) { ans = std::min(ans, dist[a][b] + *sets[c].begin()); } sets[c].insert(dist[c][a]); sets[c].insert(dist[c][b]); } } } std::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...