#include #include #include #include #include #include typedef std::size_t usize; typedef std::int64_t i64; constexpr i64 impossible = std::numeric_limits::min(); constexpr usize no_edge = std::numeric_limits::max(); constexpr usize start = 1 - 1; constexpr usize end = 2 - 1; struct edge { usize from; usize to; i64 weight; }; std::vector solve(std::vector &edges, usize node_count, usize length) { struct node_score { i64 best_score = impossible; usize last_edge = no_edge; }; std::vector> tables(length + 1, std::vector(node_count, node_score())); std::vector &initial = tables[0]; initial.at(start).best_score = 0; for (usize dist = 1; dist <= length; dist++) { std::vector &last = tables[dist - 1]; std::vector &next = tables[dist]; for (usize id = 0; id < edges.size(); id++) { edge &e = edges[id]; i64 score = last.at(e.from).best_score + e.weight; if (next.at(e.to).best_score < score) next.at(e.to) = node_score{score, id}; } } std::vector result; result.reserve(length); usize node = end; for (usize dist = length; dist > 0; dist--) { usize id = tables[dist].at(node).last_edge; result.push_back(id); node = edges.at(id).from; } std::reverse(result.begin(), result.end()); return result; } int main() { std::cin.exceptions(std::cin.failbit | std::cin.badbit); std::cout.exceptions(std::cin.failbit | std::cin.badbit); std::ios_base::sync_with_stdio(false); std::cin.tie(nullptr); usize node_count, edge_count, length; std::cin >> node_count >> edge_count >> length; std::vector edges; edges.reserve(edge_count); for (usize i = 0; i < edge_count; i++) { edge e; std::cin >> e.from >> e.to >> e.weight; e.from--; e.to--; edges.push_back(e); } std::vector path = solve(edges, node_count, length); for (usize id : path) std::cout << (id + 1) << '\n'; }