#include #define rep(i, n) for (int i = 0; i < (int)(n); i++) using namespace std; typedef long long ll; int N, M, K; map>> G; int dfs(int x, int move, int cost) { if (move == N) { if (cost == K) { return 1; } else { return 0; } } int cnt = 0; for (int i = 0; i < G[x].size(); i++) { // 次に向かうところ int a = G[x][i].first; // コスト int b = G[x][i].second; cnt += dfs(a, move + 1, cost + b); } return cnt; } int main() { cin >> N >> M >> K; vector P(M), Q(M), C(M); rep(i, M) { cin >> P[i] >> Q[i] >> C[i]; P[i]--; Q[i]--; } set st; rep(i, M) { st.insert(P[i]); } rep(i, M) { G[P[i]].push_back(make_pair(Q[i], C[i])); // G.insert(make_pair(Q[i], C[i])); } int cnt = 0; for (auto x : st) { int z = dfs(x, 1, 0); cnt += z; } cout << cnt << endl; }