struct Scanner { private var stack = [String]() private var index = 0 mutating func peek() -> String { if stack.count == index { stack += readLine()!.split(separator: " ").map{ String($0) } } return stack[index] } mutating func next() -> String { let value = peek() index += 1 return value } mutating func nextInt() -> Int { return Int(next())! } mutating func nextDouble() -> Double { return Double(next())! } } let MOD = 1000000007 struct Zn { let n: Int init(_ n: Int) { self.n = n } static func + (lhs: Self, rhs: Self) -> Self { Zn((lhs.n + rhs.n) % MOD) } static func - (lhs: Self, rhs: Self) -> Self { Zn((lhs.n - rhs.n + MOD) % MOD) } static func * (lhs: Self, rhs: Self) -> Self { Zn((lhs.n * rhs.n) % MOD) } static func += (lhs: inout Self, rhs: Self) { lhs = lhs + rhs } } var scanner = Scanner() let N = scanner.nextInt() let M = scanner.nextInt() let K = scanner.nextInt() struct Edge { let to: Int let cost: Int } var G = [[Edge]](repeating: [Edge](), count: 300) for _ in 0 ..< M { let P = scanner.nextInt() - 1 let Q = scanner.nextInt() - 1 let C = scanner.nextInt() G[P].append(Edge(to: Q, cost: C)) } var dp = [Zn](repeating: Zn(0), count: N * 300 * (K + 1)) func index(_ i: Int, _ j: Int, _ k: Int) -> Int { (i * 300 + j) * (K + 1) + k } for j in 0 ..< 300 { dp[index(0, j, 0)] = Zn(1) } for i in 1 ..< N { for from in 0 ..< 300 { for complexity in 0 ... K { for edge in G[from] where complexity + edge.cost <= K { dp[index(i, edge.to, complexity + edge.cost)] += dp[index(i - 1, from, complexity)] } } } } var answer = Zn(0) for j in 0 ..< 300 { answer += dp[index(N - 1, j, K)] } print(answer.n)