結果

問題 No.1601 With Animals into Institute
ユーザー shotoyooshotoyoo
提出日時 2021-06-13 23:33:50
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 1,111 ms / 3,000 ms
コード長 1,845 bytes
コンパイル時間 280 ms
コンパイル使用メモリ 87,092 KB
実行使用メモリ 143,852 KB
最終ジャッジ日時 2023-09-14 19:04:16
合計ジャッジ時間 18,682 ms
ジャッジサーバーID
(参考情報)
judge13 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 76 ms
71,248 KB
testcase_01 AC 76 ms
71,300 KB
testcase_02 AC 76 ms
71,292 KB
testcase_03 AC 166 ms
80,492 KB
testcase_04 AC 148 ms
79,460 KB
testcase_05 AC 162 ms
80,052 KB
testcase_06 AC 1,070 ms
137,776 KB
testcase_07 AC 1,111 ms
139,004 KB
testcase_08 AC 985 ms
137,772 KB
testcase_09 AC 1,070 ms
143,396 KB
testcase_10 AC 1,039 ms
143,212 KB
testcase_11 AC 1,093 ms
143,716 KB
testcase_12 AC 1,071 ms
143,852 KB
testcase_13 AC 1,025 ms
142,840 KB
testcase_14 AC 1,051 ms
143,268 KB
testcase_15 AC 1,087 ms
143,028 KB
testcase_16 AC 1,047 ms
143,736 KB
testcase_17 AC 1,107 ms
142,616 KB
testcase_18 AC 154 ms
79,828 KB
testcase_19 AC 138 ms
79,460 KB
testcase_20 AC 151 ms
79,948 KB
testcase_21 AC 145 ms
79,640 KB
testcase_22 AC 145 ms
79,864 KB
testcase_23 AC 151 ms
79,780 KB
testcase_24 AC 152 ms
80,004 KB
testcase_25 AC 153 ms
79,896 KB
testcase_26 AC 155 ms
80,160 KB
testcase_27 AC 76 ms
71,248 KB
testcase_28 AC 75 ms
71,184 KB
testcase_29 AC 76 ms
71,448 KB
testcase_30 AC 75 ms
71,348 KB
testcase_31 AC 82 ms
71,316 KB
testcase_32 AC 77 ms
71,244 KB
testcase_33 AC 82 ms
71,360 KB
testcase_34 AC 76 ms
71,312 KB
testcase_35 AC 76 ms
71,248 KB
testcase_36 AC 75 ms
71,300 KB
testcase_37 AC 78 ms
71,364 KB
testcase_38 AC 76 ms
71,320 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
def t2i(*vs):
    n = len(vs)+1
    nvs = [1]
    val = 1
    for v in vs[::-1]:
        val *= v
        nvs.append(val)
    vs = nvs[::-1]
    tos = "def to(%s):\n" % (",".join([f"v{i}" for i in range(n)]))
    tos += "    val = 0\n"
    for i,v in enumerate(vs):
        tos += f"    val += {v} * v{i}\n"
    tos += "    return val"
    frms = f"def frm(val):\n"
    for i in range(n-1):
        frms += f"    v{i},val = divmod(val, {vs[i]})\n"
    frms += "    return %s" % ((", ".join([f"v{i}" for i in range(n-1)]) + ", val"))
    return tos, frms
tos, frms = t2i(n,2)
exec(tos)
exec(frms)
# 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