結果

問題 No.762 PDCAパス
ユーザー matsu7874matsu7874
提出日時 2018-11-28 02:19:00
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
AC  
実行時間 400 ms / 2,000 ms
コード長 911 bytes
コンパイル時間 748 ms
コンパイル使用メモリ 10,804 KB
実行使用メモリ 29,768 KB
最終ジャッジ日時 2023-09-07 08:54:57
合計ジャッジ時間 9,973 ms
ジャッジサーバーID
(参考情報)
judge15 / judge14
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 19 ms
8,516 KB
testcase_01 AC 18 ms
8,556 KB
testcase_02 AC 18 ms
8,600 KB
testcase_03 AC 19 ms
8,488 KB
testcase_04 AC 19 ms
8,564 KB
testcase_05 AC 18 ms
8,584 KB
testcase_06 AC 19 ms
8,496 KB
testcase_07 AC 19 ms
8,612 KB
testcase_08 AC 18 ms
8,592 KB
testcase_09 AC 19 ms
8,552 KB
testcase_10 AC 19 ms
8,528 KB
testcase_11 AC 18 ms
8,596 KB
testcase_12 AC 18 ms
8,564 KB
testcase_13 AC 18 ms
8,492 KB
testcase_14 AC 18 ms
8,632 KB
testcase_15 AC 18 ms
8,528 KB
testcase_16 AC 19 ms
8,628 KB
testcase_17 AC 18 ms
8,528 KB
testcase_18 AC 19 ms
8,596 KB
testcase_19 AC 18 ms
8,520 KB
testcase_20 AC 19 ms
8,524 KB
testcase_21 AC 19 ms
8,532 KB
testcase_22 AC 350 ms
12,340 KB
testcase_23 AC 353 ms
12,364 KB
testcase_24 AC 345 ms
29,768 KB
testcase_25 AC 350 ms
29,756 KB
testcase_26 AC 383 ms
19,480 KB
testcase_27 AC 383 ms
19,420 KB
testcase_28 AC 400 ms
22,560 KB
testcase_29 AC 400 ms
22,712 KB
testcase_30 AC 395 ms
20,692 KB
testcase_31 AC 392 ms
20,684 KB
testcase_32 AC 396 ms
20,728 KB
testcase_33 AC 389 ms
18,112 KB
testcase_34 AC 388 ms
18,056 KB
testcase_35 AC 385 ms
18,100 KB
testcase_36 AC 369 ms
15,060 KB
testcase_37 AC 364 ms
15,292 KB
testcase_38 AC 368 ms
15,132 KB
testcase_39 AC 366 ms
15,112 KB
testcase_40 AC 367 ms
15,104 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import collections
mod = 10**9 + 7

n, m = map(int, input().split())

s = input()

graph = [[] for i in range(n)]
edges = {
    'PD': [],
    'DC': [],
    'CA': [],
}
for _ in range(m):
    u, v = map(lambda x: int(x) - 1, input().split())
    if s[u] == 'P':
        if s[v] == 'D':
            edges['PD'].append((u, v))
    elif s[u] == 'D':
        if s[v] == 'C':
            edges['DC'].append((u, v))
        elif s[v] == 'P':
            edges['PD'].append((v, u))
    elif s[u] == 'C':
        if s[v] == 'A':
            edges['CA'].append((u, v))
        elif s[v] == 'D':
            edges['DC'].append((v, u))
    elif s[u] == 'A':
        if s[v] == 'C':
            edges['CA'].append((v, u))

cnt = collections.defaultdict(int)


for u, v in edges['PD']:
    cnt[v] += 1

for u, v in edges['DC']:
    cnt[v] += cnt[u]

total = 0
for u, v in edges['CA']:
    total += cnt[u]

print(total % mod)
0