結果

問題 No.762 PDCAパス
ユーザー R ITSUMI
提出日時 2020-06-23 23:34:33
言語 PyPy3
(7.3.15)
結果
TLE  
実行時間 -
コード長 711 bytes
コンパイル時間 156 ms
コンパイル使用メモリ 82,432 KB
実行使用メモリ 95,872 KB
最終ジャッジ日時 2024-07-03 19:35:25
合計ジャッジ時間 5,945 ms
ジャッジサーバーID
(参考情報)
judge3 / judge4
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 19 TLE * 1 -- * 18
権限があれば一括ダウンロードができます

ソースコード

diff #

import sys
sys.setrecursionlimit(10**7)
N, M = map(int, input().split())
S = input()
G = [list(map(int, input().split())) for _ in range(M)]
edges = [[] for _ in range(N)]
for a, b in G:
    edges[a - 1].append(b - 1)
    edges[b - 1].append(a - 1)
def dfs(start,path):
    ans = 0
    check = 'PDCA'
    path.append(S[start])
    for i in range(min(4,len(path))):
        if path[i] != check[i]:
            path.pop()
            return 0
    if ''.join(path) == 'PDCA':
        path.pop()
        return 1
    elif len(path) > 4:
        path.pop()
        return 0
    for i in edges[start]:
        ans += dfs(i,path)
    path.pop()
    return ans
ans = 0
for i in range(N):
    ans += dfs(i,[])
print(ans)
0