結果
問題 | No.92 逃走経路 |
ユーザー |
![]() |
提出日時 | 2025-03-20 21:03:17 |
言語 | PyPy3 (7.3.15) |
結果 |
AC
|
実行時間 | 86 ms / 5,000 ms |
コード長 | 1,045 bytes |
コンパイル時間 | 164 ms |
コンパイル使用メモリ | 82,516 KB |
実行使用メモリ | 72,612 KB |
最終ジャッジ日時 | 2025-03-20 21:03:28 |
合計ジャッジ時間 | 2,105 ms |
ジャッジサーバーID (参考情報) |
judge1 / judge4 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 2 |
other | AC * 18 |
ソースコード
from collections import defaultdictdef main():import sysinput = sys.stdin.read().split()idx = 0N = int(input[idx]); idx += 1M = int(input[idx]); idx += 1K = int(input[idx]); idx += 1roads_dict = defaultdict(list)for _ in range(M):a = int(input[idx]); idx += 1b = int(input[idx]); idx += 1c = int(input[idx]); idx += 1roads_dict[c].append( (a, b) )d = list(map(int, input[idx:idx+K]))idx += Kpossible_prev = set(range(1, N+1)) # initially all towns are possiblefor cost in d:possible_curr = set()# Iterate through all roads with current costfor a, b in roads_dict.get(cost, []):if a in possible_prev:possible_curr.add(b)if b in possible_prev:possible_curr.add(a)possible_prev = possible_currresult = sorted(possible_prev)print(len(result))print(' '.join(map(str, result)))if __name__ == '__main__':main()