結果
問題 | No.329 全射 |
ユーザー |
![]() |
提出日時 | 2020-04-03 02:28:25 |
言語 | Python3 (3.13.1 + numpy 2.2.1 + scipy 1.14.1) |
結果 |
AC
|
実行時間 | 574 ms / 2,000 ms |
コード長 | 847 bytes |
コンパイル時間 | 68 ms |
コンパイル使用メモリ | 12,672 KB |
実行使用メモリ | 54,748 KB |
最終ジャッジ日時 | 2024-06-28 17:36:55 |
合計ジャッジ時間 | 23,663 ms |
ジャッジサーバーID (参考情報) |
judge5 / judge2 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 40 |
ソースコード
#!/usr/bin/ python3.8 import sys read = sys.stdin.buffer.read readline = sys.stdin.buffer.readline readlines = sys.stdin.buffer.readlines import numpy as np MOD = 10 ** 9 + 7 N, M = map(int, readline().split()) W = np.array(readline().split(), np.int64) UV = np.array(read().split(), np.int64) - 1 U = UV[::2] V = UV[1::2] A = np.zeros((N, N), np.int64) np.fill_diagonal(A, W) A[U, V] = np.minimum(W[U], W[V]) for k in range(N): A = np.maximum(A, np.minimum(A[:, k][:, None], A[k, :][None, :])) # 全射の数え上げ U = 1000 dp = np.zeros((U + 1, U + 1), np.int64) dp[0, 0] = 1 for n in range(U): dp[n + 1] += np.arange(U + 1, dtype=np.int64) * dp[n] dp[n + 1, 1:] += np.arange(1, U + 1, dtype=np.int64) * dp[n, :-1] dp[n + 1] %= MOD reachable = A == W[None, :] answer = (dp[W][:, W] * reachable).sum() % MOD print(answer)