結果
問題 | No.1473 おでぶなおばけさん |
ユーザー | irumo8202 |
提出日時 | 2022-01-30 13:43:12 |
言語 | PyPy3 (7.3.15) |
結果 |
WA
|
実行時間 | - |
コード長 | 1,855 bytes |
コンパイル時間 | 318 ms |
コンパイル使用メモリ | 81,924 KB |
実行使用メモリ | 101,236 KB |
最終ジャッジ日時 | 2024-06-11 08:13:47 |
合計ジャッジ時間 | 19,905 ms |
ジャッジサーバーID (参考情報) |
judge1 / judge4 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 45 ms
54,144 KB |
testcase_01 | AC | 45 ms
54,272 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 | 372 ms
92,148 KB |
testcase_23 | AC | 300 ms
89,852 KB |
testcase_24 | AC | 333 ms
90,328 KB |
testcase_25 | AC | 372 ms
90,968 KB |
testcase_26 | AC | 355 ms
90,372 KB |
testcase_27 | AC | 219 ms
82,688 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 | 321 ms
90,000 KB |
testcase_37 | AC | 321 ms
94,136 KB |
testcase_38 | AC | 172 ms
79,540 KB |
testcase_39 | WA | - |
testcase_40 | WA | - |
testcase_41 | AC | 281 ms
87,296 KB |
testcase_42 | AC | 288 ms
87,104 KB |
testcase_43 | AC | 231 ms
93,440 KB |
testcase_44 | AC | 233 ms
92,928 KB |
testcase_45 | AC | 229 ms
93,552 KB |
testcase_46 | AC | 423 ms
90,128 KB |
testcase_47 | AC | 493 ms
90,372 KB |
testcase_48 | AC | 470 ms
95,768 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])