結果
問題 | No.1473 おでぶなおばけさん |
ユーザー | irumo8202 |
提出日時 | 2022-01-30 13:57:17 |
言語 | PyPy3 (7.3.15) |
結果 |
WA
|
実行時間 | - |
コード長 | 1,784 bytes |
コンパイル時間 | 146 ms |
コンパイル使用メモリ | 82,048 KB |
実行使用メモリ | 131,128 KB |
最終ジャッジ日時 | 2024-06-11 08:15:28 |
合計ジャッジ時間 | 16,312 ms |
ジャッジサーバーID (参考情報) |
judge5 / judge1 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 43 ms
54,272 KB |
testcase_01 | AC | 40 ms
53,888 KB |
testcase_02 | AC | 520 ms
119,488 KB |
testcase_03 | AC | 455 ms
117,388 KB |
testcase_04 | AC | 381 ms
104,632 KB |
testcase_05 | AC | 204 ms
82,588 KB |
testcase_06 | AC | 399 ms
109,476 KB |
testcase_07 | AC | 566 ms
128,144 KB |
testcase_08 | AC | 592 ms
129,216 KB |
testcase_09 | AC | 511 ms
128,824 KB |
testcase_10 | AC | 190 ms
86,784 KB |
testcase_11 | AC | 186 ms
86,528 KB |
testcase_12 | AC | 192 ms
86,400 KB |
testcase_13 | AC | 149 ms
85,120 KB |
testcase_14 | AC | 115 ms
80,640 KB |
testcase_15 | AC | 187 ms
89,600 KB |
testcase_16 | AC | 194 ms
86,272 KB |
testcase_17 | AC | 63 ms
68,992 KB |
testcase_18 | AC | 68 ms
73,472 KB |
testcase_19 | AC | 256 ms
86,912 KB |
testcase_20 | AC | 421 ms
114,420 KB |
testcase_21 | AC | 378 ms
98,556 KB |
testcase_22 | WA | - |
testcase_23 | WA | - |
testcase_24 | WA | - |
testcase_25 | WA | - |
testcase_26 | WA | - |
testcase_27 | WA | - |
testcase_28 | AC | 509 ms
131,128 KB |
testcase_29 | WA | - |
testcase_30 | WA | - |
testcase_31 | AC | 491 ms
129,428 KB |
testcase_32 | AC | 355 ms
112,008 KB |
testcase_33 | AC | 385 ms
106,876 KB |
testcase_34 | AC | 306 ms
94,884 KB |
testcase_35 | AC | 241 ms
90,568 KB |
testcase_36 | WA | - |
testcase_37 | WA | - |
testcase_38 | WA | - |
testcase_39 | AC | 192 ms
86,656 KB |
testcase_40 | AC | 180 ms
86,656 KB |
testcase_41 | AC | 187 ms
86,528 KB |
testcase_42 | AC | 188 ms
86,784 KB |
testcase_43 | AC | 168 ms
99,840 KB |
testcase_44 | AC | 165 ms
99,584 KB |
testcase_45 | AC | 164 ms
99,968 KB |
testcase_46 | AC | 465 ms
106,224 KB |
testcase_47 | AC | 543 ms
118,980 KB |
testcase_48 | AC | 443 ms
108,992 KB |
ソースコード
import sys from collections import defaultdict, deque input = sys.stdin.buffer.readline 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 + 1)] for s, t, d in edges: uf.union(s, t) G[s].append(t) G[t].append(s) if uf.same(1, N): w = d break que = deque([1]) dist = [-1] * (N + 1) dist[1] = 0 while que: v = que.popleft() for u in G[v]: if dist[u] != -1: continue dist[u] = dist[v] + 1 que.append(u) print(w, dist[N])