#pragma GCC target ("avx2") // #pragma GCC optimization ("O3") #pragma GCC optimization ("unroll-loops") #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include // #include using namespace std; using ll=long long; template using V = vector; template using P = pair; using vll = V; using vii = V; using vvll = V; using vvii = V< V >; using PII = P; using PLL = P; #define RevREP(i,n,a) for(ll i=n;i>a;i--) // (a,n] #define REP(i,a,n) for(ll i=a;i inline bool chmax(T& a, T b) {if (a < b) { a=b; return true; } return false; } template < class T > inline bool chmin(T& a, T b) {if (a > b) { a=b; return true; } return false; } template< class A, class B > ostream& operator <<(ostream& out, const P &p) { return out << '(' << p.first << ", " << p.second << ')'; } template< class A > ostream& operator <<(ostream& out, const V &v) { out << '['; for (int i=0;i struct mat { int h, w; std::vector< std::vector > d; mat() {} mat(int h, int w, T v=T(0)): h(h), w(w), d(h, std::vector(w, v)){} std::vector& operator[] (int i) {return d[i];} const std::vector& operator[] (int i) const { return d[i];} void fil(T v=T(0)) { for(int i=0;i operator+(const mat& a) const { // same size mat res(h,w); for (int i = 0; i < h; i++) { for (int j = 0; j < w; j++) { res[i][j] = d[i][j]+a[i][j]; } } return res; } mat operator-(const mat& a) const { // same size mat res(h,w); for (int i = 0; i < h; i++) { for (int j = 0; j < w; j++) { res[i][j] = d[i][j]-a[i][j]; } } return res; } mat operator*(const mat& a) const { // w = a.h mat res(h,a.w); for (int i = 0; i < h; i++) { for (int k = 0; k < w; k++) { for (int j = 0; j < a.w; j++) { res[i][j] |= d[i][k]&a[k][j]; } } } return res; } mat power(ll a) { // h = w mat ret(h, w), me = *this; ret.unit(); while (a > 0) { if (a & 1) ret = ret * me; me = me * me; a >>= 1; } return ret; } }; int main() { cin.tie(0); ios::sync_with_stdio(false); ll n, m, t; cin >> n >> m >> t; vvii edges(n, vii(n, 0)); rep(i, m) { int a, b; cin >> a >> b; edges[a][b] = 1; } mat mmm(n, n, 0); mmm.d = edges; mat am = mmm.power(t); int ans = 0; rep(i, n) ans += am[0][i]; cout << ans << '\n'; return 0; }