結果

問題 No.762 PDCAパス
ユーザー DrDrpilot
提出日時 2022-01-24 18:29:30
言語 Python3
(3.13.1 + numpy 2.2.1 + scipy 1.14.1)
結果
MLE  
実行時間 -
コード長 554 bytes
コンパイル時間 320 ms
コンパイル使用メモリ 13,056 KB
実行使用メモリ 776,576 KB
最終ジャッジ日時 2024-12-14 16:57:24
合計ジャッジ時間 24,035 ms
ジャッジサーバーID
(参考情報)
judge5 / judge2
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 2 MLE * 1
other AC * 31 TLE * 4 MLE * 3
権限があれば一括ダウンロードができます

ソースコード

diff #

n,m=map(int,input().split())
S='PDCA'
s='#'+input()
g=[[] for _ in range(n+1)]
for _ in range(m):
    u,v=map(int,input().split())
    if S.index(s[u])-S.index(s[v])==1:
        g[v].append(u)
    elif S.index(s[v])-S.index(s[u])==1:
        g[u].append(v)
from collections import deque
q=deque()
mod=10**9+7
ans=0
for i in range(1,n+1):
    if s[i]=='P' and len(g[i])>0:
        q.append((i,1))
while q:
    now,cnt=q.popleft()
    if cnt==4:
        ans+=1
        ans%=mod
        continue
    for to in g[now]:
        q.append((to,cnt+1))
print(ans)
0