結果

問題 No.762 PDCAパス
ユーザー ntudantuda
提出日時 2022-10-30 22:26:31
言語 PyPy3
(7.3.15)
結果
TLE  
実行時間 -
コード長 611 bytes
コンパイル時間 312 ms
コンパイル使用メモリ 87,080 KB
実行使用メモリ 94,292 KB
最終ジャッジ日時 2023-09-21 20:20:07
合計ジャッジ時間 7,167 ms
ジャッジサーバーID
(参考情報)
judge12 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 109 ms
76,752 KB
testcase_01 AC 107 ms
72,604 KB
testcase_02 AC 106 ms
72,484 KB
testcase_03 AC 106 ms
72,400 KB
testcase_04 AC 105 ms
72,436 KB
testcase_05 AC 105 ms
72,216 KB
testcase_06 AC 105 ms
72,508 KB
testcase_07 AC 105 ms
72,340 KB
testcase_08 AC 106 ms
72,436 KB
testcase_09 AC 106 ms
72,472 KB
testcase_10 AC 105 ms
72,408 KB
testcase_11 AC 108 ms
72,376 KB
testcase_12 AC 107 ms
72,212 KB
testcase_13 AC 105 ms
72,372 KB
testcase_14 AC 106 ms
72,544 KB
testcase_15 AC 106 ms
72,496 KB
testcase_16 AC 107 ms
72,484 KB
testcase_17 AC 108 ms
72,208 KB
testcase_18 AC 106 ms
72,208 KB
testcase_19 AC 109 ms
72,464 KB
testcase_20 AC 106 ms
72,404 KB
testcase_21 AC 106 ms
72,404 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