結果

問題 No.1473 おでぶなおばけさん
ユーザー O2MTO2MT
提出日時 2021-06-02 00:54:11
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 1,022 ms / 2,000 ms
コード長 1,189 bytes
コンパイル時間 344 ms
コンパイル使用メモリ 82,432 KB
実行使用メモリ 170,112 KB
最終ジャッジ日時 2024-04-26 09:58:28
合計ジャッジ時間 20,490 ms
ジャッジサーバーID
(参考情報)
judge4 / judge3
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 44 ms
54,016 KB
testcase_01 AC 46 ms
53,888 KB
testcase_02 AC 865 ms
141,512 KB
testcase_03 AC 413 ms
131,840 KB
testcase_04 AC 478 ms
114,476 KB
testcase_05 AC 214 ms
80,768 KB
testcase_06 AC 694 ms
125,696 KB
testcase_07 AC 701 ms
152,596 KB
testcase_08 AC 1,022 ms
152,240 KB
testcase_09 AC 570 ms
152,424 KB
testcase_10 AC 187 ms
84,112 KB
testcase_11 AC 203 ms
83,712 KB
testcase_12 AC 175 ms
83,832 KB
testcase_13 AC 148 ms
81,024 KB
testcase_14 AC 123 ms
79,104 KB
testcase_15 AC 176 ms
83,712 KB
testcase_16 AC 157 ms
83,164 KB
testcase_17 AC 97 ms
77,056 KB
testcase_18 AC 102 ms
77,312 KB
testcase_19 AC 239 ms
84,736 KB
testcase_20 AC 338 ms
138,880 KB
testcase_21 AC 421 ms
110,812 KB
testcase_22 AC 343 ms
157,440 KB
testcase_23 AC 322 ms
156,964 KB
testcase_24 AC 291 ms
144,280 KB
testcase_25 AC 592 ms
125,824 KB
testcase_26 AC 733 ms
119,636 KB
testcase_27 AC 209 ms
82,304 KB
testcase_28 AC 1,004 ms
143,232 KB
testcase_29 AC 458 ms
112,364 KB
testcase_30 AC 540 ms
111,848 KB
testcase_31 AC 594 ms
170,112 KB
testcase_32 AC 499 ms
144,768 KB
testcase_33 AC 393 ms
132,096 KB
testcase_34 AC 224 ms
109,860 KB
testcase_35 AC 232 ms
98,568 KB
testcase_36 AC 344 ms
100,052 KB
testcase_37 AC 542 ms
121,940 KB
testcase_38 AC 138 ms
78,848 KB
testcase_39 AC 188 ms
82,944 KB
testcase_40 AC 163 ms
82,964 KB
testcase_41 AC 193 ms
87,604 KB
testcase_42 AC 178 ms
87,604 KB
testcase_43 AC 270 ms
125,696 KB
testcase_44 AC 260 ms
125,616 KB
testcase_45 AC 272 ms
125,952 KB
testcase_46 AC 323 ms
132,488 KB
testcase_47 AC 417 ms
139,136 KB
testcase_48 AC 430 ms
140,672 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