#include <cmath>
#include <iostream>
#include <vector>
using namespace std;
const int INF = 1000 * 1000 + 7;
struct Edge
{
int from, to, weight;
bool isSet;
};
int n, m, k;
vector<Edge> edges;
vector<int> finalWeights;
vector<int> dist;
void calculateDistances()
{
for (int i = 0; i < n; ++i)
{
dist[i] = INF;
}
dist[0] = 0;
for (int i = 0; i < n; ++i)
{
for (auto &edge : edges)
{
dist[edge.to] = min(dist[edge.to], dist[edge.from] + edge.weight);
}
}
}
int main()
{
cin >> n >> m >> k;
dist.resize(n);
for (int i = 0; i < m; ++i)
{
int from, to, weight;
cin >> from >> to >> weight;
--from;
--to;
edges.push_back(Edge{from, to, max(weight, 1), weight != -1});
edges.push_back(Edge{to, from, max(weight, 1), weight != -1});
}
calculateDistances();
if (dist.back() > k)
{
cout << -1 << endl;
return 0;
}
for (int i = 0; i < edges.size(); i += 2)
{
if (edges[i].isSet)
{
finalWeights.push_back(edges[i].weight);
continue;
}
calculateDistances();
int remainder = k - dist.back();
edges[i].weight += remainder;
edges[i + 1].weight += remainder;
finalWeights.push_back(remainder + 1);
}
calculateDistances();
if (dist.back() != k)
{
cout << -1 << endl;
return 0;
}
for (auto& w : finalWeights)
{
cout << w << endl;
}
return 0;
}