結果

問題 No.762 PDCAパス
コンテスト
ユーザー tonnnura172
提出日時 2020-04-11 20:15:18
言語 PyPy3
(7.3.17)
コンパイル:
pypy3 -mpy_compile _filename_
実行:
pypy3 _filename_
結果
RE  
(最新)
AC  
(最初)
実行時間 -
コード長 1,194 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 120 ms
コンパイル使用メモリ 85,376 KB
実行使用メモリ 90,624 KB
最終ジャッジ日時 2026-04-07 17:43:14
合計ジャッジ時間 6,895 ms
ジャッジサーバーID
(参考情報)
judge1_0 / judge3_0
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample RE * 3
other RE * 38
権限があれば一括ダウンロードができます

ソースコード

diff #
raw source code

import sys, re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians
from itertools import accumulate, permutations, combinations, product
from operator import itemgetter, mul, add
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from bisect import bisect, bisect_left
from fractions import gcd
from heapq import heappush, heappop
from functools import reduce, lru_cache
def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
def ZIP(n): return zip(*(MAP() for _ in range(n)))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7

N, M = MAP()
S = input()
graph = [[] for _ in range(N)]

for _ in range(M):
	a, b = MAP()
	graph[a-1].append(b-1)
	graph[b-1].append(a-1)

step = {"P":1, "D":2, "C":3, "A":4}

@lru_cache(maxsize=None)
def DFS(n, s):
	if s == 4:
		return 1

	ret = 0
	for node in graph[n]:
		if s+1 == step[S[node]]:
			ret += DFS(node, s+1)
	return ret

ans = 0
for i in range(N):
	if S[i] == "P":
		ans += DFS(i, 1)
		ans %= mod
print(ans)
0