結果
| 問題 | No.1340 おーじ君をさがせ |
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2021-01-15 22:41:40 |
| 言語 | Python3 (3.13.1 + numpy 2.2.1 + scipy 1.14.1) |
| 結果 |
AC
|
| 実行時間 | 660 ms / 2,000 ms |
| コード長 | 601 bytes |
| 記録 | |
| コンパイル時間 | 368 ms |
| コンパイル使用メモリ | 12,672 KB |
| 実行使用メモリ | 44,348 KB |
| 最終ジャッジ日時 | 2024-11-27 23:15:53 |
| 合計ジャッジ時間 | 38,590 ms |
|
ジャッジサーバーID (参考情報) |
judge1 / judge2 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 59 |
ソースコード
import numpy as np
def pow_matrix_mod(x, n):
if not n:
return np.eye(len(x), dtype=int)
if n % 2 == 0:
return pow_matrix_mod(np.where((x @ x) != 0, 1, 0), n // 2)
else:
tmp = pow_matrix_mod(np.where((x @ x) != 0, 1, 0), (n - 1) // 2)
return np.where((x @ tmp) != 0, 1, 0)
N, M, T = map(int, input().split())
matr = [[0] * N for _ in range(N)]
for _ in range(M):
a, b = map(int, input().split())
matr[a][b] = 1
matr = np.array(matr)
first = np.zeros(N, dtype=int)
first[0] = 1
ans = np.count_nonzero(first @ pow_matrix_mod(matr, T))
print(ans)