結果
問題 | No.1340 おーじ君をさがせ |
ユーザー |
![]() |
提出日時 | 2021-01-16 02:50:14 |
言語 | PyPy3 (7.3.15) |
結果 |
AC
|
実行時間 | 946 ms / 2,000 ms |
コード長 | 1,131 bytes |
コンパイル時間 | 646 ms |
コンパイル使用メモリ | 82,380 KB |
実行使用メモリ | 80,256 KB |
最終ジャッジ日時 | 2024-11-27 23:28:11 |
合計ジャッジ時間 | 15,858 ms |
ジャッジサーバーID (参考情報) |
judge1 / judge2 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 59 |
ソースコード
import syssys.setrecursionlimit(10**7)def I(): return int(sys.stdin.readline().rstrip())def MI(): return map(int,sys.stdin.readline().rstrip().split())def LI(): return list(map(int,sys.stdin.readline().rstrip().split()))def LI2(): return list(map(int,sys.stdin.readline().rstrip()))def S(): return sys.stdin.readline().rstrip()def LS(): return list(sys.stdin.readline().rstrip().split())def LS2(): return list(sys.stdin.readline().rstrip())def matrix_multiplication(A,B):l = len(A)m = len(B)n = len(B[0])C = [[0]*n for _ in range(l)]for i in range(l):for j in range(n):for k in range(m):C[i][j] |= A[i][k] & B[k][j]return Cdef matrix_power(A,n):l = len(A)C = [[0]*l for _ in range(l)]for i in range(l):C[i][i] = 1while n > 0:if n % 2 == 1:C = matrix_multiplication(C,A)A = matrix_multiplication(A,A)n >>= 1return CN,M,T = MI()Graph = [[0]*N for _ in range(N)]for _ in range(M):a,b = MI()Graph[a][b] = 1X = matrix_power(Graph,T)ans = sum(X[0])print(ans)