結果
問題 | No.1473 おでぶなおばけさん |
ユーザー | irumo8202 |
提出日時 | 2022-01-30 13:40:18 |
言語 | Python3 (3.12.2 + numpy 1.26.4 + scipy 1.12.0) |
結果 |
WA
|
実行時間 | - |
コード長 | 1,875 bytes |
コンパイル時間 | 220 ms |
コンパイル使用メモリ | 12,800 KB |
実行使用メモリ | 51,900 KB |
最終ジャッジ日時 | 2024-06-11 08:13:23 |
合計ジャッジ時間 | 28,956 ms |
ジャッジサーバーID (参考情報) |
judge3 / judge4 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 29 ms
11,008 KB |
testcase_01 | AC | 27 ms
11,008 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 | 658 ms
44,300 KB |
testcase_23 | AC | 555 ms
39,152 KB |
testcase_24 | AC | 628 ms
38,828 KB |
testcase_25 | AC | 659 ms
46,036 KB |
testcase_26 | AC | 646 ms
47,352 KB |
testcase_27 | AC | 260 ms
25,672 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 | 503 ms
38,332 KB |
testcase_37 | AC | 521 ms
39,412 KB |
testcase_38 | AC | 124 ms
16,896 KB |
testcase_39 | WA | - |
testcase_40 | WA | - |
testcase_41 | AC | 504 ms
32,104 KB |
testcase_42 | AC | 514 ms
32,104 KB |
testcase_43 | AC | 578 ms
44,832 KB |
testcase_44 | AC | 587 ms
45,120 KB |
testcase_45 | AC | 586 ms
44,884 KB |
testcase_46 | AC | 630 ms
39,868 KB |
testcase_47 | AC | 759 ms
45,780 KB |
testcase_48 | AC | 675 ms
42,512 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, c = 10 ** 10, 0 for s, t, d in edges: if uf.same(s, t): continue w = min(w, d) c += 1 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, 0)]) visited = [0] * N visited[0] = 1 while que: v, dist = que.popleft() if v == N - 1: print(w, dist) exit() for u in G[v]: if visited[u]: continue visited[u] = 1 que.append((u, dist + 1))