답안 #670834

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
670834 2022-12-10T19:10:12 Z dattranxxx Relay Marathon (NOI20_relaymarathon) C++11
100 / 100
1533 ms 197736 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, val5, val6, 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); special[t2] = 1;
  
  tie(val5, t2) = dijkstra(t); special[t2] = 0;
  tie(val6, tmp1) = dijkstra(s); 
  cout << min({val1 + val2, val3 + val4, val5 + val6});
	return 0;
}

# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 3412 KB Output is correct
2 Correct 3 ms 3540 KB Output is correct
3 Correct 2 ms 3412 KB Output is correct
4 Correct 2 ms 3412 KB Output is correct
5 Correct 2 ms 3412 KB Output is correct
6 Correct 2 ms 3412 KB Output is correct
7 Correct 2 ms 3540 KB Output is correct
8 Correct 2 ms 3540 KB Output is correct
9 Correct 2 ms 3452 KB Output is correct
10 Correct 2 ms 3412 KB Output is correct
11 Correct 2 ms 3448 KB Output is correct
12 Correct 2 ms 3412 KB Output is correct
13 Correct 3 ms 3464 KB Output is correct
14 Correct 3 ms 3544 KB Output is correct
15 Correct 2 ms 3540 KB Output is correct
16 Correct 2 ms 3412 KB Output is correct
17 Correct 2 ms 3412 KB Output is correct
18 Correct 2 ms 3452 KB Output is correct
19 Correct 3 ms 3508 KB Output is correct
20 Correct 2 ms 3412 KB Output is correct
21 Correct 2 ms 3412 KB Output is correct
22 Correct 2 ms 3412 KB Output is correct
23 Correct 2 ms 3412 KB Output is correct
24 Correct 2 ms 3412 KB Output is correct
25 Correct 2 ms 3452 KB Output is correct
26 Correct 2 ms 3452 KB Output is correct
27 Correct 2 ms 3412 KB Output is correct
28 Correct 2 ms 3540 KB Output is correct
29 Correct 2 ms 3504 KB Output is correct
30 Correct 2 ms 3540 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 3412 KB Output is correct
2 Correct 3 ms 3540 KB Output is correct
3 Correct 2 ms 3412 KB Output is correct
4 Correct 2 ms 3412 KB Output is correct
5 Correct 2 ms 3412 KB Output is correct
6 Correct 2 ms 3412 KB Output is correct
7 Correct 2 ms 3540 KB Output is correct
8 Correct 2 ms 3540 KB Output is correct
9 Correct 2 ms 3452 KB Output is correct
10 Correct 2 ms 3412 KB Output is correct
11 Correct 2 ms 3448 KB Output is correct
12 Correct 2 ms 3412 KB Output is correct
13 Correct 3 ms 3464 KB Output is correct
14 Correct 3 ms 3544 KB Output is correct
15 Correct 2 ms 3540 KB Output is correct
16 Correct 2 ms 3412 KB Output is correct
17 Correct 2 ms 3412 KB Output is correct
18 Correct 2 ms 3452 KB Output is correct
19 Correct 3 ms 3508 KB Output is correct
20 Correct 2 ms 3412 KB Output is correct
21 Correct 2 ms 3412 KB Output is correct
22 Correct 2 ms 3412 KB Output is correct
23 Correct 2 ms 3412 KB Output is correct
24 Correct 2 ms 3412 KB Output is correct
25 Correct 2 ms 3452 KB Output is correct
26 Correct 2 ms 3452 KB Output is correct
27 Correct 2 ms 3412 KB Output is correct
28 Correct 2 ms 3540 KB Output is correct
29 Correct 2 ms 3504 KB Output is correct
30 Correct 2 ms 3540 KB Output is correct
31 Correct 2 ms 3412 KB Output is correct
32 Correct 2 ms 3412 KB Output is correct
33 Correct 2 ms 3460 KB Output is correct
34 Correct 2 ms 3412 KB Output is correct
35 Correct 2 ms 3452 KB Output is correct
36 Correct 3 ms 3668 KB Output is correct
37 Correct 3 ms 3796 KB Output is correct
38 Correct 2 ms 3540 KB Output is correct
39 Correct 22 ms 9044 KB Output is correct
40 Correct 7 ms 4748 KB Output is correct
41 Correct 2 ms 3460 KB Output is correct
42 Correct 7 ms 4692 KB Output is correct
43 Correct 3 ms 3668 KB Output is correct
44 Correct 2 ms 3540 KB Output is correct
45 Correct 2 ms 3444 KB Output is correct
46 Correct 25 ms 9268 KB Output is correct
47 Correct 5 ms 4152 KB Output is correct
48 Correct 20 ms 8964 KB Output is correct
49 Correct 22 ms 8900 KB Output is correct
50 Correct 2 ms 3540 KB Output is correct
51 Correct 2 ms 3540 KB Output is correct
52 Correct 2 ms 3412 KB Output is correct
53 Correct 13 ms 6356 KB Output is correct
54 Correct 23 ms 9068 KB Output is correct
55 Correct 2 ms 3412 KB Output is correct
56 Correct 3 ms 3412 KB Output is correct
57 Correct 2 ms 3540 KB Output is correct
58 Correct 27 ms 9340 KB Output is correct
59 Correct 2 ms 3412 KB Output is correct
60 Correct 3 ms 3540 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 51 ms 8352 KB Output is correct
2 Correct 6 ms 4052 KB Output is correct
3 Correct 1257 ms 120236 KB Output is correct
4 Correct 603 ms 59316 KB Output is correct
5 Correct 150 ms 14300 KB Output is correct
6 Correct 131 ms 11836 KB Output is correct
7 Correct 174 ms 15492 KB Output is correct
8 Correct 59 ms 8408 KB Output is correct
9 Correct 115 ms 11360 KB Output is correct
10 Correct 75 ms 9312 KB Output is correct
11 Correct 1251 ms 126996 KB Output is correct
12 Correct 83 ms 9804 KB Output is correct
13 Correct 356 ms 36224 KB Output is correct
14 Correct 182 ms 16224 KB Output is correct
15 Correct 1233 ms 124716 KB Output is correct
16 Correct 40 ms 7660 KB Output is correct
17 Correct 877 ms 92952 KB Output is correct
18 Correct 6 ms 4436 KB Output is correct
19 Correct 1364 ms 133824 KB Output is correct
20 Correct 156 ms 15436 KB Output is correct
21 Correct 146 ms 13648 KB Output is correct
22 Correct 72 ms 9348 KB Output is correct
23 Correct 19 ms 6740 KB Output is correct
24 Correct 878 ms 102792 KB Output is correct
25 Correct 114 ms 11428 KB Output is correct
26 Correct 63 ms 8388 KB Output is correct
27 Correct 90 ms 10324 KB Output is correct
28 Correct 12 ms 5444 KB Output is correct
29 Correct 164 ms 15348 KB Output is correct
30 Correct 316 ms 29156 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 3412 KB Output is correct
2 Correct 3 ms 3540 KB Output is correct
3 Correct 2 ms 3412 KB Output is correct
4 Correct 2 ms 3412 KB Output is correct
5 Correct 2 ms 3412 KB Output is correct
6 Correct 2 ms 3412 KB Output is correct
7 Correct 2 ms 3540 KB Output is correct
8 Correct 2 ms 3540 KB Output is correct
9 Correct 2 ms 3452 KB Output is correct
10 Correct 2 ms 3412 KB Output is correct
11 Correct 2 ms 3448 KB Output is correct
12 Correct 2 ms 3412 KB Output is correct
13 Correct 3 ms 3464 KB Output is correct
14 Correct 3 ms 3544 KB Output is correct
15 Correct 2 ms 3540 KB Output is correct
16 Correct 2 ms 3412 KB Output is correct
17 Correct 2 ms 3412 KB Output is correct
18 Correct 2 ms 3452 KB Output is correct
19 Correct 3 ms 3508 KB Output is correct
20 Correct 2 ms 3412 KB Output is correct
21 Correct 2 ms 3412 KB Output is correct
22 Correct 2 ms 3412 KB Output is correct
23 Correct 2 ms 3412 KB Output is correct
24 Correct 2 ms 3412 KB Output is correct
25 Correct 2 ms 3452 KB Output is correct
26 Correct 2 ms 3452 KB Output is correct
27 Correct 2 ms 3412 KB Output is correct
28 Correct 2 ms 3540 KB Output is correct
29 Correct 2 ms 3504 KB Output is correct
30 Correct 2 ms 3540 KB Output is correct
31 Correct 2 ms 3412 KB Output is correct
32 Correct 2 ms 3412 KB Output is correct
33 Correct 2 ms 3460 KB Output is correct
34 Correct 2 ms 3412 KB Output is correct
35 Correct 2 ms 3452 KB Output is correct
36 Correct 3 ms 3668 KB Output is correct
37 Correct 3 ms 3796 KB Output is correct
38 Correct 2 ms 3540 KB Output is correct
39 Correct 22 ms 9044 KB Output is correct
40 Correct 7 ms 4748 KB Output is correct
41 Correct 2 ms 3460 KB Output is correct
42 Correct 7 ms 4692 KB Output is correct
43 Correct 3 ms 3668 KB Output is correct
44 Correct 2 ms 3540 KB Output is correct
45 Correct 2 ms 3444 KB Output is correct
46 Correct 25 ms 9268 KB Output is correct
47 Correct 5 ms 4152 KB Output is correct
48 Correct 20 ms 8964 KB Output is correct
49 Correct 22 ms 8900 KB Output is correct
50 Correct 2 ms 3540 KB Output is correct
51 Correct 2 ms 3540 KB Output is correct
52 Correct 2 ms 3412 KB Output is correct
53 Correct 13 ms 6356 KB Output is correct
54 Correct 23 ms 9068 KB Output is correct
55 Correct 2 ms 3412 KB Output is correct
56 Correct 3 ms 3412 KB Output is correct
57 Correct 2 ms 3540 KB Output is correct
58 Correct 27 ms 9340 KB Output is correct
59 Correct 2 ms 3412 KB Output is correct
60 Correct 3 ms 3540 KB Output is correct
61 Correct 51 ms 8352 KB Output is correct
62 Correct 6 ms 4052 KB Output is correct
63 Correct 1257 ms 120236 KB Output is correct
64 Correct 603 ms 59316 KB Output is correct
65 Correct 150 ms 14300 KB Output is correct
66 Correct 131 ms 11836 KB Output is correct
67 Correct 174 ms 15492 KB Output is correct
68 Correct 59 ms 8408 KB Output is correct
69 Correct 115 ms 11360 KB Output is correct
70 Correct 75 ms 9312 KB Output is correct
71 Correct 1251 ms 126996 KB Output is correct
72 Correct 83 ms 9804 KB Output is correct
73 Correct 356 ms 36224 KB Output is correct
74 Correct 182 ms 16224 KB Output is correct
75 Correct 1233 ms 124716 KB Output is correct
76 Correct 40 ms 7660 KB Output is correct
77 Correct 877 ms 92952 KB Output is correct
78 Correct 6 ms 4436 KB Output is correct
79 Correct 1364 ms 133824 KB Output is correct
80 Correct 156 ms 15436 KB Output is correct
81 Correct 146 ms 13648 KB Output is correct
82 Correct 72 ms 9348 KB Output is correct
83 Correct 19 ms 6740 KB Output is correct
84 Correct 878 ms 102792 KB Output is correct
85 Correct 114 ms 11428 KB Output is correct
86 Correct 63 ms 8388 KB Output is correct
87 Correct 90 ms 10324 KB Output is correct
88 Correct 12 ms 5444 KB Output is correct
89 Correct 164 ms 15348 KB Output is correct
90 Correct 316 ms 29156 KB Output is correct
91 Correct 108 ms 12496 KB Output is correct
92 Correct 1391 ms 181484 KB Output is correct
93 Correct 193 ms 18888 KB Output is correct
94 Correct 871 ms 108584 KB Output is correct
95 Correct 6 ms 4308 KB Output is correct
96 Correct 10 ms 4708 KB Output is correct
97 Correct 227 ms 25316 KB Output is correct
98 Correct 103 ms 12552 KB Output is correct
99 Correct 122 ms 13664 KB Output is correct
100 Correct 1518 ms 195944 KB Output is correct
101 Correct 631 ms 73392 KB Output is correct
102 Correct 611 ms 72464 KB Output is correct
103 Correct 948 ms 134284 KB Output is correct
104 Correct 1270 ms 153152 KB Output is correct
105 Correct 72 ms 9984 KB Output is correct
106 Correct 1018 ms 137652 KB Output is correct
107 Correct 353 ms 38304 KB Output is correct
108 Correct 171 ms 17092 KB Output is correct
109 Correct 16 ms 6100 KB Output is correct
110 Correct 48 ms 9108 KB Output is correct
111 Correct 178 ms 17640 KB Output is correct
112 Correct 1533 ms 196420 KB Output is correct
113 Correct 1520 ms 197736 KB Output is correct
114 Correct 209 ms 17808 KB Output is correct
115 Correct 486 ms 66944 KB Output is correct
116 Correct 1438 ms 177492 KB Output is correct
117 Correct 937 ms 131704 KB Output is correct
118 Correct 885 ms 118640 KB Output is correct
119 Correct 1282 ms 157848 KB Output is correct
120 Correct 875 ms 95212 KB Output is correct