結果
| 問題 | 
                            No.1601 With Animals into Institute
                             | 
                    
| コンテスト | |
| ユーザー | 
                             | 
                    
| 提出日時 | 2022-02-12 23:31:45 | 
| 言語 | PyPy3  (7.3.15)  | 
                    
| 結果 | 
                             
                                AC
                                 
                             
                            
                         | 
                    
| 実行時間 | 1,201 ms / 3,000 ms | 
| コード長 | 726 bytes | 
| コンパイル時間 | 126 ms | 
| コンパイル使用メモリ | 82,156 KB | 
| 実行使用メモリ | 145,272 KB | 
| 最終ジャッジ日時 | 2024-06-29 02:40:32 | 
| 合計ジャッジ時間 | 17,392 ms | 
| 
                            ジャッジサーバーID (参考情報)  | 
                        judge5 / judge4 | 
(要ログイン)
| ファイルパターン | 結果 | 
|---|---|
| sample | AC * 3 | 
| other | AC * 36 | 
ソースコード
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)]
def f(d, pos, x_):
    return (d * n + pos) * 2 + x_
hq = [f(0, n - 1, 0)]
while hq:
    tmp = heappop(hq)
    x_ = tmp % 2
    tmp //= 2
    d = tmp // n
    pos = tmp - d * n
    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, f(nd, npos, nx))
for i in range(n - 1):
    print(dist[i][1])