結果

問題 No.1473 おでぶなおばけさん
ユーザー 👑 hitonanodehitonanode
提出日時 2021-04-04 16:43:27
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
AC  
実行時間 608 ms / 2,000 ms
コード長 1,502 bytes
コンパイル時間 490 ms
コンパイル使用メモリ 10,876 KB
実行使用メモリ 40,152 KB
最終ジャッジ日時 2023-08-27 19:01:06
合計ジャッジ時間 18,160 ms
ジャッジサーバーID
(参考情報)
judge15 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 19 ms
8,716 KB
testcase_01 AC 20 ms
8,712 KB
testcase_02 AC 537 ms
37,164 KB
testcase_03 AC 375 ms
33,384 KB
testcase_04 AC 282 ms
24,752 KB
testcase_05 AC 88 ms
14,096 KB
testcase_06 AC 413 ms
34,432 KB
testcase_07 AC 569 ms
39,756 KB
testcase_08 AC 608 ms
40,152 KB
testcase_09 AC 579 ms
39,188 KB
testcase_10 AC 243 ms
22,104 KB
testcase_11 AC 237 ms
20,832 KB
testcase_12 AC 256 ms
22,572 KB
testcase_13 AC 143 ms
15,788 KB
testcase_14 AC 105 ms
13,624 KB
testcase_15 AC 201 ms
18,344 KB
testcase_16 AC 232 ms
21,636 KB
testcase_17 AC 32 ms
9,448 KB
testcase_18 AC 40 ms
9,920 KB
testcase_19 AC 239 ms
22,552 KB
testcase_20 AC 357 ms
30,524 KB
testcase_21 AC 371 ms
28,364 KB
testcase_22 AC 519 ms
30,400 KB
testcase_23 AC 434 ms
28,696 KB
testcase_24 AC 404 ms
27,388 KB
testcase_25 AC 508 ms
32,860 KB
testcase_26 AC 519 ms
33,780 KB
testcase_27 AC 167 ms
17,944 KB
testcase_28 AC 569 ms
38,308 KB
testcase_29 AC 322 ms
28,200 KB
testcase_30 AC 391 ms
31,424 KB
testcase_31 AC 463 ms
37,580 KB
testcase_32 AC 289 ms
35,304 KB
testcase_33 AC 266 ms
29,816 KB
testcase_34 AC 151 ms
19,648 KB
testcase_35 AC 131 ms
20,296 KB
testcase_36 AC 397 ms
26,376 KB
testcase_37 AC 477 ms
29,528 KB
testcase_38 AC 75 ms
12,564 KB
testcase_39 AC 236 ms
21,804 KB
testcase_40 AC 238 ms
21,804 KB
testcase_41 AC 211 ms
19,200 KB
testcase_42 AC 216 ms
19,260 KB
testcase_43 AC 233 ms
30,500 KB
testcase_44 AC 232 ms
30,500 KB
testcase_45 AC 232 ms
30,392 KB
testcase_46 AC 414 ms
30,744 KB
testcase_47 AC 503 ms
35,600 KB
testcase_48 AC 444 ms
33,472 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

# Python ACになってほしい
from collections import deque
import sys
input = sys.stdin.readline

class DSU:
    def __init__(self, N: int) -> None:
        self.par = list(range(N))
        self.sz = [1] * N

    def find(self, x: int) -> int:
        if self.par[x] != x:
            self.par[x] = self.find(self.par[x])
        return self.par[x]

    def unite(self, x: int, y: int) -> bool:
        x, y = self.find(x), self.find(y)
        if x == y:
            return False
        if self.sz[x] < self.sz[y]:
            x, y = y, x
        self.par[y] = x
        self.sz[x] += self.sz[y]
        return True

    def same(self, x: int, y: int) -> bool:
        return self.find(x) == self.find(y)


def main():
    N, M = map(int, input().split())
    uf = DSU(N)

    edges = []
    for _ in range(M):
        s, t, w = map(int, input().split())
        edges.append((w, s - 1, t - 1))

    edges.sort(reverse=True)
    ret = 1 << 30
    for w, u, v in edges:
        if uf.same(0, N - 1):
            break
        ret = w
        uf.unite(u, v)

    to = [[] for _ in range(N)]
    for w, s, t in edges:
        if w >= ret:
            to[s].append(t), to[t].append(s)

    dist = [1 << 30] * N
    dist[0] = 0
    q = deque([0])
    while q:
        now = q.popleft()
        for nxt in to[now]:
            if dist[nxt] > dist[now] + 1:
                dist[nxt] = dist[now] + 1
                q.append(nxt)
    
    print(ret, dist[N - 1])

if __name__ == '__main__':
    main()
0