結果
問題 | No.1473 おでぶなおばけさん |
ユーザー | irumo8202 |
提出日時 | 2022-01-30 13:53:10 |
言語 | PyPy3 (7.3.15) |
結果 |
WA
|
実行時間 | - |
コード長 | 1,805 bytes |
コンパイル時間 | 245 ms |
コンパイル使用メモリ | 81,900 KB |
実行使用メモリ | 133,424 KB |
最終ジャッジ日時 | 2024-06-11 08:14:42 |
合計ジャッジ時間 | 18,649 ms |
ジャッジサーバーID (参考情報) |
judge1 / judge5 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 39 ms
54,016 KB |
testcase_01 | AC | 39 ms
54,016 KB |
testcase_02 | AC | 522 ms
118,600 KB |
testcase_03 | AC | 461 ms
117,500 KB |
testcase_04 | AC | 371 ms
101,668 KB |
testcase_05 | AC | 211 ms
82,012 KB |
testcase_06 | AC | 436 ms
110,796 KB |
testcase_07 | AC | 592 ms
132,776 KB |
testcase_08 | AC | 623 ms
133,424 KB |
testcase_09 | AC | 532 ms
127,660 KB |
testcase_10 | AC | 222 ms
86,736 KB |
testcase_11 | AC | 226 ms
86,784 KB |
testcase_12 | AC | 223 ms
86,784 KB |
testcase_13 | AC | 174 ms
82,944 KB |
testcase_14 | AC | 143 ms
81,124 KB |
testcase_15 | AC | 224 ms
87,680 KB |
testcase_16 | AC | 225 ms
86,636 KB |
testcase_17 | AC | 84 ms
77,056 KB |
testcase_18 | AC | 92 ms
77,056 KB |
testcase_19 | AC | 294 ms
91,004 KB |
testcase_20 | AC | 459 ms
113,316 KB |
testcase_21 | AC | 424 ms
100,836 KB |
testcase_22 | WA | - |
testcase_23 | WA | - |
testcase_24 | WA | - |
testcase_25 | WA | - |
testcase_26 | WA | - |
testcase_27 | WA | - |
testcase_28 | AC | 538 ms
128,432 KB |
testcase_29 | WA | - |
testcase_30 | WA | - |
testcase_31 | AC | 528 ms
129,248 KB |
testcase_32 | AC | 374 ms
110,424 KB |
testcase_33 | AC | 424 ms
107,456 KB |
testcase_34 | AC | 321 ms
96,208 KB |
testcase_35 | AC | 253 ms
89,880 KB |
testcase_36 | WA | - |
testcase_37 | WA | - |
testcase_38 | WA | - |
testcase_39 | AC | 234 ms
86,912 KB |
testcase_40 | AC | 223 ms
86,852 KB |
testcase_41 | AC | 226 ms
87,296 KB |
testcase_42 | AC | 219 ms
86,768 KB |
testcase_43 | AC | 196 ms
94,132 KB |
testcase_44 | AC | 198 ms
94,012 KB |
testcase_45 | AC | 199 ms
94,208 KB |
testcase_46 | AC | 501 ms
108,384 KB |
testcase_47 | AC | 577 ms
114,488 KB |
testcase_48 | AC | 488 ms
109,192 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 = 0 G = [[] for _ in range(N)] for s, t, d in edges: uf.union(s, t) G[s - 1].append(t - 1) G[t - 1].append(s - 1) if uf.same(1, N): w = d break que = deque([0]) visited = [False] * N dist = [-1] * N visited[0] = True dist[0] = 0 while que: v = que.popleft() for u in G[v]: if visited[u]: continue visited[u] = True dist[u] = dist[v] + 1 que.append(u) print(w, dist[-1])