結果

問題 No.762 PDCAパス
ユーザー matsu7874matsu7874
提出日時 2018-11-28 01:45:07
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
RE  
実行時間 -
コード長 728 bytes
コンパイル時間 772 ms
コンパイル使用メモリ 10,860 KB
実行使用メモリ 14,376 KB
最終ジャッジ日時 2023-09-07 07:47:22
合計ジャッジ時間 6,258 ms
ジャッジサーバーID
(参考情報)
judge12 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 17 ms
7,828 KB
testcase_01 AC 16 ms
7,772 KB
testcase_02 AC 17 ms
7,936 KB
testcase_03 AC 16 ms
7,876 KB
testcase_04 AC 16 ms
7,768 KB
testcase_05 AC 16 ms
7,828 KB
testcase_06 AC 16 ms
7,840 KB
testcase_07 AC 17 ms
7,856 KB
testcase_08 AC 17 ms
7,848 KB
testcase_09 AC 17 ms
7,872 KB
testcase_10 AC 17 ms
7,852 KB
testcase_11 AC 17 ms
7,812 KB
testcase_12 AC 16 ms
7,820 KB
testcase_13 AC 16 ms
7,796 KB
testcase_14 AC 16 ms
7,772 KB
testcase_15 AC 17 ms
7,812 KB
testcase_16 AC 17 ms
7,900 KB
testcase_17 AC 16 ms
7,860 KB
testcase_18 AC 16 ms
7,808 KB
testcase_19 AC 17 ms
7,840 KB
testcase_20 AC 17 ms
7,776 KB
testcase_21 AC 17 ms
7,840 KB
testcase_22 AC 336 ms
12,924 KB
testcase_23 AC 337 ms
12,784 KB
testcase_24 RE -
testcase_25 RE -
testcase_26 AC 374 ms
14,376 KB
testcase_27 AC 370 ms
14,180 KB
testcase_28 RE -
testcase_29 RE -
testcase_30 RE -
testcase_31 RE -
testcase_32 RE -
testcase_33 RE -
testcase_34 RE -
testcase_35 RE -
testcase_36 RE -
testcase_37 RE -
testcase_38 RE -
testcase_39 RE -
testcase_40 RE -
権限があれば一括ダウンロードができます

ソースコード

diff #

mod = 10**9 + 7

n, m = map(int, input().split())
assert 2 <= n < 10**5
assert 0 <= m < 10**5

s = input()
assert len(s) == n
assert all(c in 'PCDA' for c in s)

graph = [[] for i in range(n)]
for _ in range(m):
    u, v = map(int, input().split())
    assert 1 <= u < v <= n
    graph[u - 1].append(v - 1)
    graph[v - 1].append(u - 1)


nodes = {c: [] for c in 'PDCA'}
pre = {
    'D': 'P',
    'C': 'D',
    'A': 'C',
}
for i in range(n):
    nodes[s[i]].append(i)


cnt = [1 if s[i] == 'P' else 0 for i in range(n)]
for c in 'DCA':
    for v in nodes[c]:
        for u in graph[v]:
            if s[u] == pre[c]:
                cnt[v] += cnt[u]
                cnt[v] %= mod
print(sum([cnt[v] for v in nodes['A']]) % mod)
0