結果
問題 | No.1601 With Animals into Institute |
ユーザー |
![]() |
提出日時 | 2025-03-20 21:11:20 |
言語 | PyPy3 (7.3.15) |
結果 |
AC
|
実行時間 | 2,148 ms / 3,000 ms |
コード長 | 1,572 bytes |
コンパイル時間 | 385 ms |
コンパイル使用メモリ | 82,608 KB |
実行使用メモリ | 191,032 KB |
最終ジャッジ日時 | 2025-03-20 21:12:06 |
合計ジャッジ時間 | 30,329 ms |
ジャッジサーバーID (参考情報) |
judge1 / judge3 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 36 |
ソースコード
import sysimport heapqdef main():input = sys.stdin.read().split()idx = 0N = int(input[idx])idx += 1M = int(input[idx])idx += 1adj = [[] for _ in range(N+1)]for _ in range(M):A = int(input[idx])idx += 1B = int(input[idx])idx += 1C = int(input[idx])idx += 1X = int(input[idx])idx += 1adj[A].append((B, C, X))adj[B].append((A, C, X))INF = 1 << 60d0 = [INF] * (N + 1)d1 = [INF] * (N + 1)d0[N] = 0heap = []heapq.heappush(heap, (0, N, 0))while heap:dist, u, state = heapq.heappop(heap)if state == 0:if dist > d0[u]:continueelse:if dist > d1[u]:continuefor (v, c, x) in adj[u]:if state == 0:new_dist0 = d0[u] + cif x == 1:if new_dist0 < d1[v]:d1[v] = new_dist0heapq.heappush(heap, (d1[v], v, 1))else:if new_dist0 < d0[v]:d0[v] = new_dist0heapq.heappush(heap, (d0[v], v, 0))if state == 1:new_dist1 = d1[u] + cif new_dist1 < d1[v]:d1[v] = new_dist1heapq.heappush(heap, (d1[v], v, 1))for i in range(1, N):print(d1[i] if d1[i] != INF else -1)if __name__ == '__main__':main()