結果

問題 No.1601 With Animals into Institute
ユーザー __matyaki____matyaki__
提出日時 2022-03-21 13:45:13
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 1,383 ms / 3,000 ms
コード長 933 bytes
コンパイル時間 170 ms
コンパイル使用メモリ 82,116 KB
実行使用メモリ 152,588 KB
最終ジャッジ日時 2024-04-17 06:50:09
合計ジャッジ時間 20,953 ms
ジャッジサーバーID
(参考情報)
judge3 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 43 ms
53,504 KB
testcase_01 AC 38 ms
53,624 KB
testcase_02 AC 39 ms
53,936 KB
testcase_03 AC 140 ms
77,900 KB
testcase_04 AC 136 ms
78,024 KB
testcase_05 AC 143 ms
78,304 KB
testcase_06 AC 1,301 ms
148,928 KB
testcase_07 AC 1,333 ms
150,708 KB
testcase_08 AC 1,317 ms
149,632 KB
testcase_09 AC 1,339 ms
150,904 KB
testcase_10 AC 1,324 ms
152,500 KB
testcase_11 AC 1,359 ms
150,212 KB
testcase_12 AC 1,322 ms
150,664 KB
testcase_13 AC 1,307 ms
152,588 KB
testcase_14 AC 1,383 ms
148,916 KB
testcase_15 AC 1,364 ms
151,528 KB
testcase_16 AC 1,312 ms
150,752 KB
testcase_17 AC 1,366 ms
149,128 KB
testcase_18 AC 129 ms
78,544 KB
testcase_19 AC 148 ms
78,392 KB
testcase_20 AC 135 ms
78,236 KB
testcase_21 AC 130 ms
78,948 KB
testcase_22 AC 147 ms
77,764 KB
testcase_23 AC 167 ms
78,456 KB
testcase_24 AC 134 ms
78,168 KB
testcase_25 AC 135 ms
78,704 KB
testcase_26 AC 133 ms
78,500 KB
testcase_27 AC 37 ms
53,016 KB
testcase_28 AC 38 ms
53,188 KB
testcase_29 AC 38 ms
53,876 KB
testcase_30 AC 39 ms
53,168 KB
testcase_31 AC 39 ms
54,236 KB
testcase_32 AC 39 ms
53,004 KB
testcase_33 AC 39 ms
54,252 KB
testcase_34 AC 40 ms
53,816 KB
testcase_35 AC 39 ms
54,748 KB
testcase_36 AC 39 ms
53,780 KB
testcase_37 AC 40 ms
54,656 KB
testcase_38 AC 39 ms
53,776 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)]
d_passed=[float('inf') for i in range(n)]



def f(d_now,now,ani):
  return (d_now*n+now)*2+ani
def invf(pop):
  ani=pop%2
  pop//=2
  now=pop%n
  d_now=pop//n
  return d_now,now,ani

q=[]
heapq.heappush(q,f(0,n-1,0))

while q:
  #print(q)
  pop=heapq.heappop(q)
  d_now,now,ani=invf(pop)
  #print(d_now,now,ani)
  if ani:
    if d_now>=d_passed[now]:continue
    d_passed[now]=d_now
    for nxt,c,x in G[now]:heapq.heappush(q,f(d_now+c,nxt,1))
  else:
    if d_now>=d[now] or d_now>=d_passed[now]:continue
    d[now]=d_now
    for nxt,c,x in G[now]:
      if x:heapq.heappush(q,f(d_now+c,nxt,1))
      else:heapq.heappush(q,f(d_now+c,nxt,0))
for i in range(n-1):
  print(d_passed[i])
0