Submission #1049500

#TimeUsernameProblemLanguageResultExecution timeMemory
1049500avighnaRelay Marathon (NOI20_relaymarathon)C++17
17 / 100
4455 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::vector<std::pair<ll, ll>>> sorted_dists(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; } sorted_dists[i].push_back({dist[i][j], j}); } std::sort(sorted_dists[i].begin(), sorted_dists[i].end()); } 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]; ll ptr = 0; while (ptr < sorted_dists[c].size() and (sorted_dists[c][ptr].second == a or sorted_dists[c][ptr].second == b)) { ptr++; } if (ptr < sorted_dists[c].size()) { ans = std::min(ans, dist[a][b] + sorted_dists[c][ptr].first); } } } } std::cout << ans << '\n'; }

Compilation message (stderr)

RelayMarathon.cpp: In function 'int main()':
RelayMarathon.cpp:68:20: warning: comparison of integer expressions of different signedness: 'll' {aka 'long long int'} and 'std::vector<std::pair<long long int, long long int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   68 |         while (ptr < sorted_dists[c].size() and
      |                ~~~~^~~~~~~~~~~~~~~~~~~~~~~~
RelayMarathon.cpp:73:17: warning: comparison of integer expressions of different signedness: 'll' {aka 'long long int'} and 'std::vector<std::pair<long long int, long long int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   73 |         if (ptr < sorted_dists[c].size()) {
      |             ~~~~^~~~~~~~~~~~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...