結果

問題 No.92 逃走経路
ユーザー hiragnhiragn
提出日時 2022-11-29 06:25:24
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
AC  
実行時間 201 ms / 5,000 ms
コード長 836 bytes
コンパイル時間 85 ms
コンパイル使用メモリ 12,800 KB
実行使用メモリ 11,776 KB
最終ジャッジ日時 2024-04-16 02:53:42
合計ジャッジ時間 2,462 ms
ジャッジサーバーID
(参考情報)
judge5 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 82 ms
11,648 KB
testcase_01 AC 30 ms
10,752 KB
testcase_02 AC 30 ms
10,752 KB
testcase_03 AC 30 ms
10,752 KB
testcase_04 AC 30 ms
10,752 KB
testcase_05 AC 201 ms
11,008 KB
testcase_06 AC 70 ms
11,008 KB
testcase_07 AC 70 ms
11,008 KB
testcase_08 AC 31 ms
11,776 KB
testcase_09 AC 40 ms
11,776 KB
testcase_10 AC 200 ms
11,264 KB
testcase_11 AC 185 ms
11,520 KB
testcase_12 AC 201 ms
11,648 KB
testcase_13 AC 37 ms
11,648 KB
testcase_14 AC 44 ms
11,648 KB
testcase_15 AC 55 ms
11,648 KB
testcase_16 AC 60 ms
11,648 KB
testcase_17 AC 79 ms
11,648 KB
testcase_18 AC 73 ms
11,264 KB
testcase_19 AC 70 ms
11,136 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

def main():
    n, m, k = map(int, input().split())

    paths = []
    for _ in range(m):
        a, b, c = map(int, input().split())
        paths.append([a, b, c])
    d = [0] + list(map(int, input().split()))

    # dp[i][j]=(i回の移動後に街jにいる可能性があるかどうか)
    dp = [[False] * (n + 1) for _ in range(k + 1)]
    # 1回目
    for a, b, c in paths:
        if c == d[1]:
            dp[1][a] = True
            dp[1][b] = True

    # 2回目以降
    for i in range(2, k + 1):
        for a, b, c in paths:
            if c == d[i]:
                if dp[i - 1][a]:
                    dp[i][b] = True
                if dp[i - 1][b]:
                    dp[i][a] = True

    ans = [i for i in range(1, n + 1) if dp[k][i]]
    print(len(ans))
    print(*ans)


if __name__ == "__main__":
    main()
0