結果

問題 No.1601 With Animals into Institute
ユーザー shotoyoo
提出日時 2021-06-13 22:56:40
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 1,414 ms / 3,000 ms
コード長 1,248 bytes
コンパイル時間 222 ms
コンパイル使用メモリ 82,556 KB
実行使用メモリ 144,136 KB
最終ジャッジ日時 2024-07-02 02:04:29
合計ジャッジ時間 20,829 ms
ジャッジサーバーID
(参考情報)
judge4 / judge3
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 36
権限があれば一括ダウンロードができます

ソースコード

diff #

import sys
input = lambda : sys.stdin.readline().rstrip()


sys.setrecursionlimit(2*10**5+10)
write = lambda x: sys.stdout.write(x+"\n")
debug = lambda x: sys.stderr.write(x+"\n")
writef = lambda x: print("{:.12f}".format(x))


n,m = list(map(int, input().split()))
ns = [[] for _ in range(n)]
s = 0
for i in range(m):
    a,b,c,x = map(int, input().split())
    a -= 1
    b -= 1
    ns[a].append((c,b,x))
    ns[b].append((c,a,x))
    s += c
from heapq import heappop as hpp, heappush as hp
def t2i(*vs):
    n = len(vs)
    val = 1
    nvs = [1]
    for v in vs[::-1]:
        val *= v
        nvs.append(val)
    vs = tuple(nvs[::-1])
    def to(*args):
        return sum((v1*v2 for v1,v2 in zip(vs, args)))
    def frm(val):
        res = []
        for v in vs:
            tmp, val = divmod(val, v)
            res.append(tmp)
        return res
    return to,frm
to,frm = t2i(n,2)
inf = 2*s + 10
vals = [[inf]*n for _ in range(2)]
vals[0][n-1] = 0
q = [to(0, n-1, 0)]
while q:
    d,u,x = frm(hpp(q))
    if vals[x][u]<d:
        continue
    for c,v,xx in ns[u]:
        nx = x|xx
        nd = d+c
        if vals[nx][v]>nd:
            vals[nx][v] = nd
            hp(q, to(nd, v, nx))
ans = vals[1]
write("\n".join(map(str, ans[:n-1])))
0