結果

問題 No.92 逃走経路
ユーザー lloyzlloyz
提出日時 2022-09-08 00:11:34
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
AC  
実行時間 527 ms / 5,000 ms
コード長 723 bytes
コンパイル時間 339 ms
コンパイル使用メモリ 10,820 KB
実行使用メモリ 9,784 KB
最終ジャッジ日時 2023-08-15 09:25:41
合計ジャッジ時間 5,618 ms
ジャッジサーバーID
(参考情報)
judge13 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 215 ms
9,784 KB
testcase_01 AC 19 ms
8,600 KB
testcase_02 AC 19 ms
8,560 KB
testcase_03 AC 19 ms
8,656 KB
testcase_04 AC 19 ms
8,588 KB
testcase_05 AC 489 ms
8,852 KB
testcase_06 AC 303 ms
8,960 KB
testcase_07 AC 303 ms
8,848 KB
testcase_08 AC 25 ms
9,560 KB
testcase_09 AC 97 ms
9,616 KB
testcase_10 AC 482 ms
9,232 KB
testcase_11 AC 492 ms
9,212 KB
testcase_12 AC 527 ms
9,756 KB
testcase_13 AC 62 ms
9,472 KB
testcase_14 AC 79 ms
9,504 KB
testcase_15 AC 130 ms
9,692 KB
testcase_16 AC 129 ms
9,544 KB
testcase_17 AC 191 ms
9,764 KB
testcase_18 AC 211 ms
9,336 KB
testcase_19 AC 204 ms
9,136 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

from collections import defaultdict, deque

n, m, k = map(int, input().split())
edge = defaultdict(list)
for _ in range(m):
    a, b, c = map(int, input().split())
    edge[a].append((b, c))
    edge[b].append((a, c))
D = [0] + list(map(int, input().split()))
Que = deque()
for i in range(1, n + 1):
    Que.append((i, 0))
ANS = []
Seen = [[False for _ in range(n + 1)] for _ in range(k + 1)]
while Que:
    cp, cnt = Que.popleft()
    if cnt == k:
        ANS.append(cp)
        continue
    for np, c in edge[cp]:
        if D[cnt + 1] != c:
            continue
        if Seen[cnt + 1][np]:
            continue
        Seen[cnt + 1][np] = True
        Que.append((np, cnt + 1))

ANS.sort()
print(len(ANS))
print(*ANS)
0