結果

問題 No.762 PDCAパス
ユーザー brthyyjpbrthyyjp
提出日時 2021-04-30 18:06:31
言語 PyPy3
(7.3.15)
結果
TLE  
実行時間 -
コード長 833 bytes
コンパイル時間 1,370 ms
コンパイル使用メモリ 87,140 KB
実行使用メモリ 71,584 KB
最終ジャッジ日時 2023-09-25 19:01:02
合計ジャッジ時間 6,694 ms
ジャッジサーバーID
(参考情報)
judge15 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 77 ms
71,156 KB
testcase_01 AC 74 ms
71,584 KB
testcase_02 AC 74 ms
71,480 KB
testcase_03 AC 75 ms
71,432 KB
testcase_04 AC 75 ms
70,976 KB
testcase_05 AC 75 ms
71,328 KB
testcase_06 AC 75 ms
71,112 KB
testcase_07 AC 76 ms
71,348 KB
testcase_08 AC 76 ms
71,336 KB
testcase_09 AC 75 ms
71,120 KB
testcase_10 AC 76 ms
71,196 KB
testcase_11 AC 76 ms
71,584 KB
testcase_12 AC 74 ms
71,372 KB
testcase_13 AC 75 ms
71,384 KB
testcase_14 AC 75 ms
71,152 KB
testcase_15 AC 75 ms
71,120 KB
testcase_16 AC 75 ms
71,200 KB
testcase_17 AC 73 ms
71,200 KB
testcase_18 AC 74 ms
71,180 KB
testcase_19 AC 75 ms
71,312 KB
testcase_20 AC 76 ms
71,484 KB
testcase_21 AC 77 ms
71,268 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 #

import sys
import io, os
sys.setrecursionlimit(10**9)
input = sys.stdin.readline

n, m = map(int, input().split())
s = str(input().rstrip())
g = [[] for i in range(n)]
mod = 10**9+7
for i in range(m):
    u, v = map(int, input().split())
    u, v = u-1, v-1
    g[u].append(v)
    g[v].append(u)

memo = {}
def dfs(v, A):
    if len(A) == 4:
        return 1
    if v in memo:
        return v
    ret = 0
    for u in g[v]:
        if A[-1] == 'P':
            if s[u] == 'D':
                ret += dfs(u, A+[s[u]])
        elif A[-1] == 'D':
            if s[u] == 'C':
                ret += dfs(u, A+[s[u]])
        elif A[-1] == 'C':
            if s[u] == 'A':
                ret += dfs(u, A+[s[u]])
    return ret
ans = 0
for v in range(n):
    if s[v] == 'P':
        ans += dfs(v, ['P'])
        ans %= mod
print(ans%mod)
0