結果
問題 | 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 |
コンパイル時間 | 124 ms |
コンパイル使用メモリ | 10,992 KB |
実行使用メモリ | 49,428 KB |
最終ジャッジ日時 | 2023-09-02 01:33:55 |
合計ジャッジ時間 | 26,159 ms |
ジャッジサーバーID (参考情報) |
judge13 / judge12 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 17 ms
8,804 KB |
testcase_01 | AC | 19 ms
8,812 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 | 580 ms
41,976 KB |
testcase_23 | AC | 494 ms
36,948 KB |
testcase_24 | AC | 487 ms
36,540 KB |
testcase_25 | AC | 574 ms
44,052 KB |
testcase_26 | AC | 580 ms
45,036 KB |
testcase_27 | AC | 228 ms
23,596 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 | 438 ms
36,212 KB |
testcase_37 | AC | 436 ms
37,092 KB |
testcase_38 | AC | 99 ms
14,408 KB |
testcase_39 | WA | - |
testcase_40 | WA | - |
testcase_41 | AC | 428 ms
29,648 KB |
testcase_42 | AC | 427 ms
29,768 KB |
testcase_43 | AC | 528 ms
42,768 KB |
testcase_44 | AC | 526 ms
42,732 KB |
testcase_45 | AC | 525 ms
42,780 KB |
testcase_46 | AC | 526 ms
37,620 KB |
testcase_47 | AC | 676 ms
43,736 KB |
testcase_48 | AC | 613 ms
40,476 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))