結果

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

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 76 ms
71,296 KB
testcase_01 AC 77 ms
71,248 KB
testcase_02 AC 76 ms
71,312 KB
testcase_03 AC 170 ms
80,836 KB
testcase_04 AC 149 ms
79,484 KB
testcase_05 AC 162 ms
80,360 KB
testcase_06 AC 1,061 ms
138,160 KB
testcase_07 AC 1,130 ms
138,904 KB
testcase_08 AC 1,001 ms
137,836 KB
testcase_09 AC 1,061 ms
143,228 KB
testcase_10 AC 1,023 ms
143,100 KB
testcase_11 AC 1,086 ms
143,988 KB
testcase_12 AC 1,059 ms
143,620 KB
testcase_13 AC 1,009 ms
143,060 KB
testcase_14 AC 1,064 ms
142,668 KB
testcase_15 AC 1,107 ms
143,236 KB
testcase_16 AC 1,050 ms
143,828 KB
testcase_17 AC 1,107 ms
142,404 KB
testcase_18 AC 143 ms
80,092 KB
testcase_19 AC 136 ms
79,624 KB
testcase_20 AC 147 ms
80,016 KB
testcase_21 AC 144 ms
79,940 KB
testcase_22 AC 145 ms
79,896 KB
testcase_23 AC 149 ms
79,668 KB
testcase_24 AC 150 ms
79,816 KB
testcase_25 AC 149 ms
79,528 KB
testcase_26 AC 155 ms
79,980 KB
testcase_27 AC 73 ms
71,344 KB
testcase_28 AC 74 ms
71,348 KB
testcase_29 AC 74 ms
71,376 KB
testcase_30 AC 74 ms
71,348 KB
testcase_31 AC 73 ms
71,384 KB
testcase_32 AC 75 ms
71,284 KB
testcase_33 AC 75 ms
71,244 KB
testcase_34 AC 74 ms
71,312 KB
testcase_35 AC 75 ms
71,292 KB
testcase_36 AC 76 ms
71,388 KB
testcase_37 AC 74 ms
71,284 KB
testcase_38 AC 74 ms
71,384 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
n2 = 2*n
def to(d,u,x):
    return n2*d + u*2 + x
def frm(val):
    d,v = divmod(val, n2)
    u,x = divmod(v, 2)
    return d,u,x
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