結果

問題 No.92 逃走経路
ユーザー lloyz
提出日時 2022-09-08 00:11:34
言語 Python3
(3.13.1 + numpy 2.2.1 + scipy 1.14.1)
結果
AC  
実行時間 571 ms / 5,000 ms
コード長 723 bytes
コンパイル時間 115 ms
コンパイル使用メモリ 12,800 KB
実行使用メモリ 11,904 KB
最終ジャッジ日時 2024-11-23 15:32:46
合計ジャッジ時間 5,627 ms
ジャッジサーバーID
(参考情報)
judge4 / judge3
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 2
other AC * 18
権限があれば一括ダウンロードができます

ソースコード

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