結果

問題 No.92 逃走経路
ユーザー rlangevin
提出日時 2023-01-16 12:38:07
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 101 ms / 5,000 ms
コード長 575 bytes
コンパイル時間 629 ms
コンパイル使用メモリ 82,432 KB
実行使用メモリ 70,528 KB
最終ジャッジ日時 2024-12-30 18:17:43
合計ジャッジ時間 3,367 ms
ジャッジサーバーID
(参考情報)
judge1 / judge5
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 2
other AC * 18
権限があれば一括ダウンロードができます

ソースコード

diff #

N, M, K = map(int, input().split())
G = [[] for i in range(N)]
for i in range(M):
    a, b, c = map(int, input().split())
    a, b = a - 1 , b - 1
    G[a].append((b, c))
    G[b].append((a, c))

D = list(map(int, input().split()))

pre = [1] * N
for i in range(K):
    dp = [0] * N
    for s in range(N):
        if not pre[s]:
            continue
        for u, c in G[s]:
            if c != D[i]:
                continue
            dp[u] |= pre[s]
    dp, pre = pre, dp

ans = []
for i in range(N):
    if pre[i]:
        ans.append(i + 1)

print(len(ans))
print(*ans)
0