답안 #670831

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
670831 2022-12-10T19:00:21 Z dattranxxx Relay Marathon (NOI20_relaymarathon) C++11
25 / 100
1330 ms 133860 KB
#include<bits/stdc++.h>
using namespace std;
using ll = long long;

#define int ll

const int N = 1e5 + 5, inf = 1e16;
vector<pair<int, int>> adj[N];
int special[N];
int n, m, k;

priority_queue<pair<int, int>> q;
int dis[N], src[N];

pair<int, int> dijkstra(int s) {
  memset(dis, 0x3f, sizeof(dis));
  q.emplace(0, s); dis[s] = 0;
  while (!q.empty()) {
    int d, u; tie(d, u) = q.top(); q.pop();
    if (-d != dis[u]) continue;
    if (special[u]) return {dis[u], u};
    for (auto& p : adj[u]) {
      int v, w; tie(v, w) = p;
      if (dis[u] + w < dis[v]) 
        dis[v] = dis[u] + w, q.emplace(-dis[v], v);
    }
  }
  return {inf, 0};
}

tuple<int, int, int> dijkstra0() {
  memset(dis, 0x3f, sizeof(dis));
  for (int v = 0; v < n; ++v) if (special[v])
    dis[v] = 0, src[v] = v, q.emplace(0, v);
  while (!q.empty()) {
    int d, u; tie(d, u) = q.top(); q.pop();
    if (-d != dis[u]) continue;
    for (auto& p : adj[u]) {
      int v, w; tie(v, w) = p;
      if (dis[u] + w < dis[v]) 
        dis[v] = dis[u] + w, src[v] = src[u], q.emplace(-dis[v], v);
    }
  }
  int res = inf, s = -1, t = -1;
  for (int u = 0; u < n; ++u) for (auto& p : adj[u]) {
    int v, w; tie(v, w) = p;
    if (src[u] != src[v] && dis[u] + dis[v] + w < res)
      res = dis[u] + dis[v] + w, s = src[u], t = src[v];
  }
  return make_tuple(res, s, t);
}

signed main() {
  cin.tie(0)->sync_with_stdio(0); cout.tie(0);
  cin >> n >> m >> k;
  for (int i = 0, u, v, w; i < m; ++i)
    cin >> u >> v >> w, u--, v--,
    adj[u].emplace_back(v, w),
    adj[v].emplace_back(u, w);
    
  for (int i = 0, v; i < k; ++i)
    cin >> v, v--, special[v] = 1;
  
    
  int val1, val2, val3, val4, s, t, t2, tmp1, tmp2;
  tie(val1, s, t) = dijkstra0(); special[s] = special[t] = 0; 
  tie(val2, tmp1, tmp2) = dijkstra0(); 
  
  tie(val3, t2) = dijkstra(s); special[t2] = 0;
  tie(val4, tmp1) = dijkstra(t);
  cout << min(val1 + val2, val3 + val4);
	return 0;
}

# 결과 실행 시간 메모리 Grader output
1 Incorrect 2 ms 3412 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 2 ms 3412 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 54 ms 8340 KB Output is correct
2 Correct 6 ms 4116 KB Output is correct
3 Correct 1190 ms 120136 KB Output is correct
4 Correct 562 ms 59312 KB Output is correct
5 Correct 152 ms 14292 KB Output is correct
6 Correct 124 ms 11860 KB Output is correct
7 Correct 173 ms 15512 KB Output is correct
8 Correct 55 ms 8368 KB Output is correct
9 Correct 112 ms 11324 KB Output is correct
10 Correct 76 ms 9340 KB Output is correct
11 Correct 1222 ms 127028 KB Output is correct
12 Correct 85 ms 9800 KB Output is correct
13 Correct 345 ms 36160 KB Output is correct
14 Correct 176 ms 16240 KB Output is correct
15 Correct 1191 ms 124732 KB Output is correct
16 Correct 40 ms 7648 KB Output is correct
17 Correct 847 ms 93172 KB Output is correct
18 Correct 6 ms 4436 KB Output is correct
19 Correct 1330 ms 133860 KB Output is correct
20 Correct 159 ms 15372 KB Output is correct
21 Correct 137 ms 13548 KB Output is correct
22 Correct 69 ms 9292 KB Output is correct
23 Correct 19 ms 6740 KB Output is correct
24 Correct 875 ms 102612 KB Output is correct
25 Correct 117 ms 11468 KB Output is correct
26 Correct 64 ms 8288 KB Output is correct
27 Correct 90 ms 10332 KB Output is correct
28 Correct 12 ms 5460 KB Output is correct
29 Correct 165 ms 15252 KB Output is correct
30 Correct 311 ms 29172 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Incorrect 2 ms 3412 KB Output isn't correct
2 Halted 0 ms 0 KB -