#include #include #include #include #include using namespace std; vector get_potentials(int begin, const vector > > &edges_from) { const int V = edges_from.size(); priority_queue > q; vector potentials(V, INT_MAX); q.push(make_pair(-0, begin)); while (!q.empty()) { pair c = q.top(); q.pop(); if (potentials[c.second] != INT_MAX) continue; potentials[c.second] = -c.first; const vector > &n = edges_from[c.second]; for (int i = 0; i < n.size(); i++) if (potentials[n[i].first] == INT_MAX) q.push(make_pair(c.first - n[i].second, n[i].first)); } return potentials; } struct Road { int from, to, length; Road(int from, int to, int length) : from(from), to(to), length(length) {} }; int main() { for (int N, M, K; cin >> N >> M >> K, N || M || K; ) { vector roads; vector > > roads_from(N); // vector > > roads_to(N); // for (int i = 0; i < M; i++) { int from, to, length; cin >> from >> to >> length; from--, to--; roads.push_back(Road(from, to, length)); roads_from[from].push_back(make_pair(to, length)); roads_to[to].push_back(make_pair(from, length)); } vector answer; { const vector l = get_potentials(0, roads_from); const vector r = get_potentials(N-1, roads_to); const int shortest = l[N-1]; for (int i = 0; i < M; i++) if (l[roads[i].from] != INT_MAX && r[roads[i].to] != INT_MAX && l[roads[i].from] + roads[i].length + r[roads[i].to] <= shortest + K) answer.push_back(i+1); } static bool first = true; if (first) first = false; else cout << endl; cout << answer.size() << endl; for (int i = 0; i < answer.size(); i++) cout << answer[i] << endl; } return 0; }