#include using namespace std; struct iofast_t { iofast_t() { ios::sync_with_stdio(false); cin.tie(nullptr); } } iofast; struct uns_t {} uns; template auto vec(Element init, Head arg, Args ...args) { if constexpr (sizeof...(Args) == 0) return std::vector(arg, init); else return std::vector(arg, vec(init, args...)); } template auto vec(uns_t, Head arg, Args ...args) { return vec(Element(), arg, args...); } template > T &chmin(T &l, T r, Compare &&f = less()) { return l = min(l, r, f); } template > T &chmax(T &l, T r, Compare &&f = less()) { return l = max(l, r, f); } #include using mint = atcoder::modint1000000007; int main() { constexpr int lim = 300; int n, m, k; cin >> n >> m >> k; auto g = vec>(uns, lim, 0); for (int i = 0; i < m; ++i) { int p, q, c; cin >> p >> q >> c; --p; --q; g[p].push_back({ q, c }); } auto dp = vec(0, n, k + 1, lim); auto vis = vec(false, n, k + 1, lim); queue> que; for (int i = 0; i < lim; ++i) { dp[0][0][i] = 1; que.push({ 0, 0, i }); } while (!empty(que)) { auto [i, d, v] = que.front(); que.pop(); if (n <= i + 1) { continue; } for (auto [u, c] : g[v]) { if (k < d + c) { continue; } dp[i + 1][d + c][u] += dp[i][d][v]; if (!exchange(vis[i + 1][d + c][u], true)) { que.push({ i + 1, d + c, u }); } } } mint ans = 0; for (int i = 0; i < lim; ++i) { ans += dp[n - 1][k][i]; } cout << ans.val() << endl; }