結果

問題 No.1473 おでぶなおばけさん
ユーザー tamatotamato
提出日時 2021-04-09 21:40:19
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 682 ms / 2,000 ms
コード長 1,954 bytes
コンパイル時間 462 ms
コンパイル使用メモリ 87,648 KB
実行使用メモリ 118,420 KB
最終ジャッジ日時 2023-09-07 10:26:54
合計ジャッジ時間 20,671 ms
ジャッジサーバーID
(参考情報)
judge11 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 97 ms
71,936 KB
testcase_01 AC 98 ms
71,892 KB
testcase_02 AC 600 ms
111,600 KB
testcase_03 AC 504 ms
104,732 KB
testcase_04 AC 373 ms
91,028 KB
testcase_05 AC 280 ms
83,872 KB
testcase_06 AC 507 ms
101,948 KB
testcase_07 AC 624 ms
113,728 KB
testcase_08 AC 682 ms
118,420 KB
testcase_09 AC 607 ms
108,160 KB
testcase_10 AC 284 ms
91,192 KB
testcase_11 AC 283 ms
91,564 KB
testcase_12 AC 286 ms
91,472 KB
testcase_13 AC 216 ms
85,580 KB
testcase_14 AC 180 ms
85,028 KB
testcase_15 AC 267 ms
89,216 KB
testcase_16 AC 287 ms
91,440 KB
testcase_17 AC 117 ms
77,952 KB
testcase_18 AC 123 ms
77,432 KB
testcase_19 AC 342 ms
91,608 KB
testcase_20 AC 468 ms
93,812 KB
testcase_21 AC 455 ms
101,080 KB
testcase_22 AC 398 ms
102,688 KB
testcase_23 AC 360 ms
106,432 KB
testcase_24 AC 349 ms
97,704 KB
testcase_25 AC 404 ms
108,356 KB
testcase_26 AC 435 ms
109,116 KB
testcase_27 AC 249 ms
85,224 KB
testcase_28 AC 510 ms
107,244 KB
testcase_29 AC 363 ms
93,240 KB
testcase_30 AC 402 ms
99,748 KB
testcase_31 AC 477 ms
116,360 KB
testcase_32 AC 367 ms
99,952 KB
testcase_33 AC 344 ms
100,948 KB
testcase_34 AC 287 ms
87,780 KB
testcase_35 AC 295 ms
91,072 KB
testcase_36 AC 300 ms
91,308 KB
testcase_37 AC 418 ms
105,316 KB
testcase_38 AC 207 ms
82,904 KB
testcase_39 AC 280 ms
91,192 KB
testcase_40 AC 272 ms
91,388 KB
testcase_41 AC 284 ms
91,160 KB
testcase_42 AC 287 ms
91,408 KB
testcase_43 AC 253 ms
105,044 KB
testcase_44 AC 254 ms
106,700 KB
testcase_45 AC 252 ms
106,740 KB
testcase_46 AC 518 ms
104,788 KB
testcase_47 AC 539 ms
102,580 KB
testcase_48 AC 514 ms
108,772 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

mod = 1000000007
eps = 10**-9


def main():
    import sys
    from collections import deque
    input = sys.stdin.buffer.readline

    class UnionFind():
        def __init__(self, n):
            self.n = n
            self.root = [-1] * (n + 1)
            self.rnk = [0] * (n + 1)

        def find_root(self, x):
            while self.root[x] >= 0:
                x = self.root[x]
            return x

        def unite(self, x, y):
            x = self.find_root(x)
            y = self.find_root(y)
            if x == y:
                return
            elif self.rnk[x] > self.rnk[y]:
                self.root[x] += self.root[y]
                self.root[y] = x
            else:
                self.root[y] += self.root[x]
                self.root[x] = y
                if self.rnk[x] == self.rnk[y]:
                    self.rnk[y] += 1

        def isSameGroup(self, x, y):
            return self.find_root(x) == self.find_root(y)

        def size(self, x):
            return -self.root[self.find_root(x)]

    N, M = map(int, input().split())
    E = []
    for _ in range(M):
        E.append(tuple(map(int, input().split())))
    E.sort(key=lambda x: x[2], reverse=True)
    UF = UnionFind(N)
    for a, b, c in E:
        UF.unite(a, b)
        if UF.isSameGroup(1, N):
            w = c
            break
    adj = [[] for _ in range(N+1)]
    for a, b, c in E:
        if c < w:
            break
        adj[a].append(b)
        adj[b].append(a)

    que = deque()
    que.append(1)
    seen = [-1] * (N+1)
    seen[1] = 0
    par = [0] * (N+1)
    child = [[] for _ in range(N+1)]
    seq = []
    while que:
        v = que.popleft()
        seq.append(v)
        for u in adj[v]:
            if seen[u] == -1:
                seen[u] = seen[v] + 1
                par[u] = v
                child[v].append(u)
                que.append(u)
    seq.reverse()
    print(w, seen[N])


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