結果
問題 | No.1473 おでぶなおばけさん |
ユーザー | 👑 rin204 |
提出日時 | 2022-01-18 04:14:20 |
言語 | PyPy3 (7.3.15) |
結果 |
AC
|
実行時間 | 551 ms / 2,000 ms |
コード長 | 1,969 bytes |
コンパイル時間 | 432 ms |
コンパイル使用メモリ | 82,432 KB |
実行使用メモリ | 115,144 KB |
最終ジャッジ日時 | 2024-05-02 19:15:45 |
合計ジャッジ時間 | 18,511 ms |
ジャッジサーバーID (参考情報) |
judge3 / judge5 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 43 ms
54,400 KB |
testcase_01 | AC | 41 ms
54,016 KB |
testcase_02 | AC | 500 ms
110,540 KB |
testcase_03 | AC | 413 ms
106,744 KB |
testcase_04 | AC | 335 ms
96,128 KB |
testcase_05 | AC | 202 ms
80,820 KB |
testcase_06 | AC | 418 ms
105,492 KB |
testcase_07 | AC | 539 ms
113,784 KB |
testcase_08 | AC | 551 ms
114,120 KB |
testcase_09 | AC | 495 ms
115,144 KB |
testcase_10 | AC | 236 ms
87,040 KB |
testcase_11 | AC | 232 ms
87,168 KB |
testcase_12 | AC | 248 ms
86,912 KB |
testcase_13 | AC | 185 ms
83,200 KB |
testcase_14 | AC | 148 ms
81,152 KB |
testcase_15 | AC | 247 ms
87,936 KB |
testcase_16 | AC | 231 ms
87,296 KB |
testcase_17 | AC | 91 ms
77,312 KB |
testcase_18 | AC | 92 ms
77,184 KB |
testcase_19 | AC | 291 ms
89,292 KB |
testcase_20 | AC | 401 ms
103,868 KB |
testcase_21 | AC | 406 ms
95,384 KB |
testcase_22 | AC | 352 ms
106,004 KB |
testcase_23 | AC | 333 ms
103,552 KB |
testcase_24 | AC | 327 ms
100,200 KB |
testcase_25 | AC | 347 ms
104,524 KB |
testcase_26 | AC | 347 ms
104,540 KB |
testcase_27 | AC | 182 ms
84,352 KB |
testcase_28 | AC | 464 ms
112,340 KB |
testcase_29 | AC | 320 ms
96,824 KB |
testcase_30 | AC | 386 ms
101,648 KB |
testcase_31 | AC | 430 ms
112,784 KB |
testcase_32 | AC | 340 ms
106,908 KB |
testcase_33 | AC | 388 ms
102,476 KB |
testcase_34 | AC | 287 ms
90,524 KB |
testcase_35 | AC | 251 ms
88,192 KB |
testcase_36 | AC | 270 ms
91,764 KB |
testcase_37 | AC | 354 ms
101,888 KB |
testcase_38 | AC | 155 ms
80,384 KB |
testcase_39 | AC | 247 ms
87,168 KB |
testcase_40 | AC | 238 ms
87,168 KB |
testcase_41 | AC | 229 ms
87,296 KB |
testcase_42 | AC | 240 ms
87,168 KB |
testcase_43 | AC | 215 ms
93,568 KB |
testcase_44 | AC | 196 ms
93,440 KB |
testcase_45 | AC | 201 ms
93,568 KB |
testcase_46 | AC | 488 ms
102,916 KB |
testcase_47 | AC | 541 ms
107,804 KB |
testcase_48 | AC | 443 ms
105,008 KB |
ソースコード
from collections import deque class UnionFind(): def __init__(self, n): self.n = n self.parents = [-1] * n self.group = 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 self.group -= 1 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 self.group def all_group_members(self): dic = {r:[] for r in self.roots()} for i in range(self.n): dic[self.find(i)].append(i) return dic def __str__(self): return '\n'.join('{}: {}'.format(r, self.members(r)) for r in self.roots()) n, m = map(int, input().split()) std = [list(map(int, input().split())) for _ in range(m)] std.sort(key = lambda x:-x[2]) UF = UnionFind(n) for s, t, d in std: s -= 1 t -= 1 UF.union(s, t) if UF.same(0, n - 1): w = d break edges = [[] for _ in range(n)] for s, t, d in std: if d < w: continue s -= 1 t -= 1 edges[s].append(t) edges[t].append(s) queue = deque() dist = [-1] * n dist[0] = 0 queue.append(0) while queue: pos = queue.popleft() for npos in edges[pos]: if dist[npos] != -1: continue dist[npos] = dist[pos] + 1 queue.append(npos) print(w, dist[-1])