#include #include using namespace std; using ll = long long int; template class Matrix{ private: vector> mat; int row; int column; public: Matrix(int r = 1, int c = 1){ this->row = r; this->column = c; this->mat = vector>(this->row, vector(this->column, 0)); } Matrix(vector> initmat){ this->mat = initmat; this->row = this->mat.size(); this->column = this->mat[0].size(); } vector &operator[](const int rowind){ return mat[rowind]; } vector operator[](const int rowind) const { return mat[rowind]; } const int getrow() const { return this->row; } const int getcol() const { return this->column; } Matrix operator+(const Matrix &other) const { if(this->row != other.getrow() || this->column != other.getcol()){ cerr << "Matrix calc error(add)" << endl; abort(); } Matrix ans(this->row, this->column); for(int i = 0; i < this->row; i++){ for(int j = 0; j < this->column; j++) ans[i][j] = this->mat[i][j] + other[i][j]; } return ans; } Matrix operator-(const Matrix &other) const { if(this->row != other.getrow() || this->column != other.getcol()){ cerr << "Matrix calc error(sub)" << endl; abort(); } Matrix ans(this->row, this->column); for(int i = 0; i < this->row; i++){ for(int j = 0; j < this->column; j++) ans[i][j] = this->mat[i][j] - other[i][j]; } return ans; } Matrix operator*(const Matrix &other) const { if(this->column != other.getrow()){ cerr << "Matrix calc error(mult)" << endl; abort(); } Matrix ans(this->row, other.getcol()); for(int i = 0; i < this->row; i++){ for(int j = 0; j < other.getcol(); j++){ for(int k = 0; k < this->column; k++) ans[i][j] += this->mat[i][k] * other[k][j]; } } return ans; } }; template Matrix modpow(Matrix a, ll x, ll mod){ if(a.getrow() != a.getcol()){ cerr << "Matrix calc error(pow)" << endl; abort(); } Matrix ans(a.getrow(), a.getcol()); for(int i = 0; i < ans.getrow(); i++) ans[i][i] = 1; auto modmult = [](const Matrix &a, const Matrix &b, const ll mod){ Matrix res(a.getrow(), b.getcol()); for(int i = 0; i < a.getrow(); i++){ for(int j = 0; j < b.getcol(); j++){ for(int k = 0; k < a.getcol(); k++){ res[i][j] += a[i][k] * b[k][j]; res[i][j] %= mod; } if(res[i][j] > 0) res[i][j] = 1; } } return res; }; while(x > 0){ if(x & 1){ ans = modmult(ans, a, mod); } a = modmult(a, a, mod); x >>= 1; } return ans; } int main(){ int n, m, t; cin >> n >> m >> t; Matrix mat(n, n); for(int i = 0; i < m; i++){ int a, b; cin >> a >> b; mat[a][b] = 1; } mat = modpow(mat, t, 1000000007); int ans = 0; for(int i = 0; i < n; i++){ ans += mat[0][i]; } cout << ans << endl; return 0; }