結果

問題 No.1473 おでぶなおばけさん
ユーザー moharan627moharan627
提出日時 2021-04-09 22:32:13
言語 PyPy3
(7.3.13)
結果
AC  
実行時間 1,386 ms / 2,000 ms
コード長 2,399 bytes
コンパイル時間 301 ms
コンパイル使用メモリ 86,892 KB
実行使用メモリ 144,584 KB
最終ジャッジ日時 2023-09-07 12:03:07
合計ジャッジ時間 24,613 ms
ジャッジサーバーID
(参考情報)
judge15 / judge11
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 88 ms
71,420 KB
testcase_01 AC 88 ms
71,500 KB
testcase_02 AC 1,165 ms
117,096 KB
testcase_03 AC 484 ms
124,484 KB
testcase_04 AC 583 ms
99,608 KB
testcase_05 AC 243 ms
82,176 KB
testcase_06 AC 733 ms
107,812 KB
testcase_07 AC 720 ms
119,176 KB
testcase_08 AC 1,175 ms
118,016 KB
testcase_09 AC 652 ms
120,032 KB
testcase_10 AC 221 ms
87,292 KB
testcase_11 AC 248 ms
87,280 KB
testcase_12 AC 192 ms
87,308 KB
testcase_13 AC 176 ms
83,364 KB
testcase_14 AC 141 ms
81,668 KB
testcase_15 AC 224 ms
86,136 KB
testcase_16 AC 173 ms
85,384 KB
testcase_17 AC 114 ms
78,756 KB
testcase_18 AC 123 ms
79,764 KB
testcase_19 AC 254 ms
86,580 KB
testcase_20 AC 412 ms
121,736 KB
testcase_21 AC 503 ms
103,612 KB
testcase_22 AC 325 ms
141,560 KB
testcase_23 AC 299 ms
144,584 KB
testcase_24 AC 291 ms
134,396 KB
testcase_25 AC 1,386 ms
109,072 KB
testcase_26 AC 1,332 ms
108,116 KB
testcase_27 AC 323 ms
83,768 KB
testcase_28 AC 1,073 ms
116,380 KB
testcase_29 AC 559 ms
105,496 KB
testcase_30 AC 743 ms
105,404 KB
testcase_31 AC 650 ms
144,404 KB
testcase_32 AC 570 ms
124,080 KB
testcase_33 AC 478 ms
114,636 KB
testcase_34 AC 303 ms
99,912 KB
testcase_35 AC 248 ms
92,864 KB
testcase_36 AC 431 ms
97,616 KB
testcase_37 AC 713 ms
110,280 KB
testcase_38 AC 183 ms
80,348 KB
testcase_39 AC 175 ms
85,016 KB
testcase_40 AC 168 ms
85,292 KB
testcase_41 AC 228 ms
89,064 KB
testcase_42 AC 170 ms
89,048 KB
testcase_43 AC 249 ms
112,140 KB
testcase_44 AC 251 ms
112,144 KB
testcase_45 AC 253 ms
112,516 KB
testcase_46 AC 392 ms
117,464 KB
testcase_47 AC 476 ms
110,988 KB
testcase_48 AC 467 ms
110,332 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import sys
def II(): return int(sys.stdin.readline())
def LI(): return list(map(int, sys.stdin.readline().split()))
def LC(): return list(input())
def IC(): return [int(c) for c in input()]
def MI(): return map(int, sys.stdin.readline().split())
INF = float('inf')
MOD = 10**9 + 7
def solve():
    N,M = MI()
    Graph = [[] for i in range(N+1)]
    for m in range(M):
        S,T,D = MI()
        Graph[S].append((T,D))
        Graph[T].append((S, D))
    from collections import deque
    def is_ok(arg):
        Q = deque()
        Seen = [False for i in range(N + 1)]
        Dist = [INF for i in range(N+1)]
        Dist[1] = 0
        s = 1
        Seen[s] = True
        Q.append(s)
        #始点をキューに入れる
        while len(Q) > 0:
            now = Q.popleft()
            #隣接グラフGraphの場合
            for next,weight in Graph[now]:
                if(weight<arg):
                    continue
                if(Seen[next] == False):#未探索ならば
                    Seen[next] = True
                    Q.append(next)
                #始点からの距離とかの計算はここで
                Dist[next] = min(Dist[now]+1,Dist[next])
        if(Dist[N] == INF):
            return False
        else:
            return True
    def meguru_bisect(ng, ok):
        """
        負の無限~(目的値)が条件を満たす場合
        ng…条件を満たさない値の範囲での最小値
        ok…条件を満たす値の範囲での最大値
        """
        while (abs(ok - ng) > 1):
            mid = (ok + ng) // 2
            if is_ok(mid):
                ok = mid
            else:
                ng = mid
        return ok
    W = meguru_bisect(10**9 + 1, 1)
    Q = deque()
    Seen = [False for i in range(N + 1)]
    Dist = [INF for i in range(N + 1)]
    Dist[1] = 0
    s = 1
    Seen[s] = True
    Q.append(s)
    # 始点をキューに入れる
    while len(Q) > 0:
        now = Q.popleft()
        # 隣接グラフGraphの場合
        for next, weight in Graph[now]:
            if (weight < W):
                continue
            if (Seen[next] == False):  # 未探索ならば
                Seen[next] = True
                Q.append(next)
            # 始点からの距離とかの計算はここで
            Dist[next] = min(Dist[now] + 1, Dist[next])
    print(W,Dist[N])
    return
solve()
0