結果
| 問題 | No.762 PDCAパス | 
| コンテスト | |
| ユーザー |  | 
| 提出日時 | 2022-03-22 18:10:40 | 
| 言語 | PyPy3 (7.3.15) | 
| 結果 | 
                                MLE
                                 
                             | 
| 実行時間 | - | 
| コード長 | 554 bytes | 
| コンパイル時間 | 161 ms | 
| コンパイル使用メモリ | 82,656 KB | 
| 実行使用メモリ | 849,748 KB | 
| 最終ジャッジ日時 | 2024-10-10 10:25:14 | 
| 合計ジャッジ時間 | 5,279 ms | 
| ジャッジサーバーID (参考情報) | judge3 / judge4 | 
(要ログイン)
| ファイルパターン | 結果 | 
|---|---|
| sample | AC * 3 | 
| other | AC * 19 MLE * 1 -- * 18 | 
ソースコード
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)
            
            
            
        