結果
問題 | No.1473 おでぶなおばけさん |
ユーザー | irumo8202 |
提出日時 | 2022-01-30 13:36:45 |
言語 | PyPy3 (7.3.15) |
結果 |
WA
|
実行時間 | - |
コード長 | 1,875 bytes |
コンパイル時間 | 272 ms |
コンパイル使用メモリ | 82,048 KB |
実行使用メモリ | 100,880 KB |
最終ジャッジ日時 | 2024-06-11 08:12:39 |
合計ジャッジ時間 | 18,498 ms |
ジャッジサーバーID (参考情報) |
judge4 / judge3 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 40 ms
53,888 KB |
testcase_01 | AC | 43 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 | 319 ms
92,092 KB |
testcase_23 | AC | 287 ms
97,228 KB |
testcase_24 | AC | 293 ms
89,828 KB |
testcase_25 | AC | 318 ms
90,304 KB |
testcase_26 | AC | 318 ms
90,696 KB |
testcase_27 | AC | 200 ms
82,536 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 | 274 ms
90,672 KB |
testcase_37 | AC | 264 ms
87,212 KB |
testcase_38 | AC | 154 ms
79,744 KB |
testcase_39 | WA | - |
testcase_40 | WA | - |
testcase_41 | AC | 258 ms
87,040 KB |
testcase_42 | AC | 263 ms
87,296 KB |
testcase_43 | AC | 300 ms
92,800 KB |
testcase_44 | AC | 282 ms
92,928 KB |
testcase_45 | AC | 279 ms
92,544 KB |
testcase_46 | AC | 387 ms
89,120 KB |
testcase_47 | AC | 446 ms
96,988 KB |
testcase_48 | AC | 410 ms
95,088 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))