結果
| 問題 | No.92 逃走経路 |
| コンテスト | |
| ユーザー |
lam6er
|
| 提出日時 | 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 defaultdict
def main():
import sys
input = sys.stdin.read().split()
idx = 0
N = int(input[idx]); idx += 1
M = int(input[idx]); idx += 1
K = int(input[idx]); idx += 1
roads_dict = defaultdict(list)
for _ in range(M):
a = int(input[idx]); idx += 1
b = int(input[idx]); idx += 1
c = int(input[idx]); idx += 1
roads_dict[c].append( (a, b) )
d = list(map(int, input[idx:idx+K]))
idx += K
possible_prev = set(range(1, N+1)) # initially all towns are possible
for cost in d:
possible_curr = set()
# Iterate through all roads with current cost
for 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_curr
result = sorted(possible_prev)
print(len(result))
print(' '.join(map(str, result)))
if __name__ == '__main__':
main()
lam6er