#include #include #include #include #include #include #define UNDEF (-1) using namespace std; struct edge_t { int s, t, c; }; struct cand_t { int t, c; public: cand_t(int t, int c) : t(t), c(c) { } cand_t(void) { } public: bool operator <(const cand_t &other) const { if(c != other.c) return c > other.c; if(t != other.t) return t < other.t; return false; } }; int main(void) { ifstream fin("almost.in"); int n, m, k; bool crflag = false; while(fin >> n >> m >> k) { if(n == 0 && m == 0 && k == 0) break; vector< map > v1(n); vector< map > v2(n); vector e(m); for(int i = 0; i < m; i++) { fin >> e[i].s >> e[i].t >> e[i].c; (e[i].s)--; (e[i].t)--; v1[e[i].s].insert(make_pair(e[i].t, e[i].c)); v2[e[i].t].insert(make_pair(e[i].s, e[i].c)); } vector cost1(n, UNDEF); int rest1 = n; vector cost2(n, UNDEF); int rest2 = n; priority_queue cue1; cue1.push(cand_t(0, 0)); while(!cue1.empty()) { cand_t cand = cue1.top(); cue1.pop(); if(cost1[cand.t] != UNDEF) continue; cost1[cand.t] = cand.c; if(--rest1 <= 0) break; map &adj = v1[cand.t]; for(map::iterator p = adj.begin(); p != adj.end(); p++) { if(cost1[p->first] == UNDEF) { cue1.push(cand_t(p->first, cand.c + p->second)); } } } priority_queue cue2; cue2.push(cand_t(n - 1, 0)); while(!cue2.empty()) { cand_t cand = cue2.top(); cue2.pop(); if(cost2[cand.t] != UNDEF) continue; cost2[cand.t] = cand.c; if(--rest2 <= 0) break; map &adj = v2[cand.t]; for(map::iterator p = adj.begin(); p != adj.end(); p++) { if(cost2[p->first] == UNDEF) { cue2.push(cand_t(p->first, cand.c + p->second)); } } } vector ans; for(int i = 0; i < m; i++) { if(cost1[e[i].s] == UNDEF || cost2[e[i].t] == UNDEF) continue; if(cost1[e[i].s] + e[i].c + cost2[e[i].t] <= cost1[n - 1] + k) ans.push_back(i); } if(crflag) cout << endl; crflag = true; cout << ans.size() << endl; for(int i = 0; i < ans.size(); i++) cout << ans[i] + 1 << endl; } }