#include #include #include #include #include #include #include #include #define debug_value(x) cerr << "line" << __LINE__ << ":<" << __func__ << ">:" << #x << "=" << x << endl; #define debug(x) cerr << "line" << __LINE__ << ":<" << __func__ << ">:" << x << endl; template inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; } template inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; } using namespace std; typedef long long ll; class Bit{ public: bool v; Bit(bool _v = false){ v = _v; } Bit operator+(bool b){ return Bit(v|b); } Bit operator*(bool b){ return Bit(v&b); } void operator+=(bool b){ v |= b; } void operator*=(bool b){ v &= b; } Bit operator+(Bit b){ return Bit(v|b.v); } Bit operator*(Bit b){ return Bit(v&b.v); } void operator+=(Bit b){ v |= b.v; } void operator*=(Bit b){ v &= b.v; } }; template struct matrix{ int n, m; vector> dat; matrix(int n_, int m_){ n = n_; m = m_; for(int i = 0; i < n; i++){ dat.push_back(vector(m)); } } vector& operator[](int x) { return dat[x]; } }; template bool prod(matrix a, matrix b, matrix &ans){ assert(a.m == b.n); for(int i = 0; i < a.n; i++){ for(int j = 0; j < b.m; j++){ ans.dat[i][j] = 0; for(int k = 0; k < b.n; k++){ ans.dat[i][j] += (a.dat[i][k]*b.dat[k][j]); } } } return true; } template void copy_mat(matrix a, matrix &b){ assert(a.n == b.n); assert(a.m == b.m); for(int i = 0; i < a.n; i++){ for(int j = 0; j < a.m; j++){ b.dat[i][j] = a.dat[i][j]; } } } template void pow_mat(matrix a, ll n, matrix &ans){ assert(n < ((ll)1<<61)); matrix buf(a.n, a.n); matrix tmp(a.n, a.n); copy_mat(a, tmp); for(int i = 0; i < a.n; i++) { for(int j = 0; j < a.n; j++){ ans.dat[i][j] = 0; } ans.dat[i][i] = 1; } for(int i = 0; i <= 60; i++){ ll m = (ll)1 << i; if(m&n){ prod(tmp, ans, buf); copy_mat(buf, ans); } prod(tmp, tmp, buf); copy_mat(buf, tmp); } } int n, m; ll t; int main(){ ios::sync_with_stdio(false); cin.tie(0); cout << setprecision(10) << fixed; cin >> n >> m >> t; matrix mat(n, n); for(int i = 0; i < m; i++){ int a, b; cin >> a >> b; mat[b][a] = true; } matrix v(n, 1); v[0][0] = true; matrix pw(n, n); pow_mat(mat, t, pw); matrix ans(n, 1); prod(pw, v, ans); // cout << ans << endl; int sum = 0; for(int i = 0; i < n; i++) { if(ans[i][0].v) sum++; } cout << sum << endl; }