結果

問題 No.762 PDCAパス
ユーザー matsu7874
提出日時 2018-11-28 02:19:00
言語 Python3
(3.13.1 + numpy 2.2.1 + scipy 1.14.1)
結果
AC  
実行時間 472 ms / 2,000 ms
コード長 911 bytes
コンパイル時間 1,170 ms
コンパイル使用メモリ 12,672 KB
実行使用メモリ 32,196 KB
最終ジャッジ日時 2024-06-25 03:14:19
合計ジャッジ時間 11,016 ms
ジャッジサーバーID
(参考情報)
judge2 / judge5
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 38
権限があれば一括ダウンロードができます

ソースコード

diff #

import collections
mod = 10**9 + 7

n, m = map(int, input().split())

s = input()

graph = [[] for i in range(n)]
edges = {
    'PD': [],
    'DC': [],
    'CA': [],
}
for _ in range(m):
    u, v = map(lambda x: int(x) - 1, input().split())
    if s[u] == 'P':
        if s[v] == 'D':
            edges['PD'].append((u, v))
    elif s[u] == 'D':
        if s[v] == 'C':
            edges['DC'].append((u, v))
        elif s[v] == 'P':
            edges['PD'].append((v, u))
    elif s[u] == 'C':
        if s[v] == 'A':
            edges['CA'].append((u, v))
        elif s[v] == 'D':
            edges['DC'].append((v, u))
    elif s[u] == 'A':
        if s[v] == 'C':
            edges['CA'].append((v, u))

cnt = collections.defaultdict(int)


for u, v in edges['PD']:
    cnt[v] += 1

for u, v in edges['DC']:
    cnt[v] += cnt[u]

total = 0
for u, v in edges['CA']:
    total += cnt[u]

print(total % mod)
0