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
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
|
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cstring>
#include <cmath>
#include <vector>
#include <queue>
using namespace std;
#define debug(x) cout << #x << " is " << x << endl
#define inc(i, a, b) for (int i = a; i <= b; ++i)
typedef pair<int, int> P;
typedef long long ll;
const int INF = 0x3f3f3f3f, N = 1e4 + 5, M = 2e4 + 5;
int n, m, k, tot;
int ver[M], edge[M], nxt[M], head[N];
int type[N], vis[N];
int d[1005][N];
vector<int> vec;
void add(int x, int y, int z) {
ver[++tot] = y, edge[tot] = z, nxt[tot] = head[x], head[x] = tot;
}
void dijkstra(int st, int *dis) {
priority_queue<P, vector<P>, greater<P> > q;
memset(dis, 0x3f, sizeof(int) * N);
memset(vis, 0, sizeof(vis));
dis[st] = 0;
q.push(P(dis[st], st));
while (!q.empty()) {
int x = q.top().second;
q.pop();
if (vis[x]) continue;
vis[x] = 1;
for (int i = head[x]; i; i = nxt[i]) {
int y = ver[i];
if (dis[y] > dis[x] + edge[i]) {
dis[y] = dis[x] + edge[i];
q.push(P(dis[y], y));
}
}
}
}
int main()
{
scanf("%d%d%d", &n, &m, &k);
int x, y, z;
for (int i = 1; i <= n; ++i) {
scanf("%d", &x);
if (x) vec.push_back(i);
}
while (m--) {
scanf("%d%d%d", &x, &y, &z);
add(x, y, z); add(y, x, z);
}
for (int i = 0; i < (int)vec.size(); ++i) {
dijkstra(vec[i], d[i]);
}
if (k > (int)vec.size()) k = (int)vec.size();
for (int i = 1; i <= n; ++i) {
vector<int> dis;
for (int x = 0; x < (int)vec.size(); ++x) {
dis.push_back(d[x][i]);
}
sort(dis.begin(), dis.end());
int ans = 0;
for (int j = 0; j < k && dis[j] != INF; ++j) ans += dis[j];
printf("%d\n", ans);
}
return 0;
}
/*
7 6 2
1 0 1 0 1 1 0
1 4 1
1 2 3
2 4 4
2 3 5
2 5 7
6 7 5
*/
|