結果

問題 No.1601 With Animals into Institute
ユーザー qibqib
提出日時 2022-12-03 17:45:00
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 1,232 ms / 3,000 ms
コード長 738 bytes
コンパイル時間 216 ms
コンパイル使用メモリ 82,176 KB
実行使用メモリ 141,372 KB
最終ジャッジ日時 2024-04-19 03:48:49
合計ジャッジ時間 19,632 ms
ジャッジサーバーID
(参考情報)
judge2 / judge3
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 47 ms
53,248 KB
testcase_01 AC 39 ms
52,992 KB
testcase_02 AC 40 ms
52,736 KB
testcase_03 AC 141 ms
78,684 KB
testcase_04 AC 133 ms
78,624 KB
testcase_05 AC 127 ms
78,208 KB
testcase_06 AC 1,092 ms
140,632 KB
testcase_07 AC 1,203 ms
141,372 KB
testcase_08 AC 1,120 ms
140,912 KB
testcase_09 AC 1,134 ms
139,600 KB
testcase_10 AC 1,109 ms
139,324 KB
testcase_11 AC 1,146 ms
139,988 KB
testcase_12 AC 1,232 ms
140,800 KB
testcase_13 AC 1,127 ms
139,572 KB
testcase_14 AC 1,190 ms
140,032 KB
testcase_15 AC 1,168 ms
140,132 KB
testcase_16 AC 1,180 ms
140,112 KB
testcase_17 AC 1,192 ms
139,760 KB
testcase_18 AC 128 ms
78,616 KB
testcase_19 AC 120 ms
78,232 KB
testcase_20 AC 128 ms
78,208 KB
testcase_21 AC 126 ms
78,336 KB
testcase_22 AC 129 ms
78,592 KB
testcase_23 AC 126 ms
78,464 KB
testcase_24 AC 123 ms
78,592 KB
testcase_25 AC 129 ms
78,500 KB
testcase_26 AC 133 ms
78,224 KB
testcase_27 AC 39 ms
53,120 KB
testcase_28 AC 40 ms
52,864 KB
testcase_29 AC 39 ms
52,864 KB
testcase_30 AC 40 ms
53,120 KB
testcase_31 AC 40 ms
53,120 KB
testcase_32 AC 40 ms
52,992 KB
testcase_33 AC 40 ms
52,736 KB
testcase_34 AC 39 ms
53,248 KB
testcase_35 AC 39 ms
52,992 KB
testcase_36 AC 39 ms
52,608 KB
testcase_37 AC 41 ms
52,864 KB
testcase_38 AC 41 ms
52,864 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import heapq

INF = 1 << 60

n, m = map(int, input().split())
g = [[] for _ in range(2 * n)]
for _ in range(m):
  a, b, c, x = map(int, input().split())
  a -= 1
  b -= 1
  if x == 0:
    g[a].append((b, c))
    g[b].append((a, c))
    g[a + n].append((b + n, c))
    g[b + n].append((a + n, c))
  else:
    g[a + n].append((b, c))
    g[b + n].append((a, c))
    g[a].append((b, c))
    g[b].append((a, c))

src = 2 * n - 1
dist = [INF for _ in range(2 * n)]
dist[src] = 0
hp = [(0, src)]
while len(hp) > 0:
  cd, cur = heapq.heappop(hp)
  if cd > dist[cur]:
    continue

  for nxt, c in g[cur]:
    if dist[cur] + c < dist[nxt]:
      dist[nxt] = dist[cur] + c
      heapq.heappush(hp, (dist[nxt], nxt))

print(*dist[:n - 1], sep='\n')
0