結果

問題 No.1750 ラムドスウイルスの感染拡大-hard
ユーザー NatsubiSoganNatsubiSogan
提出日時 2021-11-20 16:11:14
言語 PyPy3
(7.3.15)
結果
TLE  
実行時間 -
コード長 3,072 bytes
コンパイル時間 364 ms
コンパイル使用メモリ 82,536 KB
実行使用メモリ 79,760 KB
最終ジャッジ日時 2024-06-11 17:37:27
合計ジャッジ時間 25,642 ms
ジャッジサーバーID
(参考情報)
judge4 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 59 ms
68,820 KB
testcase_01 AC 55 ms
70,156 KB
testcase_02 AC 58 ms
70,608 KB
testcase_03 AC 64 ms
74,676 KB
testcase_04 AC 132 ms
78,268 KB
testcase_05 AC 54 ms
68,156 KB
testcase_06 AC 56 ms
68,800 KB
testcase_07 AC 55 ms
68,440 KB
testcase_08 AC 452 ms
78,764 KB
testcase_09 AC 445 ms
79,028 KB
testcase_10 AC 470 ms
78,992 KB
testcase_11 AC 381 ms
78,836 KB
testcase_12 AC 491 ms
79,064 KB
testcase_13 AC 465 ms
78,908 KB
testcase_14 TLE -
testcase_15 TLE -
testcase_16 TLE -
testcase_17 TLE -
testcase_18 TLE -
testcase_19 TLE -
testcase_20 AC 1,469 ms
78,996 KB
testcase_21 AC 1,716 ms
79,420 KB
testcase_22 AC 515 ms
78,976 KB
testcase_23 AC 1,987 ms
79,164 KB
testcase_24 AC 295 ms
78,268 KB
testcase_25 AC 598 ms
78,376 KB
testcase_26 AC 243 ms
78,552 KB
testcase_27 AC 76 ms
78,448 KB
testcase_28 AC 89 ms
78,196 KB
testcase_29 AC 76 ms
78,292 KB
testcase_30 AC 364 ms
78,488 KB
testcase_31 AC 341 ms
78,528 KB
testcase_32 AC 332 ms
78,664 KB
testcase_33 AC 327 ms
78,812 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import typing

class Matrix:
	def __init__(self, n: int, m: int, mat: typing.Union[list, None] = None, mod: int = 998244353) -> None:
		self.n = n
		self.m = m
		self.mat = [[0] * self.m for i in range(self.n)]
		self.mod = mod
		if mat:
			for i in range(self.n):
				self.mat[i] = mat[i]
	
	def is_square(self) -> None:
		return self.n == self.m
	
	def __getitem__(self, key: int) -> int:
		if isinstance(key, slice):
			return self.mat[key]
		else:
			assert key >= 0
			return self.mat[key]

	@classmethod
	def id(n):
		res = Matrix(n, n)
		for i in range(n):
			res[i][i] = 1
		return res

	def __len__(self) -> int:
		return len(self.mat)
	
	def __str__(self) -> str:
		return "\n".join(" ".join(map(str, self[i])) for i in range(self.n))

	def times(self, k: int) -> "Matrix":
		res = [[0] * self.m for i in range(self.n)]
		for i in range(self.n):
			for j in range(self.m):
				res[i][j] = k * self[i][j] % self.mod
		return Matrix(self.n, self.m, res)

	def __pos__(self) -> "Matrix":
		return self

	def __neg__(self) -> "Matrix":
		return self.times(-1)

	def __add__(self, other: "Matrix") -> "Matrix":
		res = [[0] * self.m for i in range(self.n)]
		for i in range(self.n):
			for j in range(self.m):
				res[i][j] = (self[i][j] + other[i][j]) % self.mod
		return Matrix(self.n, self.m, res)
	
	def __sub__(self, other: "Matrix") -> "Matrix":
		res = [[0] * self.m for i in range(self.n)]
		for i in range(self.n):
			for j in range(self.m):
				res[i][j] = (self[i][j] - other[i][j]) % self.mod
		return Matrix(self.n, self.m, res)

	def __mul__(self, other: typing.Union["Matrix", int]) -> "Matrix":
		if other.__class__ == Matrix:
			res = [[0] * other.m for i in range(self.n)]
			for i in range(self.n):
				for k in range(self.m):
					for j in range(other.m):
						res[i][j] += self[i][k] * other[k][j]
						res[i][j] %= self.mod
			return Matrix(self.n, other.m, res)
		else:
			return self.times(other)
	
	def __rmul__(self, other: typing.Union["Matrix", int]) -> "Matrix":
		return self.times(other)

	def __pow__(self, k: int) -> "Matrix":
		tmp = Matrix(self.n, self.n, self.mat)
		res = Matrix(n, n)
		for i in range(n):
			res[i][i] = 1
		while k:
			if k & 1:
				res *= tmp
			tmp *= tmp
			k >>= 1
		return res

	def determinant(self) -> int:
		res = 1
		tmp  = Matrix(self.n, self.n, self.mat)
		for j in range(self.n):
			if tmp[j][j] == 0:
				for i in range(j + 1, self.n):
					if tmp[i][j] != 0: break
				else:
					return 0
				tmp.mat[j], tmp.mat[i] = tmp.mat[i], tmp.mat[j]
				res *= -1
			inv = invmod(tmp[j][j], self.mod)
			for i in range(j + 1, self.n):
				c = -inv * tmp[i][j] % self.mod
				for k in range(self.n):
					tmp[i][k] += c * tmp[j][k]
					tmp[i][k] %= self.mod
		for i in range(self.n):
			res *= tmp[i][i]
			res %= self.mod
		return res

n, m, t = map(int, input().split())
G = [[0] * n for i in range(n)]
for _ in range(m):
	a, b = map(int, input().split())
	G[a][b] = 1
	G[b][a] = 1
G = Matrix(n, n, G)
b = [[0] * n for i in range(n)]
b[0][0] = 1
b = Matrix(n, n, b)
ans = G ** t * b
print(ans.mat[0][0])
0