結果

問題 No.1750 ラムドスウイルスの感染拡大-hard
ユーザー NatsubiSoganNatsubiSogan
提出日時 2021-11-20 15:56:51
言語 PyPy3
(7.3.15)
結果
TLE  
実行時間 -
コード長 1,624 bytes
コンパイル時間 778 ms
コンパイル使用メモリ 86,980 KB
実行使用メモリ 145,504 KB
最終ジャッジ日時 2023-09-02 10:39:29
合計ジャッジ時間 10,756 ms
ジャッジサーバーID
(参考情報)
judge16 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 166 ms
84,160 KB
testcase_01 AC 172 ms
80,192 KB
testcase_02 AC 173 ms
81,204 KB
testcase_03 AC 179 ms
81,692 KB
testcase_04 AC 297 ms
83,984 KB
testcase_05 AC 168 ms
80,240 KB
testcase_06 AC 171 ms
80,184 KB
testcase_07 AC 166 ms
80,128 KB
testcase_08 AC 707 ms
89,012 KB
testcase_09 AC 679 ms
88,400 KB
testcase_10 AC 739 ms
89,752 KB
testcase_11 AC 705 ms
91,080 KB
testcase_12 AC 844 ms
94,520 KB
testcase_13 AC 881 ms
94,212 KB
testcase_14 TLE -
testcase_15 -- -
testcase_16 -- -
testcase_17 -- -
testcase_18 -- -
testcase_19 -- -
testcase_20 -- -
testcase_21 -- -
testcase_22 -- -
testcase_23 -- -
testcase_24 -- -
testcase_25 -- -
testcase_26 -- -
testcase_27 -- -
testcase_28 -- -
testcase_29 -- -
testcase_30 -- -
testcase_31 -- -
testcase_32 -- -
testcase_33 -- -
権限があれば一括ダウンロードができます

ソースコード

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]

	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]
			for i in range(self.n):
				for j in range(other.m): 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(self.n, self.n)
		for i in range(self.n):
			res[i][i] = 1
		while k:
			if k & 1:
				res *= tmp
			tmp *= tmp
			k >>= 1
		return res

def main():
	import sys
	input = sys.stdin.buffer.readline
	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)
	G **= t
	b = [[0] * n for i in range(n)]
	b[0][0] = 1
	G *= Matrix(n, n, b)
	print(G.mat[0][0])
if __name__ == '__main__':
	main()
	
0