Submission #1049550

# Submission time Handle Problem Language Result Execution time Memory
1049550 2024-08-08T22:31:26 Z avighna Relay Marathon (NOI20_relaymarathon) C++17
25 / 100
773 ms 247840 KB
#include <bits/stdc++.h>

typedef long long ll;

const ll inf = 1e15;

struct Edge {
  ll u, v, w;
};

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);
  std::vector<Edge> edges;
  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});
    edges.push_back({u, v, w});
  }
  std::vector<ll> A(k);
  std::vector<bool> special(n + 1);
  std::priority_queue<std::pair<ll, std::pair<ll, ll>>> pq;
  std::vector<ll> d(n + 1, inf);
  for (auto &i : A) {
    std::cin >> i;
    special[i] = true;
    pq.push({0, {i, i}});
    d[i] = 0;
  }

  std::vector<std::pair<ll, ll>> closest_special(n + 1);
  std::vector<bool> vis(n + 1);
  while (!pq.empty()) {
    ll node = pq.top().second.first, source = pq.top().second.second,
       dist = -pq.top().first;
    pq.pop();
    if (vis[node]) {
      continue;
    }
    vis[node] = true;
    closest_special[node] = {source, dist};
    for (auto &[i, i_d] : adj[node]) {
      if (dist + i_d < d[i]) {
        d[i] = dist + i_d;
        pq.push({-d[i], {i, source}});
      }
    }
  }

  ll ans = inf;
  for (auto &[u, v, w] : edges) {
    if (u != 1 and u != 2 and v != 1 and v != 2 and special[u] and special[v]) {
      ans = std::min(ans, w);
    }
  }
  for (auto &[u, v, w] : edges) {
    if (u == 1 or u == 2 or v == 1 or v == 2) {
      continue;
    }
    if (closest_special[u].first != closest_special[v].first) {
      ans = std::min(ans,
                     closest_special[u].second + w + closest_special[v].second);
    }
  }
  std::cout << ans + 1 << '\n';
}
# Verdict Execution time Memory Grader output
1 Incorrect 0 ms 348 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 0 ms 348 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 28 ms 11716 KB Output is correct
2 Correct 3 ms 5980 KB Output is correct
3 Correct 740 ms 242284 KB Output is correct
4 Correct 312 ms 103148 KB Output is correct
5 Correct 63 ms 23548 KB Output is correct
6 Correct 49 ms 19716 KB Output is correct
7 Correct 98 ms 25856 KB Output is correct
8 Correct 27 ms 12544 KB Output is correct
9 Correct 46 ms 17412 KB Output is correct
10 Correct 34 ms 13984 KB Output is correct
11 Correct 727 ms 243140 KB Output is correct
12 Correct 39 ms 14692 KB Output is correct
13 Correct 195 ms 63316 KB Output is correct
14 Correct 83 ms 27132 KB Output is correct
15 Correct 732 ms 242904 KB Output is correct
16 Correct 21 ms 10756 KB Output is correct
17 Correct 489 ms 162984 KB Output is correct
18 Correct 4 ms 6036 KB Output is correct
19 Correct 773 ms 247840 KB Output is correct
20 Correct 69 ms 24320 KB Output is correct
21 Correct 63 ms 21992 KB Output is correct
22 Correct 32 ms 14088 KB Output is correct
23 Correct 12 ms 8972 KB Output is correct
24 Correct 551 ms 175060 KB Output is correct
25 Correct 49 ms 17668 KB Output is correct
26 Correct 26 ms 12044 KB Output is correct
27 Correct 39 ms 16140 KB Output is correct
28 Correct 7 ms 7356 KB Output is correct
29 Correct 73 ms 26084 KB Output is correct
30 Correct 157 ms 50780 KB Output is correct
# Verdict Execution time Memory Grader output
1 Incorrect 0 ms 348 KB Output isn't correct
2 Halted 0 ms 0 KB -