답안 #261634

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
261634 2020-08-11T23:12:21 Z Haunted_Cpp Relay Marathon (NOI20_relaymarathon) C++17
25 / 100
1953 ms 72188 KB
/**
 *  author: Haunted_Cpp
**/
 
#include <bits/stdc++.h>
using namespace std;
 
#pragma GCC optimize("Ofast")
#pragma GCC target("fma,sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,avx2,tune=native")
#pragma GCC optimize("unroll-loops")
 
template<typename T> ostream &operator << (ostream &os, const vector<T> &v) { os << '{'; string sep; for (const auto &x : v) os << sep << x, sep = ", "; return os << '}'; }
template<typename T, size_t size> ostream &operator << (ostream &os, const array<T, size> &arr) { os << '{'; string sep; for (const auto &x : arr) os << sep << x, sep = ", "; return os << '}'; }
template<typename A, typename B> ostream &operator << (ostream &os, const pair<A, B> &p) { return os << '(' << p.first << ", " << p.second << ')'; }
 
void debug_out() { cerr << endl; }
template<typename Head, typename... Tail> void debug_out(Head H, Tail... T) { cerr << ' ' << H; debug_out(T...); }
 
#ifdef LOCAL
#define debug(...) cerr << "(" << #__VA_ARGS__ << "):", debug_out(__VA_ARGS__)
#else
#define debug(...) 47
#endif

const int MAX_N = 1e5 + 5;
const int INF = 1e9 + 5;

vector<vector<pair<int, int>>> g(MAX_N);

int main () {
  ios::sync_with_stdio(0);
  cin.tie(0);
  int n, m, k;
  cin >> n >> m >> k;
  for (int i = 0; i < m; i++) {
    int st, et, w;
    cin >> st >> et >> w;
    --st; --et;
    g[st].emplace_back(et, w);
    g[et].emplace_back(st, w);
  }
  vector<bool> is_special(n);
  for (int i = 0; i < k; i++) {
    int foo;
    cin >> foo;
    --foo;
    is_special[foo] = true;
  }
  int res = 0;
  auto Dijkstra = [&]() {
    priority_queue<pair<int, int>, vector<pair<int, int>>, greater<pair<int, int>>> pq;
    vector<int> dist(n, INF);
    vector<int> root(n, -1);
    vector<pair<int, int>> closest_vertex(n, {INF, -1});
    for (int i = 0; i < n; i++) {
      if (is_special[i]) {
        dist[i] = 0;
        root[i] = i;
        pq.push({dist[i], i});
      }
    }
    while(!pq.empty()) {
      int node = pq.top().second;
      int w = pq.top().first;
      pq.pop();
      if (w != dist[node]) continue;
      for (auto to : g[node]) {
        if (root[to.first] != -1 && root[to.first] != root[node]) {
          pair<int, int> best_way = {dist[node] + to.second + dist[to.first], root[to.first]};
          closest_vertex[root[node]] = min(closest_vertex[root[node]], best_way);
        }
        if (dist[to.first] > dist[node] + to.second) {
          dist[to.first] = dist[node] + to.second;
          root[to.first] = root[node];
          pq.push({dist[to.first], to.first});
        }
      }
    }
    int mn = 1e9;
    for (int i = 0; i < n; i++) {
      if (!is_special[i]) continue;
      mn = min(mn, closest_vertex[i].first);
    }
    for (int i = 0; i < n; i++) {
      if (!is_special[i]) continue;
      if (closest_vertex[i].first == mn) {
        res += closest_vertex[i].first;
        is_special[i] = false;
        is_special[closest_vertex[i].second] = false;
        return;
      }
    }
  };
  Dijkstra();
  Dijkstra();
  cout << res << '\n';
  return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Incorrect 2 ms 2688 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 2 ms 2688 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 87 ms 7352 KB Output is correct
2 Correct 11 ms 4864 KB Output is correct
3 Correct 1688 ms 64208 KB Output is correct
4 Correct 748 ms 33572 KB Output is correct
5 Correct 193 ms 10988 KB Output is correct
6 Correct 154 ms 9444 KB Output is correct
7 Correct 221 ms 11572 KB Output is correct
8 Correct 78 ms 7416 KB Output is correct
9 Correct 145 ms 9104 KB Output is correct
10 Correct 102 ms 7928 KB Output is correct
11 Correct 1906 ms 67828 KB Output is correct
12 Correct 141 ms 8368 KB Output is correct
13 Correct 520 ms 21772 KB Output is correct
14 Correct 258 ms 11812 KB Output is correct
15 Correct 1744 ms 66808 KB Output is correct
16 Correct 57 ms 7032 KB Output is correct
17 Correct 1230 ms 51440 KB Output is correct
18 Correct 10 ms 4960 KB Output is correct
19 Correct 1953 ms 72188 KB Output is correct
20 Correct 210 ms 11180 KB Output is correct
21 Correct 185 ms 10516 KB Output is correct
22 Correct 111 ms 7788 KB Output is correct
23 Correct 28 ms 6488 KB Output is correct
24 Correct 1267 ms 55268 KB Output is correct
25 Correct 185 ms 9356 KB Output is correct
26 Correct 90 ms 7416 KB Output is correct
27 Correct 138 ms 8652 KB Output is correct
28 Correct 19 ms 5760 KB Output is correct
29 Correct 239 ms 11336 KB Output is correct
30 Correct 425 ms 18392 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Incorrect 2 ms 2688 KB Output isn't correct
2 Halted 0 ms 0 KB -