結果
問題 |
No.762 PDCAパス
|
ユーザー |
![]() |
提出日時 | 2024-10-11 16:40:02 |
言語 | PyPy3 (7.3.15) |
結果 |
TLE
|
実行時間 | - |
コード長 | 611 bytes |
コンパイル時間 | 356 ms |
コンパイル使用メモリ | 82,304 KB |
実行使用メモリ | 87,168 KB |
最終ジャッジ日時 | 2024-10-11 16:40:11 |
合計ジャッジ時間 | 8,304 ms |
ジャッジサーバーID (参考情報) |
judge2 / judge5 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 23 TLE * 1 -- * 14 |
ソースコード
N,M = map(int,input().split()) S = input() from collections import defaultdict dic = defaultdict(list) for i in range(N): dic[S[i]].append(i) T = "PDCA" DIV = 1000000007 G = [[] for i in range(N)] for _ in range(M): u,v = map(int,input().split()) if S[u - 1] + S[v - 1] in T: G[v - 1].append(u - 1) if S[v - 1] + S[u - 1] in T: G[u - 1].append(v - 1) def dfs(x): if S[x] == "P": return 1 res = 0 for child in G[x]: res += dfs(child) res %= DIV return res ans = 0 for v in dic["A"]: ans += dfs(v) ans %= DIV print(ans)