結果
問題 | No.1473 おでぶなおばけさん |
ユーザー | irumo8202 |
提出日時 | 2022-01-30 13:43:12 |
言語 | PyPy3 (7.3.15) |
結果 |
WA
|
実行時間 | - |
コード長 | 1,855 bytes |
コンパイル時間 | 620 ms |
コンパイル使用メモリ | 87,348 KB |
実行使用メモリ | 103,964 KB |
最終ジャッジ日時 | 2023-09-02 01:34:17 |
合計ジャッジ時間 | 21,250 ms |
ジャッジサーバーID (参考情報) |
judge11 / judge13 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 85 ms
71,932 KB |
testcase_01 | AC | 84 ms
71,780 KB |
testcase_02 | WA | - |
testcase_03 | WA | - |
testcase_04 | WA | - |
testcase_05 | WA | - |
testcase_06 | WA | - |
testcase_07 | WA | - |
testcase_08 | WA | - |
testcase_09 | WA | - |
testcase_10 | WA | - |
testcase_11 | WA | - |
testcase_12 | WA | - |
testcase_13 | WA | - |
testcase_14 | WA | - |
testcase_15 | WA | - |
testcase_16 | WA | - |
testcase_17 | WA | - |
testcase_18 | WA | - |
testcase_19 | WA | - |
testcase_20 | WA | - |
testcase_21 | WA | - |
testcase_22 | AC | 401 ms
101,192 KB |
testcase_23 | AC | 341 ms
97,224 KB |
testcase_24 | AC | 378 ms
90,720 KB |
testcase_25 | AC | 430 ms
99,616 KB |
testcase_26 | AC | 435 ms
99,176 KB |
testcase_27 | AC | 278 ms
85,996 KB |
testcase_28 | WA | - |
testcase_29 | WA | - |
testcase_30 | WA | - |
testcase_31 | WA | - |
testcase_32 | WA | - |
testcase_33 | WA | - |
testcase_34 | WA | - |
testcase_35 | WA | - |
testcase_36 | AC | 327 ms
90,948 KB |
testcase_37 | AC | 352 ms
96,808 KB |
testcase_38 | AC | 206 ms
81,728 KB |
testcase_39 | WA | - |
testcase_40 | WA | - |
testcase_41 | AC | 292 ms
89,604 KB |
testcase_42 | AC | 293 ms
89,392 KB |
testcase_43 | AC | 248 ms
98,708 KB |
testcase_44 | AC | 251 ms
98,804 KB |
testcase_45 | AC | 251 ms
98,604 KB |
testcase_46 | AC | 419 ms
90,660 KB |
testcase_47 | AC | 498 ms
98,940 KB |
testcase_48 | AC | 461 ms
94,012 KB |
ソースコード
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 = 10 ** 10 for s, t, d in edges: if uf.same(s, t): continue w = min(w, d) uf.union(s, t) G = [[] for _ in range(N)] for s, t, d in edges: if d >= w: G[s - 1].append(t - 1) G[t - 1].append(s - 1) que = deque([0]) visited = [0] * N dist = [-1] * N visited[0] = 1 dist[0] = 0 while que: v = que.popleft() for u in G[v]: if visited[u]: continue visited[u] = 1 dist[u] = dist[v] + 1 que.append(u) print(w, dist[-1])