#include using namespace std; int dfs(int n, int k, int present, const set &chord, const map, int> &seq) { if (k < 0) return 0; if (n == 0 && k == 0) return 1; if (n == 0) return 0; int ans = 0; for (auto c : chord) { if (seq.find(make_pair(present, c)) == seq.end()) continue; ans += dfs(n - 1, k - seq.at(make_pair(present, c)), c, chord, seq); } return ans; } int main() { int n, m, k; cin >> n >> m >> k; set chord; map, int> seq; for (int i = 0; i < m; i++) { int p, q, c; cin >> p >> q >> c; chord.insert(p); chord.insert(q); seq[make_pair(p, q)] = c; } int ans = 0; for (auto c : chord) { ans += dfs(n - 1, k, c, chord, seq); } cout << ans << endl; }