結果

問題 No.1473 おでぶなおばけさん
ユーザー ronpooronpoo
提出日時 2023-10-31 14:06:24
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 733 ms / 2,000 ms
コード長 1,110 bytes
コンパイル時間 472 ms
コンパイル使用メモリ 81,852 KB
実行使用メモリ 139,328 KB
最終ジャッジ日時 2023-10-31 14:06:44
合計ジャッジ時間 19,590 ms
ジャッジサーバーID
(参考情報)
judge11 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 40 ms
55,656 KB
testcase_01 AC 41 ms
55,656 KB
testcase_02 AC 662 ms
133,936 KB
testcase_03 AC 472 ms
131,204 KB
testcase_04 AC 341 ms
110,732 KB
testcase_05 AC 195 ms
86,220 KB
testcase_06 AC 716 ms
126,132 KB
testcase_07 AC 581 ms
136,116 KB
testcase_08 AC 733 ms
137,700 KB
testcase_09 AC 480 ms
137,700 KB
testcase_10 AC 224 ms
97,664 KB
testcase_11 AC 237 ms
100,412 KB
testcase_12 AC 223 ms
98,540 KB
testcase_13 AC 121 ms
88,284 KB
testcase_14 AC 109 ms
84,080 KB
testcase_15 AC 159 ms
93,952 KB
testcase_16 AC 203 ms
98,828 KB
testcase_17 AC 83 ms
77,976 KB
testcase_18 AC 92 ms
77,800 KB
testcase_19 AC 324 ms
100,592 KB
testcase_20 AC 446 ms
119,368 KB
testcase_21 AC 603 ms
109,160 KB
testcase_22 AC 612 ms
123,660 KB
testcase_23 AC 710 ms
120,300 KB
testcase_24 AC 642 ms
115,404 KB
testcase_25 AC 500 ms
119,896 KB
testcase_26 AC 315 ms
127,700 KB
testcase_27 AC 171 ms
89,788 KB
testcase_28 AC 447 ms
135,460 KB
testcase_29 AC 321 ms
115,608 KB
testcase_30 AC 390 ms
119,228 KB
testcase_31 AC 552 ms
139,328 KB
testcase_32 AC 645 ms
126,728 KB
testcase_33 AC 364 ms
122,216 KB
testcase_34 AC 188 ms
99,176 KB
testcase_35 AC 252 ms
97,128 KB
testcase_36 AC 535 ms
105,820 KB
testcase_37 AC 339 ms
117,196 KB
testcase_38 AC 107 ms
81,656 KB
testcase_39 AC 191 ms
99,164 KB
testcase_40 AC 203 ms
99,212 KB
testcase_41 AC 150 ms
96,144 KB
testcase_42 AC 144 ms
96,152 KB
testcase_43 AC 268 ms
124,380 KB
testcase_44 AC 261 ms
124,396 KB
testcase_45 AC 262 ms
124,400 KB
testcase_46 AC 244 ms
118,240 KB
testcase_47 AC 325 ms
134,796 KB
testcase_48 AC 312 ms
129,696 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import sys
from collections import deque, defaultdict
input = sys.stdin.readline

n, m = map(int, input().split())
std = [list(map(int, input().split())) for _ in range(m)]

G = [defaultdict(int) for _ in range(n)]
D = []
W = [float('inf')] * (m+2)
for i in range(m):
    s, t, d = std[i]
    s -= 1
    t -= 1
    if G[s][t] < d:
        G[s][t] = d
    if G[t][s] < d:
        G[t][s] = d
    D.append(d)

def bfs(cost):
    dist = [float('inf')] * n
    dist[0] = 0
    q = deque([0])
    while q:
        now = q.popleft()
        for nxt, d in G[now].items():            
            if dist[nxt] < dist[now] + 1:
                continue
            if d < cost:
                continue
            dist[nxt] = dist[now] + 1
            if nxt == n-1:                
                return dist[nxt]
            q.append(nxt)
    return float('inf')

D.append(0)
D.append(float('inf'))
D.sort()
ok = 0
ng = len(D)
while ng - ok > 1:
    mid = (ng + ok) // 2
    W[mid] = bfs(D[mid])
    if W[mid] != float('inf'):
        ok = mid        
    else:
        ng = mid
                
print(D[ok], W[ok])
0