-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy patha58_q3_p3a_hacking.cpp
More file actions
52 lines (41 loc) · 1.12 KB
/
Copy patha58_q3_p3a_hacking.cpp
File metadata and controls
52 lines (41 loc) · 1.12 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
#include <bits/stdc++.h>
using namespace std;
const int INF = 1e9 + 7;
int main() {
cin.tie(nullptr)->sync_with_stdio(false);
int n, m, k;
cin >> n >> m >> k;
vector <int> s(k), c(n);
vector <vector <int>> graph(n);
for (int i = 0; i < k; i++) cin >> s[i];
for (int i = 0; i < n; i++) cin >> c[i];
while (m--) {
int a, b;
cin >> a >> b;
graph[a].push_back(b);
graph[b].push_back(a);
}
vector <int> dist(n, INF);
vector <bool> visited(n, false);
priority_queue <pair <int, int>> pq;
for (int i = 0; i < k; i++) {
dist[s[i]] = c[s[i]];
pq.emplace(-c[s[i]], s[i]);
}
while (!pq.empty()) {
auto [d, u] = pq.top();
pq.pop();
if (visited[u] == true) continue;
visited[u] = true;
for (auto v : graph[u]) {
if (visited[v] == false and dist[u] + c[v] < dist[v]) {
dist[v] = dist[u] + c[v];
pq.emplace(-dist[v], v);
}
}
}
int ans = 0;
for (int i = 0; i < n; i++) ans = max(ans, dist[i]);
cout << ans;
return 0;
}