# 嘘解法 N, M, T, *nums = map(int, open(0).read().split()) G = set(zip(nums[::2], nums[1::2])) T_max = min(N*N+10*N, T) T0 = [-1] * N T1 = [-1] * N dp = [0] * N dp[0] = 1 for t in range(T_max): newdp = [0] * N for frm, to in G: if dp[frm] and not newdp[to]: newdp[to] = 1 T0[to], T1[to] = T1[to], t dp = newdp ans = 0 for v in range(N): if T == T_max: ans += dp[v] else: t0, t1 = T0[v], T1[v] if t0 == -1: continue ans += (T-t1) % (t1-t0) == 0 print(ans)