結果

問題 No.1601 With Animals into Institute
ユーザー __matyaki____matyaki__
提出日時 2022-03-21 12:04:12
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 2,742 ms / 3,000 ms
コード長 870 bytes
コンパイル時間 173 ms
コンパイル使用メモリ 82,432 KB
実行使用メモリ 175,752 KB
最終ジャッジ日時 2024-04-17 05:14:19
合計ジャッジ時間 36,232 ms
ジャッジサーバーID
(参考情報)
judge1 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 44 ms
52,736 KB
testcase_01 AC 40 ms
53,120 KB
testcase_02 AC 39 ms
52,864 KB
testcase_03 AC 161 ms
78,800 KB
testcase_04 AC 148 ms
78,628 KB
testcase_05 AC 150 ms
78,916 KB
testcase_06 AC 2,366 ms
166,696 KB
testcase_07 AC 2,474 ms
168,124 KB
testcase_08 AC 2,529 ms
167,504 KB
testcase_09 AC 2,622 ms
174,496 KB
testcase_10 AC 2,664 ms
175,412 KB
testcase_11 AC 2,622 ms
175,008 KB
testcase_12 AC 2,697 ms
174,744 KB
testcase_13 AC 2,629 ms
175,752 KB
testcase_14 AC 2,694 ms
173,644 KB
testcase_15 AC 2,587 ms
175,260 KB
testcase_16 AC 2,742 ms
175,384 KB
testcase_17 AC 2,679 ms
174,404 KB
testcase_18 AC 141 ms
79,232 KB
testcase_19 AC 159 ms
78,928 KB
testcase_20 AC 167 ms
79,092 KB
testcase_21 AC 148 ms
79,196 KB
testcase_22 AC 168 ms
79,136 KB
testcase_23 AC 158 ms
79,360 KB
testcase_24 AC 165 ms
79,728 KB
testcase_25 AC 147 ms
79,232 KB
testcase_26 AC 166 ms
79,208 KB
testcase_27 AC 40 ms
52,616 KB
testcase_28 AC 40 ms
53,120 KB
testcase_29 AC 42 ms
52,864 KB
testcase_30 AC 41 ms
52,608 KB
testcase_31 AC 40 ms
52,992 KB
testcase_32 AC 41 ms
52,736 KB
testcase_33 AC 41 ms
52,864 KB
testcase_34 AC 42 ms
53,248 KB
testcase_35 AC 41 ms
52,864 KB
testcase_36 AC 44 ms
52,864 KB
testcase_37 AC 41 ms
52,736 KB
testcase_38 AC 40 ms
52,736 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import heapq
import sys
input=sys.stdin.readline
n,m=map(int,input().split())

G=[[] for i in range(n)]

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

d=[[float('inf') for i in range(n)] for j in range(2)]
#d=[float('inf') for i in range(n)]
#d_passed=[float('inf') for i in range(n)]
q=[]
heapq.heappush(q,[0,n-1,0])

while q:
  #print(q)
  d_now,now,ani=heapq.heappop(q)
  #print(d_now,now,ani)
  if ani==0:
    if d_now>d[0][now] or d_now>d[1][now]:continue
    d[0][now]=d_now
  else:
    if d_now>d[1][now]:continue
    d[1][now]=d_now
  for nxt,c,x in G[now]:
    if ani==0 and x==0:
      if d[0][nxt]>d_now+c:
        d[0][nxt]=d_now+c
        heapq.heappush(q,[d_now+c,nxt,0])
    else:
      if d[1][nxt]>d_now+c:
        heapq.heappush(q,[d_now+c,nxt,1])

for i in range(n-1):
  print(d[1][i])


0