結果

問題 No.762 PDCAパス
ユーザー eQeeQe
提出日時 2020-05-06 00:35:49
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 302 ms / 2,000 ms
コード長 823 bytes
コンパイル時間 279 ms
コンパイル使用メモリ 86,864 KB
実行使用メモリ 90,196 KB
最終ジャッジ日時 2023-09-09 18:08:19
合計ジャッジ時間 9,574 ms
ジャッジサーバーID
(参考情報)
judge11 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 112 ms
78,152 KB
testcase_01 AC 111 ms
78,000 KB
testcase_02 AC 112 ms
78,256 KB
testcase_03 AC 111 ms
78,052 KB
testcase_04 AC 110 ms
78,260 KB
testcase_05 AC 109 ms
78,052 KB
testcase_06 AC 111 ms
78,112 KB
testcase_07 AC 112 ms
78,252 KB
testcase_08 AC 112 ms
78,260 KB
testcase_09 AC 111 ms
78,328 KB
testcase_10 AC 110 ms
78,156 KB
testcase_11 AC 111 ms
78,168 KB
testcase_12 AC 110 ms
78,140 KB
testcase_13 AC 112 ms
78,172 KB
testcase_14 AC 111 ms
78,360 KB
testcase_15 AC 112 ms
78,256 KB
testcase_16 AC 112 ms
78,076 KB
testcase_17 AC 112 ms
78,064 KB
testcase_18 AC 110 ms
78,108 KB
testcase_19 AC 112 ms
78,060 KB
testcase_20 AC 111 ms
78,172 KB
testcase_21 AC 112 ms
78,004 KB
testcase_22 AC 201 ms
83,468 KB
testcase_23 AC 190 ms
83,556 KB
testcase_24 AC 248 ms
90,196 KB
testcase_25 AC 247 ms
90,112 KB
testcase_26 AC 197 ms
84,608 KB
testcase_27 AC 196 ms
84,504 KB
testcase_28 AC 280 ms
88,148 KB
testcase_29 AC 302 ms
88,260 KB
testcase_30 AC 288 ms
87,468 KB
testcase_31 AC 287 ms
88,088 KB
testcase_32 AC 284 ms
87,624 KB
testcase_33 AC 270 ms
87,420 KB
testcase_34 AC 291 ms
87,944 KB
testcase_35 AC 285 ms
87,996 KB
testcase_36 AC 242 ms
86,192 KB
testcase_37 AC 243 ms
86,520 KB
testcase_38 AC 242 ms
86,072 KB
testcase_39 AC 241 ms
86,264 KB
testcase_40 AC 242 ms
86,064 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

s=None
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