結果

問題 No.1601 With Animals into Institute
ユーザー shotoyooshotoyoo
提出日時 2021-06-13 22:56:40
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 1,400 ms / 3,000 ms
コード長 1,248 bytes
コンパイル時間 358 ms
コンパイル使用メモリ 87,124 KB
実行使用メモリ 146,312 KB
最終ジャッジ日時 2023-09-14 19:03:57
合計ジャッジ時間 21,400 ms
ジャッジサーバーID
(参考情報)
judge13 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 75 ms
71,392 KB
testcase_01 AC 75 ms
71,412 KB
testcase_02 AC 73 ms
71,644 KB
testcase_03 AC 181 ms
80,908 KB
testcase_04 AC 162 ms
79,648 KB
testcase_05 AC 183 ms
80,116 KB
testcase_06 AC 1,240 ms
139,872 KB
testcase_07 AC 1,217 ms
140,100 KB
testcase_08 AC 1,400 ms
142,988 KB
testcase_09 AC 1,255 ms
144,940 KB
testcase_10 AC 1,319 ms
145,752 KB
testcase_11 AC 1,264 ms
146,312 KB
testcase_12 AC 1,271 ms
144,652 KB
testcase_13 AC 1,366 ms
146,092 KB
testcase_14 AC 1,276 ms
144,480 KB
testcase_15 AC 1,297 ms
145,480 KB
testcase_16 AC 1,236 ms
144,960 KB
testcase_17 AC 1,287 ms
143,416 KB
testcase_18 AC 166 ms
80,276 KB
testcase_19 AC 170 ms
79,988 KB
testcase_20 AC 169 ms
79,908 KB
testcase_21 AC 170 ms
79,868 KB
testcase_22 AC 167 ms
80,216 KB
testcase_23 AC 175 ms
80,056 KB
testcase_24 AC 175 ms
80,564 KB
testcase_25 AC 175 ms
80,084 KB
testcase_26 AC 167 ms
79,760 KB
testcase_27 AC 76 ms
71,144 KB
testcase_28 AC 75 ms
71,300 KB
testcase_29 AC 75 ms
71,232 KB
testcase_30 AC 75 ms
71,232 KB
testcase_31 AC 78 ms
71,136 KB
testcase_32 AC 75 ms
71,240 KB
testcase_33 AC 76 ms
71,140 KB
testcase_34 AC 75 ms
71,248 KB
testcase_35 AC 75 ms
71,220 KB
testcase_36 AC 76 ms
71,232 KB
testcase_37 AC 76 ms
71,376 KB
testcase_38 AC 76 ms
71,280 KB
権限があれば一括ダウンロードができます

ソースコード

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