結果

問題 No.1601 With Animals into Institute
ユーザー mkawa2
提出日時 2023-05-19 15:23:45
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 1,119 ms / 3,000 ms
コード長 1,555 bytes
コンパイル時間 427 ms
コンパイル使用メモリ 82,132 KB
実行使用メモリ 118,688 KB
最終ジャッジ日時 2024-12-17 22:28:08
合計ジャッジ時間 19,991 ms
ジャッジサーバーID
(参考情報)
judge2 / judge1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 36
権限があれば一括ダウンロードができます

ソースコード

diff #

import sys

# sys.setrecursionlimit(200005)
# sys.set_int_max_str_digits(200005)
int1 = lambda x: int(x)-1
pDB = lambda *x: print(*x, end="\n", file=sys.stderr)
p2D = lambda x: print(*x, sep="\n", end="\n\n", file=sys.stderr)
def II(): return int(sys.stdin.readline())
def LI(): return list(map(int, sys.stdin.readline().split()))
def LLI(rows_number): return [LI() for _ in range(rows_number)]
def LI1(): return list(map(int1, sys.stdin.readline().split()))
def LLI1(rows_number): return [LI1() for _ in range(rows_number)]
def SI(): return sys.stdin.readline().rstrip()

dij = [(0, 1), (-1, 0), (0, -1), (1, 0)]
# dij = [(0, 1), (-1, 0), (0, -1), (1, 0), (1, 1), (1, -1), (-1, 1), (-1, -1)]
inf = (1 << 63)-1
# md = 10**9+7
md = 998244353

from heapq import *

n,m=LI()
s=n
to=[[] for _ in range(n)]
for _ in range(m):
    u,v,c,x=LI()
    u,v=u-1,v-1
    if x:
        to+=[[],[]]
        to[u].append((s,c))
        to[s].append((v,0))
        to[v].append((s+1,c))
        to[s+1].append((u,0))
        s+=2
    else:
        to[u].append((v,c))
        to[v].append((u,c))

d1=[inf]*s
d1[n-1]=0
hp=[(0,n-1)]
while hp:
    d,u=heappop(hp)
    if d>d1[u]:continue
    for v,c in to[u]:
        nd=d+c
        if nd>=d1[v]:continue
        d1[v]=nd
        heappush(hp,(nd,v))

d2=[inf]*s
hp=[]
for u in range(n,s):
    d2[u]=d1[u]
    heappush(hp,(d2[u],u))
while hp:
    d,u=heappop(hp)
    if d>d2[u]:continue
    for v,c in to[u]:
        nd=d+c
        if nd>=d2[v]:continue
        d2[v]=nd
        heappush(hp,(nd,v))

print(*d2[:n-1],sep="\n")
0