結果

問題 No.1473 おでぶなおばけさん
ユーザー mkawa2
提出日時 2021-04-09 21:59:59
言語 Python3
(3.13.1 + numpy 2.2.1 + scipy 1.14.1)
結果
AC  
実行時間 1,126 ms / 2,000 ms
コード長 1,452 bytes
コンパイル時間 296 ms
コンパイル使用メモリ 12,800 KB
実行使用メモリ 48,512 KB
最終ジャッジ日時 2024-06-25 05:25:52
合計ジャッジ時間 29,193 ms
ジャッジサーバーID
(参考情報)
judge5 / judge2
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 2
other AC * 47
権限があれば一括ダウンロードができます

ソースコード

diff #

import sys

sys.setrecursionlimit(10**6)
int1 = lambda x: int(x)-1
p2D = lambda x: print(*x, sep="\n")
def II(): return int(sys.stdin.buffer.readline())
def FI(): return float(sys.stdin.buffer.readline())
def LI(): return list(map(int, sys.stdin.buffer.readline().split()))
def LI1(): return list(map(int1, sys.stdin.buffer.readline().split()))
def LLI(rows_number): return [LI() for _ in range(rows_number)]
def LLI1(rows_number): return [LI1() for _ in range(rows_number)]
def BI(): return sys.stdin.buffer.readline().rstrip()
def SI(): return sys.stdin.buffer.readline().rstrip().decode()
# 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)]
dij = [(0, 1), (1, 0), (1, 1), (1, -1)]
inf = 10**16
# md = 998244353
md = 10**9+7

from heapq import *

n,m=LI()
to=[[] for _ in range(n)]
for _ in range(m):
    u,v,d=LI()
    u,v=u-1,v-1
    to[u].append((v,d))
    to[v].append((u,d))

ww=[0]*n
ww[0]=inf
ee=[inf]*n
ee[0]=0

hp=[(-inf,0)]
while hp:
    w,u=heappop(hp)
    w=-w
    if w<ww[u]:continue
    if u==n-1:break
    for v,lim in to[u]:
        nw=min(lim,w)
        if ww[v]>=nw:continue
        ww[v]=nw
        heappush(hp,(-nw,v))

hp=[(0,0)]
while hp:
    e,u=heappop(hp)
    if e>ee[u]:continue
    if u==n-1:break
    for v,lim in to[u]:
        if lim<ww[-1]:continue
        if ee[v]<=e+1:continue
        ee[v]=e+1
        heappush(hp,(e+1,v))

print(ww[-1],ee[-1])
0