#include <iostream>
#include <cstring>
#include <queue>
#include <algorithm>
using namespace std;
const int N = 10010,M = 20010,INF = 0x3f3f3f3f;
int n,m,k;
int dist[N];
int h[N], w[M], e[M], ne[M], idx;
int is_x[N];
bool st[N];
int ds[N][1010];
int len;
int u1,v1,w1;
void add(int a,int b,int c)
{
e[idx] = b,w[idx] = c,ne[idx] = h[a],h[a] = idx++;
}
void spfa(int k1)
{
memset(dist, 0x3f, sizeof dist);
dist[k1] = 0;
st[N] = {0};
queue<int> q;
q.push(k1);
st[k1] = true;
while (q.size())
{
auto t = q.front();
q.pop();
st[t] = false;
for (int i = h[t]; i != -1; i = ne[i])
{
int j = e[i];
if (dist[j] > dist[t] + w[i])
{
dist[j] = dist[t] + w[i];
if (!st[j])
{
q.push(j);
st[j] = true;
}
}
}
}
for(int i=1;i <= n ;i++) ds[i][len] = dist[i];
}
int main()
{
cin >> n >> m >> k;
for(int i=1;i <= n;i++)
{
cin >> is_x[i];
}
memset(h, -1, sizeof h);
int tmp = m;
while(tmp--)
{
cin >> u1 >> v1 >> w1;
add(u1,v1,w1);
add(v1,u1,w1);
}
for(int i=1;i <= n;i++)
{
if(is_x[i])
{
spfa(i);
len++;
}
}
for(int i=1;i <= n;i++)
{
int ans = 0;
sort(ds[i],ds[i]+len);
for(int j=0;j < len && j < k;j++)
{
if(ds[i][j] != INF) ans += ds[i][j];
else break;
}
cout << ans << endl;
}
return 0;
}
|