#include #include #include using namespace std; void ins() {} templatevoid ins(T& v,Rest&... rest){cin>>v;ins(rest...);} #define rep(i,n) for(int i=0,_i=(n);i<_i;++i) struct Graph { vector> edge; Graph(int n = 0) { resize(n); } void resize(int n) { edge.resize(n, map()); } void addEdge(int from, int to, long long weight) { edge[from][to] = weight; } map& operator[](int from) { return edge[from]; } }; template struct MInt { long long val; constexpr MInt(long long val = 0) : val(val % MOD) { if (val < 0) val += MOD; } MInt operator+(const MInt& n) const { return MInt(val) += n; } MInt& operator+=(const MInt& n) { val = (val + n.val) % MOD; return *this; } friend ostream& operator<<(ostream& os, const MInt& n) { os<; int main() { int N, M, K; ins(N, M, K); Graph G(300); rep(i, M) { int P, Q, C; ins(P, Q, C); --P, --Q; G.addEdge(P, Q, C); } vector> memo(300, vector(K+1)); rep(i, 300) { memo[i][0] = 1; } rep(n, N-1) { vector> memo2(300, vector(K+1)); rep(from, 300) rep(k, K+1) for (const auto& [to, c] : G[from]) { if (k-c >= 0) memo2[from][k] += memo[to][k-c]; } swap(memo2, memo); } mint ans = 0; rep(from, 300) ans += memo[from][K]; cout << ans << endl; return 0; }