結果

問題 No.762 PDCAパス
ユーザー eQeeQe
提出日時 2020-05-06 00:26:37
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 288 ms / 2,000 ms
コード長 817 bytes
コンパイル時間 280 ms
コンパイル使用メモリ 87,160 KB
実行使用メモリ 90,552 KB
最終ジャッジ日時 2023-09-09 17:55:30
合計ジャッジ時間 10,370 ms
ジャッジサーバーID
(参考情報)
judge14 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 110 ms
78,316 KB
testcase_01 AC 110 ms
78,400 KB
testcase_02 AC 110 ms
78,440 KB
testcase_03 AC 110 ms
78,468 KB
testcase_04 AC 110 ms
78,444 KB
testcase_05 AC 110 ms
78,404 KB
testcase_06 AC 109 ms
78,256 KB
testcase_07 AC 110 ms
78,416 KB
testcase_08 AC 111 ms
78,432 KB
testcase_09 AC 112 ms
78,584 KB
testcase_10 AC 112 ms
78,436 KB
testcase_11 AC 112 ms
78,772 KB
testcase_12 AC 110 ms
78,264 KB
testcase_13 AC 112 ms
78,400 KB
testcase_14 AC 113 ms
78,500 KB
testcase_15 AC 111 ms
78,628 KB
testcase_16 AC 112 ms
78,212 KB
testcase_17 AC 111 ms
78,404 KB
testcase_18 AC 110 ms
78,468 KB
testcase_19 AC 111 ms
78,380 KB
testcase_20 AC 111 ms
78,580 KB
testcase_21 AC 110 ms
78,392 KB
testcase_22 AC 188 ms
83,692 KB
testcase_23 AC 189 ms
83,996 KB
testcase_24 AC 241 ms
90,412 KB
testcase_25 AC 245 ms
90,552 KB
testcase_26 AC 197 ms
84,660 KB
testcase_27 AC 198 ms
84,828 KB
testcase_28 AC 268 ms
88,508 KB
testcase_29 AC 288 ms
88,696 KB
testcase_30 AC 287 ms
87,832 KB
testcase_31 AC 287 ms
88,328 KB
testcase_32 AC 275 ms
87,980 KB
testcase_33 AC 262 ms
87,584 KB
testcase_34 AC 287 ms
88,276 KB
testcase_35 AC 281 ms
88,216 KB
testcase_36 AC 243 ms
86,188 KB
testcase_37 AC 245 ms
86,548 KB
testcase_38 AC 238 ms
86,388 KB
testcase_39 AC 235 ms
86,520 KB
testcase_40 AC 238 ms
86,260 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import cmath
import sys
from collections import deque, defaultdict
from heapq import heappop,heappush
from copy import deepcopy

INF=10**18
MOD=10**9+7
MAX=10**5+7


g=[[] for i in range(MAX)]
mem=[-1]*MAX

def rec(u):
  global s, g, mem

  if s[u]==3: return 1
  if mem[u]!=-1: return mem[u]

  res=0
  for v in g[u]:
    if s[u]+1==s[v]:
      res+=rec(v)
      res%=MOD

  mem[u]=res
  return res


def main():
  global s, g

  N,M=map(int, input().split())

  d={'P':0, 'D':1, 'C':2, 'A':3}

  s=input()
  s=list(map(lambda c: d[c], s))

  for i in range(M):
    u,v=map(int, input().split())
    u-=1
    v-=1

    if s[u]+1==s[v]: g[u].append(v)
    if s[v]+1==s[u]: g[v].append(u)

  ans=0
  for i in range(N):
    if s[i]==0:
      ans+=rec(i)
      ans%=MOD
  print(ans)


if __name__=='__main__':
    main()
0