結果

問題 No.1601 With Animals into Institute
ユーザー 👑 rin204rin204
提出日時 2022-02-12 23:31:45
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 1,392 ms / 3,000 ms
コード長 726 bytes
コンパイル時間 319 ms
コンパイル使用メモリ 86,564 KB
実行使用メモリ 147,952 KB
最終ジャッジ日時 2023-09-11 12:10:35
合計ジャッジ時間 22,317 ms
ジャッジサーバーID
(参考情報)
judge13 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 76 ms
70,924 KB
testcase_01 AC 75 ms
71,188 KB
testcase_02 AC 75 ms
70,812 KB
testcase_03 AC 193 ms
79,744 KB
testcase_04 AC 183 ms
79,536 KB
testcase_05 AC 178 ms
78,976 KB
testcase_06 AC 1,368 ms
141,736 KB
testcase_07 AC 1,379 ms
141,720 KB
testcase_08 AC 1,293 ms
140,996 KB
testcase_09 AC 1,337 ms
146,820 KB
testcase_10 AC 1,390 ms
147,952 KB
testcase_11 AC 1,234 ms
145,140 KB
testcase_12 AC 1,358 ms
146,232 KB
testcase_13 AC 1,392 ms
146,072 KB
testcase_14 AC 1,386 ms
146,616 KB
testcase_15 AC 1,351 ms
147,484 KB
testcase_16 AC 1,352 ms
146,704 KB
testcase_17 AC 1,363 ms
146,604 KB
testcase_18 AC 165 ms
79,352 KB
testcase_19 AC 167 ms
79,368 KB
testcase_20 AC 166 ms
79,288 KB
testcase_21 AC 169 ms
79,376 KB
testcase_22 AC 166 ms
78,932 KB
testcase_23 AC 173 ms
79,540 KB
testcase_24 AC 174 ms
79,420 KB
testcase_25 AC 175 ms
79,452 KB
testcase_26 AC 170 ms
79,372 KB
testcase_27 AC 78 ms
71,176 KB
testcase_28 AC 79 ms
71,176 KB
testcase_29 AC 78 ms
70,980 KB
testcase_30 AC 79 ms
70,796 KB
testcase_31 AC 78 ms
71,096 KB
testcase_32 AC 78 ms
70,932 KB
testcase_33 AC 77 ms
70,860 KB
testcase_34 AC 78 ms
71,180 KB
testcase_35 AC 76 ms
70,684 KB
testcase_36 AC 77 ms
71,116 KB
testcase_37 AC 78 ms
71,184 KB
testcase_38 AC 77 ms
70,884 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

from heapq import *

n, m = map(int, input().split())
edges = [[] for _ in range(n)]
for _ in range(m):
    a, b, c, x = map(int, input().split())
    a -= 1
    b -= 1
    edges[a].append((b, c, x))
    edges[b].append((a, c, x))

inf = 1 << 60
dist = [[inf] * 2 for _ in range(n)]
def f(d, pos, x_):
    return (d * n + pos) * 2 + x_
hq = [f(0, n - 1, 0)]
while hq:
    tmp = heappop(hq)
    x_ = tmp % 2
    tmp //= 2
    d = tmp // n
    pos = tmp - d * n
    if dist[pos][x_] < d:
        continue
    for npos, c, x in edges[pos]:
        nd = d + c
        nx = x_ | x
        if dist[npos][nx] > nd:
            dist[npos][nx] = nd
            heappush(hq, f(nd, npos, nx))
for i in range(n - 1):
    print(dist[i][1])
0