結果

問題 No.1601 With Animals into Institute
ユーザー 👑 rin204
提出日時 2022-02-12 23:30:48
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 2,480 ms / 3,000 ms
コード長 608 bytes
コンパイル時間 231 ms
コンパイル使用メモリ 82,356 KB
実行使用メモリ 169,928 KB
最終ジャッジ日時 2024-06-29 02:40:08
合計ジャッジ時間 33,314 ms
ジャッジサーバーID
(参考情報)
judge4 / judge3
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 36
権限があれば一括ダウンロードができます

ソースコード

diff #

from heapq import *

n, m = map(int, input().split())
edges = [[] for _ in range(n)]
for _ in range(m):
    a, b, c, x = map(int, input().split())
    a -= 1
    b -= 1
    edges[a].append((b, c, x))
    edges[b].append((a, c, x))

inf = 1 << 60
dist = [[inf] * 2 for _ in range(n)]
hq = [(0, n - 1, 0)]
while hq:
    d, pos, x_ = heappop(hq)
    if dist[pos][x_] < d:
        continue
    for npos, c, x in edges[pos]:
        nd = d + c
        nx = x_ | x
        if dist[npos][nx] > nd:
            dist[npos][nx] = nd
            heappush(hq, (nd, npos, nx))
for i in range(n - 1):
    print(dist[i][1])
0