結果
問題 | No.1473 おでぶなおばけさん |
ユーザー | 👑 hitonanode |
提出日時 | 2021-04-04 16:43:54 |
言語 | PyPy3 (7.3.15) |
結果 |
AC
|
実行時間 | 704 ms / 2,000 ms |
コード長 | 1,500 bytes |
コンパイル時間 | 273 ms |
コンパイル使用メモリ | 87,244 KB |
実行使用メモリ | 106,208 KB |
最終ジャッジ日時 | 2023-08-27 19:22:23 |
合計ジャッジ時間 | 24,285 ms |
ジャッジサーバーID (参考情報) |
judge15 / judge12 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 95 ms
71,700 KB |
testcase_01 | AC | 93 ms
71,868 KB |
testcase_02 | AC | 666 ms
103,632 KB |
testcase_03 | AC | 553 ms
99,816 KB |
testcase_04 | AC | 422 ms
88,644 KB |
testcase_05 | AC | 272 ms
83,196 KB |
testcase_06 | AC | 549 ms
93,748 KB |
testcase_07 | AC | 702 ms
103,296 KB |
testcase_08 | AC | 704 ms
99,976 KB |
testcase_09 | AC | 641 ms
98,648 KB |
testcase_10 | AC | 385 ms
88,976 KB |
testcase_11 | AC | 385 ms
88,756 KB |
testcase_12 | AC | 386 ms
88,860 KB |
testcase_13 | AC | 275 ms
84,308 KB |
testcase_14 | AC | 222 ms
82,608 KB |
testcase_15 | AC | 358 ms
88,872 KB |
testcase_16 | AC | 373 ms
88,656 KB |
testcase_17 | AC | 119 ms
77,356 KB |
testcase_18 | AC | 127 ms
77,300 KB |
testcase_19 | AC | 432 ms
89,460 KB |
testcase_20 | AC | 557 ms
98,380 KB |
testcase_21 | AC | 584 ms
94,300 KB |
testcase_22 | AC | 695 ms
101,152 KB |
testcase_23 | AC | 542 ms
98,124 KB |
testcase_24 | AC | 587 ms
94,816 KB |
testcase_25 | AC | 627 ms
96,036 KB |
testcase_26 | AC | 634 ms
93,796 KB |
testcase_27 | AC | 308 ms
86,596 KB |
testcase_28 | AC | 677 ms
105,624 KB |
testcase_29 | AC | 499 ms
92,304 KB |
testcase_30 | AC | 568 ms
93,580 KB |
testcase_31 | AC | 469 ms
106,208 KB |
testcase_32 | AC | 361 ms
96,984 KB |
testcase_33 | AC | 415 ms
97,600 KB |
testcase_34 | AC | 329 ms
89,280 KB |
testcase_35 | AC | 289 ms
87,820 KB |
testcase_36 | AC | 509 ms
93,572 KB |
testcase_37 | AC | 574 ms
97,912 KB |
testcase_38 | AC | 220 ms
81,648 KB |
testcase_39 | AC | 383 ms
88,916 KB |
testcase_40 | AC | 392 ms
88,948 KB |
testcase_41 | AC | 387 ms
88,556 KB |
testcase_42 | AC | 386 ms
88,136 KB |
testcase_43 | AC | 259 ms
95,472 KB |
testcase_44 | AC | 256 ms
95,420 KB |
testcase_45 | AC | 261 ms
95,344 KB |
testcase_46 | AC | 601 ms
97,528 KB |
testcase_47 | AC | 691 ms
101,268 KB |
testcase_48 | AC | 594 ms
92,952 KB |
ソースコード
# PyPy ACになってほしい from collections import deque import sys input = sys.stdin.readline class DSU: def __init__(self, N: int) -> None: self.par = list(range(N)) self.sz = [1] * N def find(self, x: int) -> int: if self.par[x] != x: self.par[x] = self.find(self.par[x]) return self.par[x] def unite(self, x: int, y: int) -> bool: x, y = self.find(x), self.find(y) if x == y: return False if self.sz[x] < self.sz[y]: x, y = y, x self.par[y] = x self.sz[x] += self.sz[y] return True def same(self, x: int, y: int) -> bool: return self.find(x) == self.find(y) def main(): N, M = map(int, input().split()) uf = DSU(N) edges = [] for _ in range(M): s, t, w = map(int, input().split()) edges.append((w, s - 1, t - 1)) edges.sort(reverse=True) ret = 1 << 30 for w, u, v in edges: if uf.same(0, N - 1): break ret = w uf.unite(u, v) to = [[] for _ in range(N)] for w, s, t in edges: if w >= ret: to[s].append(t), to[t].append(s) dist = [1 << 30] * N dist[0] = 0 q = deque([0]) while q: now = q.popleft() for nxt in to[now]: if dist[nxt] > dist[now] + 1: dist[nxt] = dist[now] + 1 q.append(nxt) print(ret, dist[N - 1]) if __name__ == '__main__': main()