#include #define rep(i,n) for(int i = 0; i < (n); i++) using namespace std; typedef long long ll; vector> matmul(vector> A, vector> B){ int N = A.size(); vector> ans(N, vector(N, 0)); for (int i = 0; i < N; i++){ for (int j = 0; j < N; j++){ for (int k = 0; k < N; k++){ ans[i][k] |= A[i][j] & B[j][k]; } } } return ans; } vector> matpow(vector> A, long long b){ int N = A.size(); vector> ans(N, vector(N, 0)); for (int i = 0; i < N; i++){ ans[i][i] = 1; } while (b > 0){ if (b % 2 == 1){ ans = matmul(ans, A); } A = matmul(A, A); b /= 2; } return ans; } int main(){ cin.tie(0); ios::sync_with_stdio(0); ll N,M,T; cin >> N >> M >> T; vector> A(N, vector (N, 0)); rep(i,M){ ll a,b; cin >> a >> b; A[a][b] = 1; } A = matpow(A, T); int ans = 0; rep(i,N) ans += A[0][i]; cout << ans << '\n'; }