結果

問題 No.1750 ラムドスウイルスの感染拡大-hard
ユーザー Kome_soudou
提出日時 2022-03-11 01:20:08
言語 PyPy3
(7.3.15)
結果
TLE  
実行時間 -
コード長 763 bytes
コンパイル時間 221 ms
コンパイル使用メモリ 81,892 KB
実行使用メモリ 77,320 KB
最終ジャッジ日時 2024-09-15 01:20:20
合計ジャッジ時間 25,688 ms
ジャッジサーバーID
(参考情報)
judge6 / judge1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 4
other AC * 23 TLE * 7
権限があれば一括ダウンロードができます

ソースコード

diff #

import sys
input = sys.stdin.buffer.readline

# 行列の乗算(mod)
def mat_mul(a, b, mod):
	I, K, J = len(a), len(b), len(b[0])
	c = [[0 for j in range(J)] for i in range(I)]
	for i in range(I):
		for k in range(K):
			for j in range(J):
				c[i][j] += a[i][k] * b[k][j]
				c[i][j] %= mod
	return c

# 行列の累乗(mod)
def mat_pow(a, n, mod):
	b = [[0 for j in range(len(a))] for i in range(len(a))]
	for i in range(len(a)):
		b[i][i] = 1
	while n > 0:
		if n & 1:
			b = mat_mul(b, a, mod)
		a = mat_mul(a, a, mod)
		n >>= 1
	return b

N, M, T = map(int, input().split())
G = [[0 for j in range(N)] for i in range(N)]
mod = 998244353
for i in range(M):
	s, t = map(int, input().split())
	G[s][t] = 1
	G[t][s] = 1

ans = mat_pow(G, T, mod)
print(ans[0][0])
0