結果

問題 No.762 PDCAパス
ユーザー matsu7874matsu7874
提出日時 2018-11-28 01:52:01
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
WA  
実行時間 -
コード長 717 bytes
コンパイル時間 104 ms
コンパイル使用メモリ 10,928 KB
実行使用メモリ 29,744 KB
最終ジャッジ日時 2023-09-07 08:05:38
合計ジャッジ時間 11,150 ms
ジャッジサーバーID
(参考情報)
judge13 / judge14
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 16 ms
7,832 KB
testcase_01 AC 16 ms
7,860 KB
testcase_02 AC 16 ms
7,788 KB
testcase_03 AC 16 ms
7,832 KB
testcase_04 AC 16 ms
7,856 KB
testcase_05 AC 15 ms
7,780 KB
testcase_06 AC 16 ms
7,880 KB
testcase_07 AC 16 ms
7,928 KB
testcase_08 AC 16 ms
7,856 KB
testcase_09 AC 16 ms
7,852 KB
testcase_10 AC 16 ms
7,788 KB
testcase_11 AC 15 ms
7,860 KB
testcase_12 AC 16 ms
7,780 KB
testcase_13 AC 16 ms
7,880 KB
testcase_14 AC 16 ms
7,812 KB
testcase_15 AC 16 ms
7,820 KB
testcase_16 AC 16 ms
7,792 KB
testcase_17 AC 16 ms
7,876 KB
testcase_18 AC 16 ms
7,928 KB
testcase_19 AC 16 ms
7,880 KB
testcase_20 AC 17 ms
7,876 KB
testcase_21 AC 16 ms
7,856 KB
testcase_22 AC 328 ms
13,024 KB
testcase_23 AC 328 ms
13,096 KB
testcase_24 AC 421 ms
28,172 KB
testcase_25 AC 416 ms
28,440 KB
testcase_26 WA -
testcase_27 WA -
testcase_28 AC 536 ms
29,744 KB
testcase_29 AC 535 ms
29,600 KB
testcase_30 AC 505 ms
26,372 KB
testcase_31 AC 507 ms
26,420 KB
testcase_32 AC 506 ms
26,388 KB
testcase_33 AC 470 ms
22,844 KB
testcase_34 AC 463 ms
22,828 KB
testcase_35 AC 472 ms
22,872 KB
testcase_36 AC 417 ms
18,684 KB
testcase_37 AC 414 ms
18,728 KB
testcase_38 AC 426 ms
18,716 KB
testcase_39 AC 417 ms
18,704 KB
testcase_40 AC 411 ms
18,740 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

# mod = 10**9 + 7しないと落ちる

n, m = map(int, input().split())
assert 2 <= n <= 10**5
assert 0 <= m <= 10**5

s = input()
assert len(s) == n
assert all(c in 'PCDA' for c in s)

graph = [[] for i in range(n)]
for _ in range(m):
    u, v = map(int, input().split())
    assert 1 <= u < v <= n
    graph[u - 1].append(v - 1)
    graph[v - 1].append(u - 1)


nodes = {c: [] for c in 'PDCA'}
pre = {
    'D': 'P',
    'C': 'D',
    'A': 'C',
}
for i in range(n):
    nodes[s[i]].append(i)


cnt = [1 if s[i] == 'P' else 0 for i in range(n)]
for c in 'DCA':
    for v in nodes[c]:
        for u in graph[v]:
            if s[u] == pre[c]:
                cnt[v] += cnt[u]
print(sum([cnt[v] for v in nodes['A']]))
0