結果

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

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 73 ms
71,388 KB
testcase_01 AC 74 ms
71,444 KB
testcase_02 AC 78 ms
71,552 KB
testcase_03 AC 165 ms
80,612 KB
testcase_04 AC 147 ms
79,620 KB
testcase_05 AC 162 ms
80,168 KB
testcase_06 AC 1,103 ms
138,028 KB
testcase_07 AC 1,130 ms
139,032 KB
testcase_08 AC 996 ms
137,836 KB
testcase_09 AC 1,062 ms
143,196 KB
testcase_10 AC 1,037 ms
143,200 KB
testcase_11 AC 1,083 ms
144,216 KB
testcase_12 AC 1,066 ms
143,640 KB
testcase_13 AC 1,028 ms
143,032 KB
testcase_14 AC 1,087 ms
142,632 KB
testcase_15 AC 1,109 ms
143,268 KB
testcase_16 AC 1,073 ms
143,944 KB
testcase_17 AC 1,119 ms
142,640 KB
testcase_18 AC 146 ms
80,120 KB
testcase_19 AC 138 ms
79,728 KB
testcase_20 AC 150 ms
79,832 KB
testcase_21 AC 148 ms
79,812 KB
testcase_22 AC 152 ms
79,820 KB
testcase_23 AC 150 ms
79,696 KB
testcase_24 AC 153 ms
79,756 KB
testcase_25 AC 151 ms
79,852 KB
testcase_26 AC 156 ms
80,232 KB
testcase_27 AC 76 ms
71,344 KB
testcase_28 AC 76 ms
71,288 KB
testcase_29 AC 76 ms
71,312 KB
testcase_30 AC 77 ms
71,240 KB
testcase_31 AC 77 ms
71,440 KB
testcase_32 AC 76 ms
71,068 KB
testcase_33 AC 75 ms
71,292 KB
testcase_34 AC 76 ms
71,236 KB
testcase_35 AC 76 ms
71,408 KB
testcase_36 AC 77 ms
71,240 KB
testcase_37 AC 76 ms
71,332 KB
testcase_38 AC 76 ms
71,288 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