#include <iostream>
#include <queue>
#include <vector>
using namespace std;
#define MAXN 1000
priority_queue<int> dist[MAXN];
priority_queue<pair<int,int> ,vector<pair<int,int> >, greater<> > pq;
vector<pair<int,int> > adj[MAXN];
int N,M,K;
void dijkstra(){
pq.push({0,0});
dist[0].push(0);
while (!pq.empty()){
int cur = pq.top().second;
int cur_w = pq.top().first;
pq.pop();
for (int i = 0 ; i < adj[cur].size(); i++){
int next = adj[cur][i].first;
int next_w = adj[cur][i].second + cur_w;
if (dist[next].size() < K){
dist[next].push(next_w);
pq.push({next_w,next});
}
else if (dist[next].top() > next_w){
dist[next].pop();
dist[next].push(next_w);
pq.push({next_w,next});
}
}
}
}
int main(){
ios::sync_with_stdio(false);
cin.tie(0);
cin >> N >> M >> K;
while (M--){
int u,v,w;
cin >> u >> v >> w;
u--;
v--;
adj[u].push_back({v,w});
}
dijkstra();
for (int i = 0 ; i < N; i++){
if (dist[i].size() == K){
cout << dist[i].top() <<"\n";
}
else cout << "-1\n";
}
return 0;
}