#include #include #include #include #include #include #include using namespace std; using ll = long long; template struct Matrix { Matrix(int n, int m) : a(n * m), n(n), m(m) {} static Matrix E(int n) { Matrix r(n, n); for (int i = 0; i < n; i++) { for (int j = 0; j < n; j++) { r[i][j] = i == j; } } return r; } Matrix pow(ll k) const { Matrix r = E(n), t = *this; for (; k != 0; k /= 2) { if (k & 1) r = r * t; t = t * t; } return r; } Matrix operator*(const Matrix &x) const { if (m != x.n) throw; Matrix r(n, x.m); for (int i = 0; i < n; i++) { for (int j = 0; j < x.m; j++) { T t = 0; for (int k = 0; k < m; k++) { t |= (*this)[i][k] & x[k][j]; } r[i][j] = t; } } return r; } const T *operator[](int i) const { return &a[i * m]; } T *operator[](int i) { return &a[i * m]; } vector a; int n, m; }; int main() { ios::sync_with_stdio(false); cin.tie(0); int n, m; cin >> n >> m; ll t; cin >> t; Matrix v(n, 1), x(n, n); v[0][0] = 1; for (int i = 0; i < m; i++) { int a, b; cin >> a >> b; x[b][a] = 1; } v = x.pow(t) * v; int r = 0; for (int i = 0; i < n; i++) { r += v.a[i]; } cout << r << endl; return 0; }