結果

問題 No.1473 おでぶなおばけさん
ユーザー buey_tbuey_t
提出日時 2023-03-26 10:51:49
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 729 ms / 2,000 ms
コード長 2,317 bytes
コンパイル時間 705 ms
コンパイル使用メモリ 81,452 KB
実行使用メモリ 117,988 KB
最終ジャッジ日時 2023-10-19 13:29:20
合計ジャッジ時間 22,127 ms
ジャッジサーバーID
(参考情報)
judge14 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 129 ms
84,112 KB
testcase_01 AC 122 ms
84,108 KB
testcase_02 AC 638 ms
114,416 KB
testcase_03 AC 420 ms
110,868 KB
testcase_04 AC 344 ms
102,380 KB
testcase_05 AC 255 ms
92,972 KB
testcase_06 AC 539 ms
110,932 KB
testcase_07 AC 500 ms
114,184 KB
testcase_08 AC 716 ms
114,204 KB
testcase_09 AC 543 ms
114,988 KB
testcase_10 AC 309 ms
99,616 KB
testcase_11 AC 341 ms
100,192 KB
testcase_12 AC 300 ms
99,616 KB
testcase_13 AC 251 ms
96,184 KB
testcase_14 AC 215 ms
93,400 KB
testcase_15 AC 299 ms
100,076 KB
testcase_16 AC 276 ms
98,296 KB
testcase_17 AC 179 ms
89,484 KB
testcase_18 AC 187 ms
90,028 KB
testcase_19 AC 355 ms
99,956 KB
testcase_20 AC 420 ms
107,708 KB
testcase_21 AC 601 ms
105,832 KB
testcase_22 AC 729 ms
114,204 KB
testcase_23 AC 643 ms
109,020 KB
testcase_24 AC 686 ms
110,104 KB
testcase_25 AC 658 ms
111,744 KB
testcase_26 AC 405 ms
111,960 KB
testcase_27 AC 327 ms
97,636 KB
testcase_28 AC 425 ms
117,988 KB
testcase_29 AC 381 ms
106,620 KB
testcase_30 AC 432 ms
110,412 KB
testcase_31 AC 507 ms
114,588 KB
testcase_32 AC 506 ms
112,004 KB
testcase_33 AC 362 ms
109,296 KB
testcase_34 AC 261 ms
100,416 KB
testcase_35 AC 312 ms
99,888 KB
testcase_36 AC 613 ms
110,156 KB
testcase_37 AC 354 ms
109,700 KB
testcase_38 AC 195 ms
90,620 KB
testcase_39 AC 272 ms
98,488 KB
testcase_40 AC 275 ms
98,508 KB
testcase_41 AC 291 ms
102,844 KB
testcase_42 AC 264 ms
103,188 KB
testcase_43 AC 343 ms
109,244 KB
testcase_44 AC 347 ms
109,244 KB
testcase_45 AC 347 ms
109,240 KB
testcase_46 AC 339 ms
109,148 KB
testcase_47 AC 376 ms
114,416 KB
testcase_48 AC 384 ms
108,356 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

def main():
    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
    #再帰ならPython!!!!!!!!!!!!!!!!!!!!!!!!!!
    
    
    '''
    
    
    
    '''
    
    N,M = map(int, input().split())
    G = [[] for _ in range(N+1)]
    w = []
    for _ in range(M):
        a,b,c = map(int, input().split())
        G[a].append((b,c))
        G[b].append((a,c))
        w.append(c)
    
    w.sort()
    
    r = M
    l = 0
    
    while r-l > 1:
        m = (r+l)//2
        
        Q = deque()
        Q.append((1,0))
        seen = [0]*(N+1)
        ans = -1
        while len(Q) > 0:
            pos,cnt = Q.popleft()
            
            if seen[pos] == 1:
                continue
            
            seen[pos] = 1
            
            if pos == N:
                ans = cnt
                break
            
            for nx,d in G[pos]:
                if d >= w[m] and seen[nx] == 0:
                    Q.append((nx,cnt+1))
        
        if ans == -1:
            r = m
        else:
            l = m
    
    Q = deque()
    Q.append((1,0))
    seen = [0]*(N+1)
    ans = -1
    while len(Q) > 0:
        pos,cnt = Q.popleft()
        
        if seen[pos] == 1:
            continue
        
        seen[pos] = 1
        
        if pos == N:
            ans = cnt
            break
        
        for nx,d in G[pos]:
            if d >= w[l] and seen[nx] == 0:
                Q.append((nx,cnt+1))
    
    print(w[l],ans)
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
if __name__ == '__main__':
    main()
0