結果

問題 No.2569 はじめてのおつかいHard
ユーザー Navier_BoltzmannNavier_Boltzmann
提出日時 2024-04-11 21:43:18
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 1,070 ms / 2,000 ms
コード長 1,333 bytes
コンパイル時間 502 ms
コンパイル使用メモリ 82,412 KB
実行使用メモリ 183,644 KB
最終ジャッジ日時 2024-04-11 21:43:29
合計ジャッジ時間 10,036 ms
ジャッジサーバーID
(参考情報)
judge2 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 345 ms
119,512 KB
testcase_01 AC 287 ms
118,932 KB
testcase_02 AC 280 ms
119,604 KB
testcase_03 AC 272 ms
119,464 KB
testcase_04 AC 278 ms
119,320 KB
testcase_05 AC 934 ms
181,920 KB
testcase_06 AC 1,070 ms
140,236 KB
testcase_07 AC 632 ms
182,184 KB
testcase_08 AC 861 ms
183,644 KB
testcase_09 AC 582 ms
136,376 KB
testcase_10 AC 44 ms
56,364 KB
testcase_11 AC 44 ms
55,748 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

# import pypyjit
# pypyjit.set_param("max_unroll_recursion=-1")
from collections import *
from functools import *
from itertools import *
from heapq import *
import sys, math
# sys.setrecursionlimit(3*10**5)
input = sys.stdin.readline
INF = (1<<60)
def dijkstra(s,e):
    
    N = len(e)
    dist = [INF]*N
    dist[s]=0
    h = []
    heappush(h,s)
    while h:
        nw,v = divmod(heappop(h),N)
        if dist[v]!=nw:
            continue
        for iv,ic in e[v]:
            nc = ic + nw
            if nc < dist[iv]:
                dist[iv] = nc
                heappush(h,nc*N + iv)
    return dist

N,M = map(int,input().split())
e = [[] for _ in range(N)]
re = [[] for _ in range(4*N)]
for _ in range(M):
    u,v,t = map(int,input().split())
    u -= 1
    v -= 1
    e[u].append((v,t))
    re[v].append((u,t))
    re[v+N].append((u+N,t))
    re[v+2*N].append((u+2*N,t))
    re[v+3*N].append((u+3*N,t))
    if v==N-1:
        re[v+N].append((u,t))
        re[v+3*N].append((u+2*N,t))
    if v==N-2:
        re[v+2*N].append((u,t))
        re[v+3*N].append((u+N,t))

A = dijkstra(N-1+3*N,re)
B = dijkstra(N-2+3*N,re)
C = dijkstra(N-1,e)
D = dijkstra(N-2,e)
# print(A)
# print(B)
# print(C)
# print(D)
for i in range(N-2):
    val = min(A[i]+C[i],B[i]+D[i])
    if val>=INF:
        print(-1)
    else:
        print(val)
0