結果

問題 No.1473 おでぶなおばけさん
ユーザー ああいいああいい
提出日時 2022-05-31 11:17:53
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 714 ms / 2,000 ms
コード長 999 bytes
コンパイル時間 267 ms
コンパイル使用メモリ 82,440 KB
実行使用メモリ 107,080 KB
最終ジャッジ日時 2024-09-21 01:15:06
合計ジャッジ時間 21,793 ms
ジャッジサーバーID
(参考情報)
judge1 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 46 ms
55,516 KB
testcase_01 AC 44 ms
55,048 KB
testcase_02 AC 649 ms
104,824 KB
testcase_03 AC 546 ms
102,092 KB
testcase_04 AC 454 ms
92,828 KB
testcase_05 AC 240 ms
82,176 KB
testcase_06 AC 584 ms
101,972 KB
testcase_07 AC 664 ms
105,684 KB
testcase_08 AC 714 ms
107,080 KB
testcase_09 AC 714 ms
105,904 KB
testcase_10 AC 272 ms
89,900 KB
testcase_11 AC 277 ms
90,224 KB
testcase_12 AC 267 ms
89,872 KB
testcase_13 AC 191 ms
86,024 KB
testcase_14 AC 155 ms
81,904 KB
testcase_15 AC 257 ms
90,796 KB
testcase_16 AC 260 ms
89,588 KB
testcase_17 AC 84 ms
77,440 KB
testcase_18 AC 90 ms
77,352 KB
testcase_19 AC 325 ms
89,448 KB
testcase_20 AC 468 ms
96,676 KB
testcase_21 AC 481 ms
94,672 KB
testcase_22 AC 474 ms
97,856 KB
testcase_23 AC 421 ms
96,932 KB
testcase_24 AC 362 ms
94,720 KB
testcase_25 AC 464 ms
97,900 KB
testcase_26 AC 468 ms
97,804 KB
testcase_27 AC 221 ms
83,716 KB
testcase_28 AC 660 ms
106,364 KB
testcase_29 AC 366 ms
95,160 KB
testcase_30 AC 393 ms
96,724 KB
testcase_31 AC 530 ms
103,448 KB
testcase_32 AC 387 ms
98,740 KB
testcase_33 AC 373 ms
95,476 KB
testcase_34 AC 292 ms
87,664 KB
testcase_35 AC 263 ms
87,036 KB
testcase_36 AC 405 ms
92,648 KB
testcase_37 AC 387 ms
94,960 KB
testcase_38 AC 142 ms
79,168 KB
testcase_39 AC 264 ms
89,896 KB
testcase_40 AC 268 ms
89,596 KB
testcase_41 AC 274 ms
90,160 KB
testcase_42 AC 264 ms
90,260 KB
testcase_43 AC 223 ms
100,240 KB
testcase_44 AC 224 ms
100,580 KB
testcase_45 AC 223 ms
100,532 KB
testcase_46 AC 478 ms
96,848 KB
testcase_47 AC 517 ms
100,648 KB
testcase_48 AC 442 ms
97,940 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import sys
sys.setrecursionlimit(10 ** 8)

n,m = map(int,input().split())
edge = []
for _ in range(m):
    s,t,d = map(int,input().split())
    s -= 1
    t -= 1
    edge.append((s,t,d))
edge.sort(key = lambda x:x[2])

parent = list(range(n))
def find(i):
    if parent[i] == i:return i
    parent[i] = find(parent[i])
    return parent[i]
def unite(i,j):
    I = find(i)
    J = find(j)
    if I == J:return False
    parent[I] = J
    parent[i] = J
    return True
def isSame(i,j):
    return find(i) == find(j)

ans = 0
G = [[] for _ in range(n)]
while not isSame(0,n-1):
    s,t,d = edge.pop()
    ans = d
    G[s].append(t)
    G[t].append(s)
    unite(s,t)
while edge and edge[-1][2] == ans:
    s,t,d = edge.pop()
    G[s].append(t)
    G[t].append(s)
from collections import deque
q = deque()
q.append(0)
dist = [-1] * n
dist[0] = 0
while q:
    now = q.popleft()
    for v in G[now]:
        if dist[v] == -1:
            dist[v] = dist[now] + 1
            q.append(v)
print(ans,dist[-1])
0