#include using namespace std; #define repl(i, l, r) for (ll i = (l); i < (r); i++) #define rep(i, n) repl(i, 0, n) #define CST(x) cout << fixed << setprecision(x) using ll = long long; constexpr ll MOD = 1000000007; constexpr int inf = 1e9 + 10; constexpr ll INF = (ll)4e18 + 10; constexpr int dx[9] = {1, 0, -1, 0, 1, -1, -1, 1, 0}; constexpr int dy[9] = {0, 1, 0, -1, 1, 1, -1, -1, 0}; template inline bool chmax(T &a, T b) { return ((a < b) ? (a = b, true) : (false)); } template inline bool chmin(T &a, T b) { return ((a > b) ? (a = b, true) : (false)); } vector> product(const vector> &a, const vector> &b) { assert(a[0].size() == b.size()); vector> c(a.size(), vector(b[0].size())); rep(i, (int)a.size()) rep(k, (int)b.size()) rep(j, (int)b[0].size()) { c[i][j] = c[i][j] | (a[i][k] & b[k][j]); } return c; } vector> powmat(vector> a, ll n) { vector> b(a.size(), vector(a.size())); rep(i, (int)a.size()) b[i][i] = 1; while (n > 0) { if (n & 1) b = product(b, a); a = product(a, a); n >>= 1; } return b; } int main() { cin.tie(0); cout.tie(0); ios::sync_with_stdio(false); int n, m; cin >> n >> m; vector> a(n, vector(n)); ll k; cin >> k; rep(i, m) { int x, y; cin >> x >> y; a[x][y] = 1; } vector> ans = powmat(a, k); int x = 0; rep(i, n) { int y = 0; rep(j, n) y += ans[i][j]; x += (y != 0); } cout << x << endl; return 0; }