結果

問題 No.762 PDCAパス
ユーザー ntudantuda
提出日時 2022-10-30 22:27:16
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
TLE  
実行時間 -
コード長 611 bytes
コンパイル時間 163 ms
コンパイル使用メモリ 10,896 KB
実行使用メモリ 30,056 KB
最終ジャッジ日時 2023-09-21 20:20:48
合計ジャッジ時間 5,086 ms
ジャッジサーバーID
(参考情報)
judge14 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 20 ms
12,976 KB
testcase_01 AC 20 ms
8,660 KB
testcase_02 AC 19 ms
8,652 KB
testcase_03 AC 19 ms
8,608 KB
testcase_04 AC 18 ms
8,596 KB
testcase_05 AC 19 ms
8,604 KB
testcase_06 AC 18 ms
8,612 KB
testcase_07 AC 19 ms
8,556 KB
testcase_08 AC 19 ms
8,616 KB
testcase_09 AC 22 ms
8,624 KB
testcase_10 AC 19 ms
8,676 KB
testcase_11 AC 19 ms
8,632 KB
testcase_12 AC 18 ms
8,588 KB
testcase_13 AC 19 ms
8,612 KB
testcase_14 AC 18 ms
8,604 KB
testcase_15 AC 18 ms
8,676 KB
testcase_16 AC 19 ms
8,604 KB
testcase_17 AC 19 ms
8,588 KB
testcase_18 AC 18 ms
8,720 KB
testcase_19 AC 19 ms
8,700 KB
testcase_20 AC 18 ms
8,712 KB
testcase_21 AC 19 ms
8,704 KB
testcase_22 TLE -
testcase_23 -- -
testcase_24 -- -
testcase_25 -- -
testcase_26 -- -
testcase_27 -- -
testcase_28 -- -
testcase_29 -- -
testcase_30 -- -
testcase_31 -- -
testcase_32 -- -
testcase_33 -- -
testcase_34 -- -
testcase_35 -- -
testcase_36 -- -
testcase_37 -- -
testcase_38 -- -
testcase_39 -- -
testcase_40 -- -
権限があれば一括ダウンロードができます

ソースコード

diff #

from functools import lru_cache
MOD = 10 ** 9 + 7
N, M = map(int, input().split())
S = input()
UV = [list(map(int, input().split())) for _ in range(M)]
E = [[] for _ in range(N)]
A = ["P", "D", "C", "A"]

for u, v in UV:
    u -= 1
    v -= 1
    a = A.index(S[u])
    if a < 3 and S[v] == A[a + 1]:
        E[u].append(v)
    if 0 < a and S[v] == A[a - 1]:
        E[v].append(u)

@lru_cache()
def dfs(x):
    if S[x] == "A":
        return 1
    ret = 0
    for v in E[x]:
        ret += dfs(v)
    return ret

ans = 0
for i in range(N):
    if S[i] == "P":
        ans += dfs(i)
        ans %= MOD
print(ans)
0