結果

問題 No.1473 おでぶなおばけさん
ユーザー ああいいああいい
提出日時 2022-05-31 11:17:53
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 706 ms / 2,000 ms
コード長 999 bytes
コンパイル時間 448 ms
コンパイル使用メモリ 81,824 KB
実行使用メモリ 106,588 KB
最終ジャッジ日時 2023-10-21 00:35:32
合計ジャッジ時間 23,584 ms
ジャッジサーバーID
(参考情報)
judge15 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 41 ms
55,628 KB
testcase_01 AC 41 ms
55,628 KB
testcase_02 AC 658 ms
104,360 KB
testcase_03 AC 533 ms
101,680 KB
testcase_04 AC 453 ms
92,420 KB
testcase_05 AC 237 ms
82,080 KB
testcase_06 AC 570 ms
101,608 KB
testcase_07 AC 635 ms
105,220 KB
testcase_08 AC 684 ms
106,588 KB
testcase_09 AC 706 ms
105,504 KB
testcase_10 AC 271 ms
89,368 KB
testcase_11 AC 271 ms
89,336 KB
testcase_12 AC 275 ms
89,324 KB
testcase_13 AC 201 ms
85,636 KB
testcase_14 AC 155 ms
81,640 KB
testcase_15 AC 257 ms
90,296 KB
testcase_16 AC 263 ms
89,332 KB
testcase_17 AC 85 ms
77,236 KB
testcase_18 AC 92 ms
77,036 KB
testcase_19 AC 333 ms
88,976 KB
testcase_20 AC 472 ms
96,220 KB
testcase_21 AC 483 ms
94,164 KB
testcase_22 AC 513 ms
97,088 KB
testcase_23 AC 435 ms
96,548 KB
testcase_24 AC 386 ms
94,156 KB
testcase_25 AC 484 ms
97,328 KB
testcase_26 AC 471 ms
97,144 KB
testcase_27 AC 219 ms
83,092 KB
testcase_28 AC 669 ms
105,832 KB
testcase_29 AC 359 ms
94,828 KB
testcase_30 AC 392 ms
96,108 KB
testcase_31 AC 529 ms
103,456 KB
testcase_32 AC 383 ms
98,748 KB
testcase_33 AC 379 ms
95,416 KB
testcase_34 AC 294 ms
87,184 KB
testcase_35 AC 264 ms
86,584 KB
testcase_36 AC 410 ms
92,208 KB
testcase_37 AC 400 ms
93,860 KB
testcase_38 AC 145 ms
78,692 KB
testcase_39 AC 263 ms
89,340 KB
testcase_40 AC 267 ms
89,316 KB
testcase_41 AC 257 ms
89,672 KB
testcase_42 AC 260 ms
89,672 KB
testcase_43 AC 219 ms
99,916 KB
testcase_44 AC 222 ms
99,920 KB
testcase_45 AC 222 ms
99,916 KB
testcase_46 AC 478 ms
96,352 KB
testcase_47 AC 497 ms
99,920 KB
testcase_48 AC 434 ms
97,568 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