結果
問題 | No.1601 With Animals into Institute |
ユーザー |
![]() |
提出日時 | 2021-07-10 14:08:49 |
言語 | PyPy3 (7.3.15) |
結果 |
AC
|
実行時間 | 1,134 ms / 3,000 ms |
コード長 | 1,334 bytes |
コンパイル時間 | 161 ms |
コンパイル使用メモリ | 82,412 KB |
実行使用メモリ | 135,008 KB |
最終ジャッジ日時 | 2024-07-02 02:15:44 |
合計ジャッジ時間 | 17,287 ms |
ジャッジサーバーID (参考情報) |
judge5 / judge2 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 36 |
ソースコード
mod = 1000000007 eps = 10**-9 def main(): import sys input = sys.stdin.buffer.readline import heapq def dijkstra(adj, start): # adj: [[to, cost] * vertices], 0th index must be empty inf = 1 << 60 dist = [inf] * len(adj) dist[start] = 0 q = [] heapq.heappush(q, (0, start)) while q: min_dist, v_from = heapq.heappop(q) if min_dist > dist[v_from]: continue v_tos = adj[v_from] for v_to, cost in v_tos: if min_dist + cost < dist[v_to]: dist[v_to] = min_dist + cost heapq.heappush(q, (dist[v_to], v_to)) return dist N, M = map(int, input().split()) adj = [[] for _ in range(N*2+1)] for _ in range(M): a, b, c, x = map(int, input().split()) if x: adj[a].append((b+N, c)) adj[b].append((a+N, c)) adj[a+N].append((b+N, c)) adj[b+N].append((a+N, c)) else: adj[a].append((b, c)) adj[b].append((a, c)) adj[a+N].append((b+N, c)) adj[b+N].append((a+N, c)) dist = dijkstra(adj, N) for i in range(N-1): print(dist[i+N+1]) #print(dist) #print(adj) if __name__ == '__main__': main()