結果

問題 No.1473 おでぶなおばけさん
ユーザー irumo8202irumo8202
提出日時 2022-01-30 13:53:10
言語 PyPy3
(7.3.15)
結果
WA  
実行時間 -
コード長 1,805 bytes
コンパイル時間 292 ms
コンパイル使用メモリ 87,364 KB
実行使用メモリ 129,664 KB
最終ジャッジ日時 2023-09-02 01:35:00
合計ジャッジ時間 23,667 ms
ジャッジサーバーID
(参考情報)
judge11 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 92 ms
71,436 KB
testcase_01 AC 93 ms
71,908 KB
testcase_02 AC 670 ms
117,140 KB
testcase_03 AC 729 ms
113,700 KB
testcase_04 AC 475 ms
101,632 KB
testcase_05 AC 288 ms
83,932 KB
testcase_06 AC 565 ms
113,620 KB
testcase_07 AC 745 ms
125,104 KB
testcase_08 AC 786 ms
127,020 KB
testcase_09 AC 694 ms
123,764 KB
testcase_10 AC 299 ms
88,992 KB
testcase_11 AC 294 ms
88,980 KB
testcase_12 AC 300 ms
88,824 KB
testcase_13 AC 225 ms
84,732 KB
testcase_14 AC 193 ms
83,148 KB
testcase_15 AC 274 ms
87,128 KB
testcase_16 AC 294 ms
88,624 KB
testcase_17 AC 130 ms
78,044 KB
testcase_18 AC 138 ms
79,252 KB
testcase_19 AC 373 ms
88,692 KB
testcase_20 AC 573 ms
113,832 KB
testcase_21 AC 551 ms
104,916 KB
testcase_22 WA -
testcase_23 WA -
testcase_24 WA -
testcase_25 WA -
testcase_26 WA -
testcase_27 WA -
testcase_28 AC 673 ms
129,664 KB
testcase_29 WA -
testcase_30 WA -
testcase_31 AC 670 ms
126,212 KB
testcase_32 AC 486 ms
110,868 KB
testcase_33 AC 538 ms
110,188 KB
testcase_34 AC 409 ms
95,744 KB
testcase_35 AC 338 ms
92,140 KB
testcase_36 WA -
testcase_37 WA -
testcase_38 WA -
testcase_39 AC 302 ms
89,112 KB
testcase_40 AC 295 ms
89,096 KB
testcase_41 AC 292 ms
88,824 KB
testcase_42 AC 292 ms
89,108 KB
testcase_43 AC 270 ms
101,456 KB
testcase_44 AC 265 ms
101,600 KB
testcase_45 AC 264 ms
101,416 KB
testcase_46 AC 603 ms
106,880 KB
testcase_47 AC 696 ms
113,756 KB
testcase_48 AC 585 ms
107,212 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

from collections import defaultdict, deque


class UnionFind:
    def __init__(self, n):
        self.n = n
        self.parents = [-1] * n

    def find(self, x):
        if self.parents[x] < 0:
            return x
        else:
            self.parents[x] = self.find(self.parents[x])
            return self.parents[x]

    def union(self, x, y):
        x = self.find(x)
        y = self.find(y)

        if x == y:
            return

        if self.parents[x] > self.parents[y]:
            x, y = y, x

        self.parents[x] += self.parents[y]
        self.parents[y] = x

    def size(self, x):
        return -self.parents[self.find(x)]

    def same(self, x, y):
        return self.find(x) == self.find(y)

    def members(self, x):
        root = self.find(x)
        return [i for i in range(self.n) if self.find(i) == root]

    def roots(self):
        return [i for i, x in enumerate(self.parents) if x < 0]

    def group_count(self):
        return len(self.roots())

    def all_group_members(self):
        group_members = defaultdict(list)
        for member in range(self.n):
            group_members[self.find(member)].append(member)
        return group_members


N, M = map(int, input().split())

edges = [list(map(int, input().split())) for _ in range(M)]
edges.sort(key=lambda x: -x[2])


uf = UnionFind(N + 1)

w = 0
G = [[] for _ in range(N)]
for s, t, d in edges:
    uf.union(s, t)
    G[s - 1].append(t - 1)
    G[t - 1].append(s - 1)
    if uf.same(1, N):
        w = d
        break


que = deque([0])
visited = [False] * N
dist = [-1] * N
visited[0] = True
dist[0] = 0

while que:
    v = que.popleft()

    for u in G[v]:
        if visited[u]:
            continue
        visited[u] = True
        dist[u] = dist[v] + 1
        que.append(u)

print(w, dist[-1])
0