// #pragma GCC target("avx2") // #pragma GCC optimize("O3") // #pragma GCC optimize("unroll-loops") #include using namespace std; using ll = long long; using ld = long double; using pll = pair; using pii = pair; using vvl = vector>; using vvi = vector>; using vvpll = vector>; #define rep(i, a, b) for (ll i=(a); i<(b); i++) #define rrep(i, a, b) for (ll i=(a); i>(b); i--) #define pb push_back #define tostr to_string #define ALL(A) A.begin(), A.end() #define elif else if // constexpr ll INF = LONG_LONG_MAX; constexpr ll INF = 1e18; constexpr ll MOD = 1000000009; const string digits = "0123456789"; const string ascii_lowercase = "abcdefghijklmnopqrstuvwxyz"; const string ascii_uppercase = "ABCDEFGHIJKLMNOPQRSTUVWXYZ"; const string ascii_letters = ascii_lowercase + ascii_uppercase; template vector> list2d(int N, int M, T init) { return vector>(N, vector(M, init)); } template vector>> list3d(int N, int M, int L, T init) { return vector>>(N, vector>(M, vector(L, init))); } template vector>>> list4d(int N, int M, int L, int O, T init) { return vector>>>(N, vector>>(M, vector>(L, vector(O, init)))); } vector LIST(ll N) { vector A(N); rep(i, 0, N) cin >> A[i]; return A; } void print(ld out) { cout << fixed << setprecision(15) << out << '\n'; } void print(double out) { cout << fixed << setprecision(15) << out << '\n'; } template void print(T out) { cout << out << '\n'; } template void print(pair out) { cout << out.first << ' ' << out.second << '\n'; } template void print(vector A) { rep(i, 0, A.size()) { cout << A[i]; cout << (i == A.size()-1 ? '\n' : ' '); } } template void print(set S) { vector A(S.begin(), S.end()); print(A); } void Yes() { print("Yes"); } void No() { print("No"); } void YES() { print("YES"); } void NO() { print("NO"); } ll floor(ll a, ll b) { if (a < 0) { return (a-b+1) / b; } else { return a / b; } } ll ceil(ll a, ll b) { if (a >= 0) { return (a+b-1) / b; } else { return a / b; } } pll divmod(ll a, ll b) { ll d = a / b; ll m = a % b; return {d, m}; } template bool chmax(T &x, T y) { return (y > x) ? x = y, true : false; } template bool chmin(T &x, T y) { return (y < x) ? x = y, true : false; } template T sum(vector A) { T res = 0; for (T a: A) res += a; return res; } template T max(vector A) { return *max_element(ALL(A)); } template T min(vector A) { return *min_element(ALL(A)); } ll toint(string s) { ll res = 0; for (char c : s) { res *= 10; res += (c - '0'); } return res; } int toint(char num) { return num - '0'; } char tochar(int num) { return '0' + num; } int ord(char c) { return (int)c; } char chr(int a) { return (char)a; } ll pow(ll x, ll n) { ll res = 1; rep(_, 0, n) res *= x; return res; } ll pow(ll x, ll n, int mod) { ll res = 1; while (n > 0) { if (n & 1) { res = (res * x) % mod; } x = (x * x) % mod; n >>= 1; } return res; } int popcount(ll S) { return __builtin_popcountll(S); } ll gcd(ll a, ll b) { return __gcd(a, b); } ll lcm(ll x, ll y) { return (x * y) / gcd(x, y); } template int bisect_left(vector &A, T val) { return lower_bound(ALL(A), val) - A.begin(); } template int bisect_right(vector &A, T val) { return upper_bound(ALL(A), val) - A.begin(); } // 行列累乗 template struct MatPow { MatPow() {} vector> mat_dot(vector> &A, vector> &B) { int n1 = A.size(); int n2 = A[0].size(); int m2 = B[0].size(); auto res = list2d(n1, m2, (T)0); rep(i, 0, n1) { rep(j, 0, m2) { rep(k, 0, n2) { res[i][j] = (res[i][j] + (A[i][k] * B[k][j]) % MOD) % MOD; } } } return res; } vector> mat_pow(vector> mat, ll k) { int n = mat.size(); auto res = list2d(n, n, (T)0); rep(i, 0, n) { res[i][i] = 1; } while (k > 0) { if (k & 1) { res = mat_dot(res, mat); } mat = mat_dot(mat, mat); k >>= 1; } return res; } vector solve(vector> mat, vector &_init, ll K) { int n = mat.size(); auto init = list2d(n, 1, (T)0); rep(i, 0, n) init[i][0] = _init[i]; auto res = mat_pow(mat, K); res = mat_dot(res, init); vector ret(n, 0); rep(i, 0, n) { ret[i] = res[i][0]; } return ret; } }; int main() { cin.tie(0); ios::sync_with_stdio(false); ll N, M, T; cin >> N >> M >> T; auto G = list2d(N, N, 0LL); rep(i, 0, M) { ll u, v; cin >> u >> v; // いつもの隣接行列と逆向き G[v][u] = 1; } // init[i] := 出発前に頂点iにいる通り数 vector init(N); init[0] = 1; MatPow mp; // res[i] := T回移動後に頂点iにいる通り数 auto res = mp.solve(G, init, T); ll ans = 0; rep(i, 0, N) { if (res[i]) ans++; } print(ans); return 0; }