結果
問題 | No.1750 ラムドスウイルスの感染拡大-hard |
ユーザー | 草苺奶昔 |
提出日時 | 2023-03-14 17:49:39 |
言語 | PyPy3 (7.3.15) |
結果 |
AC
|
実行時間 | 1,868 ms / 2,000 ms |
コード長 | 2,810 bytes |
コンパイル時間 | 249 ms |
コンパイル使用メモリ | 82,016 KB |
実行使用メモリ | 79,360 KB |
最終ジャッジ日時 | 2024-09-18 08:19:53 |
合計ジャッジ時間 | 22,546 ms |
ジャッジサーバーID (参考情報) |
judge1 / judge2 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 63 ms
67,200 KB |
testcase_01 | AC | 64 ms
67,456 KB |
testcase_02 | AC | 66 ms
67,968 KB |
testcase_03 | AC | 68 ms
70,016 KB |
testcase_04 | AC | 132 ms
77,952 KB |
testcase_05 | AC | 66 ms
67,200 KB |
testcase_06 | AC | 66 ms
67,584 KB |
testcase_07 | AC | 65 ms
66,944 KB |
testcase_08 | AC | 388 ms
78,336 KB |
testcase_09 | AC | 386 ms
78,720 KB |
testcase_10 | AC | 390 ms
78,592 KB |
testcase_11 | AC | 320 ms
77,696 KB |
testcase_12 | AC | 415 ms
78,464 KB |
testcase_13 | AC | 397 ms
77,696 KB |
testcase_14 | AC | 1,732 ms
78,988 KB |
testcase_15 | AC | 1,776 ms
78,592 KB |
testcase_16 | AC | 1,784 ms
78,976 KB |
testcase_17 | AC | 1,807 ms
78,848 KB |
testcase_18 | AC | 1,868 ms
78,976 KB |
testcase_19 | AC | 1,787 ms
79,360 KB |
testcase_20 | AC | 1,258 ms
78,336 KB |
testcase_21 | AC | 1,465 ms
78,464 KB |
testcase_22 | AC | 326 ms
78,336 KB |
testcase_23 | AC | 1,706 ms
78,848 KB |
testcase_24 | AC | 267 ms
77,696 KB |
testcase_25 | AC | 531 ms
78,336 KB |
testcase_26 | AC | 222 ms
77,952 KB |
testcase_27 | AC | 75 ms
73,728 KB |
testcase_28 | AC | 91 ms
77,696 KB |
testcase_29 | AC | 74 ms
73,728 KB |
testcase_30 | AC | 320 ms
77,440 KB |
testcase_31 | AC | 312 ms
77,568 KB |
testcase_32 | AC | 304 ms
78,080 KB |
testcase_33 | AC | 297 ms
78,220 KB |
ソースコード
from typing import List M = List[List[int]] class MatPow: __slots__ = ("_n", "_mod", "_base", "_cacheLevel", "_useCache", "_cache") def __init__(self, base: M, mod=1000000007, cacheLevel=4): n = len(base) b = [0] * n * n for i in range(n): for j in range(n): b[i * n + j] = base[i][j] useCache = cacheLevel >= 2 self._n = n self._mod = mod self._base = b self._cacheLevel = cacheLevel self._useCache = useCache if useCache: self._cache = [[] for _ in range(cacheLevel - 1)] def pow(self, exp: int) -> M: if not self._useCache: return self._powWithOutCache(exp) if len(self._cache[0]) == 0: self._cache[0].append(self._base) for i in range(1, self._cacheLevel - 1): self._cache[i].append(self._mul(self._cache[i - 1][0], self._base)) e = self._eye(self._n) div = 0 while exp: if div == len(self._cache[0]): self._cache[0].append( self._mul(self._cache[self._cacheLevel - 2][div - 1], self._cache[0][div - 1]) ) for i in range(1, self._cacheLevel - 1): self._cache[i].append(self._mul(self._cache[i - 1][div], self._cache[0][div])) mod = exp % self._cacheLevel if mod: e = self._mul(e, self._cache[mod - 1][div]) exp //= self._cacheLevel div += 1 return self._to2D(e) def _mul(self, mat1: List[int], mat2: List[int]) -> List[int]: n = self._n res = [0] * n * n for i in range(n): for k in range(n): for j in range(n): res[i * n + j] = ( res[i * n + j] + mat1[i * n + k] * mat2[k * n + j] ) % self._mod return res def _powWithOutCache(self, exp: int) -> M: e = self._eye(self._n) b = self._base[:] while exp: if exp & 1: e = self._mul(e, b) exp >>= 1 b = self._mul(b, b) return self._to2D(e) def _eye(self, n: int) -> List[int]: res = [0] * n * n for i in range(n): res[i * n + i] = 1 return res def _to2D(self, mat: List[int]) -> M: n = self._n return [mat[i * n : (i + 1) * n] for i in range(n)] def __pow__(self, exp: int) -> M: return self.pow(exp) n, m, k = map(int, input().split()) adjMatrix = [[0] * n for _ in range(n)] for _ in range(m): u, v = map(int, input().split()) adjMatrix[u][v] = 1 adjMatrix[v][u] = 1 P = MatPow(adjMatrix, 998244353, cacheLevel=-1) res = P.pow(k)[0][0] print(res)