結果

問題 No.329 全射
ユーザー maspymaspy
提出日時 2020-04-03 02:10:23
言語 Python3
(3.13.1 + numpy 2.2.1 + scipy 1.14.1)
結果
WA  
実行時間 -
コード長 824 bytes
コンパイル時間 166 ms
コンパイル使用メモリ 12,672 KB
実行使用メモリ 52,180 KB
最終ジャッジ日時 2024-06-28 17:08:45
合計ジャッジ時間 31,209 ms
ジャッジサーバーID
(参考情報)
judge2 / judge1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 27 WA * 13
権限があれば一括ダウンロードができます

ソースコード

diff #

#!/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)
IJ = np.array(read().split(), np.int32) - 1
I = IJ[::2]
J = IJ[1::2]

A = np.zeros((N, N), np.int32)
np.fill_diagonal(A, W)
A[I, J] = np.minimum(W[I], W[J])

for i in range(N):
    for j in range(N):
        A[i, j] = np.max(np.minimum(A[i, :], A[:, j]))


# 全射の数え上げ
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) * dp[n]
    dp[n + 1, 1:] += np.arange(1, U + 1) * dp[n, :-1]
    dp[n + 1] %= MOD

reachable = A == W[None, :]
answer = (dp[W][:, W] * reachable).sum() % MOD
print(answer)
0