結果

問題 No.807 umg tours
ユーザー buey_tbuey_t
提出日時 2023-03-19 13:25:54
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 3,929 ms / 4,000 ms
コード長 1,994 bytes
コンパイル時間 272 ms
コンパイル使用メモリ 81,828 KB
実行使用メモリ 181,228 KB
最終ジャッジ日時 2023-10-18 17:48:37
合計ジャッジ時間 37,249 ms
ジャッジサーバーID
(参考情報)
judge12 / judge14
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 156 ms
89,168 KB
testcase_01 AC 156 ms
89,084 KB
testcase_02 AC 174 ms
89,288 KB
testcase_03 AC 170 ms
89,288 KB
testcase_04 AC 153 ms
89,104 KB
testcase_05 AC 158 ms
89,148 KB
testcase_06 AC 179 ms
89,288 KB
testcase_07 AC 169 ms
89,284 KB
testcase_08 AC 138 ms
88,436 KB
testcase_09 AC 145 ms
88,936 KB
testcase_10 AC 143 ms
88,748 KB
testcase_11 AC 2,773 ms
156,288 KB
testcase_12 AC 1,973 ms
139,112 KB
testcase_13 AC 2,874 ms
156,832 KB
testcase_14 AC 1,258 ms
119,112 KB
testcase_15 AC 914 ms
111,528 KB
testcase_16 AC 2,945 ms
159,352 KB
testcase_17 AC 3,719 ms
177,428 KB
testcase_18 AC 3,650 ms
174,924 KB
testcase_19 AC 3,405 ms
169,048 KB
testcase_20 AC 1,326 ms
128,092 KB
testcase_21 AC 1,370 ms
129,864 KB
testcase_22 AC 656 ms
106,248 KB
testcase_23 AC 529 ms
102,140 KB
testcase_24 AC 1,445 ms
161,972 KB
testcase_25 AC 3,929 ms
181,228 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

def main():
    try:
        import pypyjit
        pypyjit.set_param('max_unroll_recursion=-1')
    except:
        pass
    try:
        import sys
        sys.setrecursionlimit(10**7)
    except:
        pass
    from math import sqrt,sin,cos,tan,ceil,radians,floor,gcd,exp,log,log10,log2,factorial,fsum
    from heapq import heapify, heappop, heappush
    from bisect import bisect_left, bisect_right
    from copy import deepcopy
    import copy
    import random
    from collections import deque,Counter,defaultdict
    from itertools import permutations,combinations
    from decimal import Decimal,ROUND_HALF_UP
    #tmp = Decimal(mid).quantize(Decimal('0'), rounding=ROUND_HALF_UP)
    from functools import lru_cache, reduce
    #@lru_cache(maxsize=None)
    from operator import add,sub,mul,xor,and_,or_,itemgetter
    INF = 10**18
    mod1 = 10**9+7
    mod2 = 998244353
    
    #DecimalならPython
    
    
    '''
    
    
    
    '''
    
    N,M = map(int, input().split())
    G = [[] for _ in range(N+1)]
    for _ in range(M):
        a,b,c = map(int, input().split())
        G[a].append((b,c))
        G[b].append((a,c))
    
    Q = []
    heappush(Q,(0,1,0))
    dis = [[INF]*2 for _ in range(N+1)]
    dis[0][1] = 0
    
    while len(Q) > 0:
        cnt,pos,f = heappop(Q)
        
        if dis[pos][f] != INF:
            continue
        
        dis[pos][f] = cnt
        
        if f == 1 and dis[pos][1] >= dis[pos][0]:
            continue
        
        for nx,d in G[pos]:
            if dis[nx][f] == INF and cnt<dis[nx][0]:
                heappush(Q,(cnt+d,nx,f))
            if f == 0 and dis[nx][1] == INF and cnt<dis[nx][0]:
                heappush(Q,(cnt,nx,1))
    
    for i in range(1,N+1):
        print(dis[i][0]+min(dis[i][0],dis[i][1]))
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
if __name__ == '__main__':
    main()
0