結果

問題 No.1473 おでぶなおばけさん
ユーザー O2MTO2MT
提出日時 2021-06-02 00:54:11
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 867 ms / 2,000 ms
コード長 1,189 bytes
コンパイル時間 425 ms
コンパイル使用メモリ 87,112 KB
実行使用メモリ 170,916 KB
最終ジャッジ日時 2023-08-08 17:24:30
合計ジャッジ時間 20,478 ms
ジャッジサーバーID
(参考情報)
judge11 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 92 ms
71,360 KB
testcase_01 AC 92 ms
71,616 KB
testcase_02 AC 779 ms
142,704 KB
testcase_03 AC 403 ms
129,228 KB
testcase_04 AC 444 ms
115,672 KB
testcase_05 AC 239 ms
81,612 KB
testcase_06 AC 667 ms
128,324 KB
testcase_07 AC 596 ms
153,700 KB
testcase_08 AC 867 ms
155,444 KB
testcase_09 AC 473 ms
155,148 KB
testcase_10 AC 211 ms
86,188 KB
testcase_11 AC 216 ms
86,040 KB
testcase_12 AC 208 ms
86,296 KB
testcase_13 AC 177 ms
83,204 KB
testcase_14 AC 159 ms
80,800 KB
testcase_15 AC 196 ms
86,044 KB
testcase_16 AC 188 ms
84,764 KB
testcase_17 AC 122 ms
77,828 KB
testcase_18 AC 127 ms
77,864 KB
testcase_19 AC 244 ms
86,196 KB
testcase_20 AC 322 ms
144,572 KB
testcase_21 AC 391 ms
113,172 KB
testcase_22 AC 318 ms
157,916 KB
testcase_23 AC 289 ms
158,688 KB
testcase_24 AC 278 ms
145,628 KB
testcase_25 AC 508 ms
129,804 KB
testcase_26 AC 645 ms
120,692 KB
testcase_27 AC 236 ms
83,592 KB
testcase_28 AC 750 ms
144,456 KB
testcase_29 AC 439 ms
109,284 KB
testcase_30 AC 468 ms
117,260 KB
testcase_31 AC 463 ms
170,916 KB
testcase_32 AC 445 ms
147,036 KB
testcase_33 AC 365 ms
132,920 KB
testcase_34 AC 235 ms
112,736 KB
testcase_35 AC 253 ms
101,208 KB
testcase_36 AC 344 ms
103,320 KB
testcase_37 AC 480 ms
125,128 KB
testcase_38 AC 174 ms
80,292 KB
testcase_39 AC 195 ms
85,076 KB
testcase_40 AC 190 ms
85,000 KB
testcase_41 AC 206 ms
88,252 KB
testcase_42 AC 205 ms
88,176 KB
testcase_43 AC 278 ms
128,536 KB
testcase_44 AC 276 ms
128,836 KB
testcase_45 AC 277 ms
128,876 KB
testcase_46 AC 320 ms
135,036 KB
testcase_47 AC 364 ms
131,728 KB
testcase_48 AC 376 ms
136,404 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

from collections import deque
def is_ok(w):
    # 条件を満たすかどうか?問題ごとに定義
    que = deque([(0,0)])
    visited = [float('inf')]*N
    visited[0] = 0
    while que:
      t,c = que.popleft()
      for i,j in l[t]:
        if w > j or c+1 >= visited[i]:
          continue
        visited[i] = c+1
        que.append((i,c+1))
    if visited[-1] == float('inf'):
      visited[-1] = -1
    return visited[-1]



def meguru_bisect(ng, ok):
    '''
    初期値のng,okを受け取り,is_okを満たす最小(最大)のokを返す
    まずis_okを定義すべし
    ng ok は  とり得る最小の値-1 とり得る最大の値+1
    最大最小が逆の場合はよしなにひっくり返す
    '''
    num = 0
    while (abs(ok - ng) > 1):
        mid = (ok + ng) // 2
        flg = is_ok(mid)
        if flg != -1:
            ng = mid
            num = flg
        else:
            ok = mid
    return (ng,num)

N,M = map(int,input().split())
l = [[] for _ in range(N)]

for _ in range(M):
  a,b,c = map(int,input().split())
  a -= 1
  b -= 1
  l[a].append((b,c))
  l[b].append((a,c))
ng,ok = 0,10**18
ans = meguru_bisect(ng,ok)

print(ans[0],ans[1])
0