結果

問題 No.762 PDCAパス
ユーザー tails1434tails1434
提出日時 2020-01-14 22:06:42
言語 PyPy3
(7.3.15)
結果
TLE  
実行時間 -
コード長 734 bytes
コンパイル時間 402 ms
コンパイル使用メモリ 86,984 KB
実行使用メモリ 85,004 KB
最終ジャッジ日時 2023-08-27 05:07:33
合計ジャッジ時間 7,488 ms
ジャッジサーバーID
(参考情報)
judge13 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 71 ms
75,980 KB
testcase_01 AC 70 ms
71,412 KB
testcase_02 AC 73 ms
71,688 KB
testcase_03 AC 73 ms
71,596 KB
testcase_04 AC 72 ms
71,392 KB
testcase_05 AC 71 ms
71,468 KB
testcase_06 AC 72 ms
71,372 KB
testcase_07 AC 72 ms
71,680 KB
testcase_08 AC 71 ms
71,476 KB
testcase_09 AC 71 ms
71,412 KB
testcase_10 AC 72 ms
71,448 KB
testcase_11 AC 71 ms
71,424 KB
testcase_12 AC 71 ms
71,436 KB
testcase_13 AC 70 ms
71,364 KB
testcase_14 AC 72 ms
71,368 KB
testcase_15 AC 71 ms
71,324 KB
testcase_16 AC 73 ms
71,456 KB
testcase_17 AC 72 ms
71,692 KB
testcase_18 AC 72 ms
71,616 KB
testcase_19 AC 72 ms
71,456 KB
testcase_20 AC 71 ms
71,492 KB
testcase_21 AC 72 ms
71,372 KB
testcase_22 TLE -
testcase_23 -- -
testcase_24 -- -
testcase_25 -- -
testcase_26 -- -
testcase_27 -- -
testcase_28 -- -
testcase_29 -- -
testcase_30 -- -
testcase_31 -- -
testcase_32 -- -
testcase_33 -- -
testcase_34 -- -
testcase_35 -- -
testcase_36 -- -
testcase_37 -- -
testcase_38 -- -
testcase_39 -- -
testcase_40 -- -
権限があれば一括ダウンロードができます

ソースコード

diff #

import sys
input = sys.stdin.readline

def main():
    N, M = map(int, input().split())
    S = input()
    d = [[] for _ in range(N)]
    for _ in range(M):
        u, v = map(int, input().split())
        u -= 1
        v -= 1
        d[u].append(v)
        d[v].append(u)
    match = 'PDCA'

    def dfs(v,pre,cnt):
        if cnt == 3:
            return 1

        res = 0
        for i in range(len(d[v])):
            u = d[v][i]
            if u == pre:
                continue
            if match[cnt+1] == S[u]:
                res += dfs(u,v,cnt+1)

        return res 


    cnt = 0
    for i, s in enumerate(S):
        if s == 'P':
            cnt += dfs(i,-1,0)

    print(cnt)


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